// - - - - - - - - - - - - - - - - - - - - -
//
// Title : Dynamic Resolution Dependent Layout Demo
// Author : Kevin Hale
// URL : http://particletree.com
//
// Description : This is a demonstration of a dynamic 
// resolution dependent layout in action. Change your browser 
// window size to see the layout respond to your changes. To 
// preserve the separation of the presentation and behavior 
// layers, this implementation delegates all the presentation 
// details to external CSS stylesheets instead of changing 
// each style property through JavaScript.
//
// Created : July 30, 2005
// Modified : November 15, 2005
//
// - - - - - - - - - - - - - - - - - - - - -

// getBrowserWidth is taken from The Man in Blue Resolution Dependent Layout Script
// http://www.themaninblue.com/experiment/ResolutionLayout/
	function getBrowserWidth(){
		if (window.innerWidth){
			return window.innerWidth;}	
		else if (document.documentElement && document.documentElement.clientWidth != 0){
			return document.documentElement.clientWidth;	}
		else if (document.body){return document.body.clientWidth;}		
			return 0;
	}

// dynamicLayout by Kevin Hale
function dynamicLayout(){
	var browserWidth = getBrowserWidth();
	usePicture();
	
	$('a[rel*=lightbox]').lightBox();
	
	//Load Wide CSS Rules
	if (browserWidth < 1200){
		changeLayout("layout");
		//document.write('<link rel="stylesheet" type="text/css" href="layout.css" title="layout"/>');
	}
	//Load Wider CSS Rules
	if (browserWidth >= 1200){
	  //document.write('<link rel="stylesheet" type="text/css" href="layout1280.css" title="layout1280"/>');
		changeLayout("layout1280");
	}
}

function usePicture(){
	el = document.getElementById('replace');
	
  var browserWidth = getBrowserWidth();

	if (browserWidth < 1200){
		var tmp = '<map name="FPMap0" id="FPMap0">'+
'<area href="?page=shop&amp;item_tree=0" shape="rect" coords="187, 6, 457, 24" />'+
'<area href="http://www.oponex.pl/opony/index.php" shape="rect" coords="197, 29, 424, 49" />'+
'<area href="http://www.oponex.pl/opony/index.php" shape="rect" coords="302, 90, 351, 104" />'+
'<area href="http://www.oponex.pl/opony/index.php" shape="circle" coords="378, 100, 29" />'+
'<area href="?page=shop&amp;item_tree=1" shape="rect" coords="168, 120, 222, 136" />'+
'<area href="?page=shop&amp;item_tree=218" shape="rect" coords="76, 165, 137, 180" />'+
'<area href="?page=shop&amp;item_tree=57" shape="rect" coords="193, 176, 258, 191" />'+
'<area href="?page=shop&amp;item_tree=227" shape="rect" coords="327, 199, 403, 216" />'+
'<area href="?page=register" shape="rect" coords="338, 319, 470, 350" />'+
'<area href="?page=shop&amp;item_tree=35" shape="rect" coords="259, 295, 333, 311" />'+
'<area href="?page=shop&amp;item_tree=35" shape="circle" coords="234, 291, 24" />'+
'<area href="?page=shop&amp;item_tree=0" shape="rect" coords="14, 262, 194, 288" />'+
'<area href="?page=cart" shape="rect" coords="15, 293, 137, 321" />'+
'<area href="?page=confirm" shape="rect" coords="14, 326, 200, 351" />'+
'</map>'+
'<img alt="" src="images/baner-mid.jpg" width="484" height="362" usemap="#FPMap0" />';
	}

	if (browserWidth >= 1200){
	  var tmp = '<map name="FPMap0" id="FPMap0">'+
'<area href="?page=shop" shape="rect" coords="242, 4, 561, 35" />'+
'<area target="_blank" href="http://www.oponex.pl/opony/index.php" shape="rect" coords="246, 37, 515, 63" />'+
'<area target="_blank" coords="376, 110, 429, 132" shape="rect" href="http://www.oponex.pl/opony/index.php" />'+
'<area target="_blank" href="http://www.oponex.pl/opony/index.php" shape="circle" coords="466, 123, 37" />'+
'<area href="?page=shop&amp;item_tree=1" shape="rect" coords="208, 150, 265, 170" />'+
'<area href="?page=shop&amp;item_tree=218" shape="rect" coords="96, 204, 171, 221" />'+
'<area href="?page=shop&amp;item_tree=57" shape="rect" coords="241, 218, 318, 236" />'+
'<area href="?page=shop&amp;item_tree=227" shape="rect" coords="406, 248, 505, 265" />'+
'<area href="?page=register" shape="rect" coords="418, 394, 584, 437" />'+
'<area href="?page=shop&amp;item_tree=0" shape="rect" coords="16, 325, 240, 359" />'+
'<area href="?page=cart" shape="rect" coords="14, 365, 241, 397" />'+
'<area href="?page=confirm" shape="rect" coords="13, 404, 241, 439" />'+
'<area href="?page=shop&amp;item_tree=35" shape="rect" coords="317, 365, 407, 381" />'+
'<area href="?page=shop&amp;item_tree=35" shape="circle" coords="293, 358, 26" />'+
'</map>'+
'<img alt="" src="images/baner-big.jpg" width="600" height="449" usemap="#FPMap0" />';
	}
	if (el){
	  el.innerHTML = tmp;
	}

}

// changeLayout is based on setActiveStyleSheet function by Paul Sowdon 
// http://www.alistapart.com/articles/alternate/
function changeLayout(description){
   var i, a;
   for(i=0; (a = document.getElementsByTagName("link")[i]); i++){
	   if(a.getAttribute("title") == description){a.disabled = true;a.disabled = false;}
	   else if(a.getAttribute("title") != "default"){a.disabled = true;}
   }
}

	//addEvent() by John Resig
	function addEvent( obj, type, fn ){ 
	   if (obj.addEventListener){ 
	      obj.addEventListener( type, fn, false );
	   }
	   else if (obj.attachEvent){ 
	      obj["e"+type+fn] = fn; 
	      obj[type+fn] = function(){ obj["e"+type+fn]( window.event ); } 
	      obj.attachEvent( "on"+type, obj[type+fn] ); 
	   } 
	} 
	
	$(function() {
		// Use this example, or...

		//alert('ok');

	});
	
	addEvent(window, 'load', dynamicLayout);
	addEvent(window, 'resize', dynamicLayout);

