// JavaScript Document

function changeLayout(newLayout) {
	document.body.className = newLayout;
}

function dynamicLayout(){
	var browserWidth = getBrowserWidth();
	var browserHeight = getBrowserHeight();
					
	//Load Thin CSS Rules
	if (browserWidth < 850){
		$("body").addClass("thin");
		$("body").removeClass("wide");
		//changeLayout("thin");
	}
	//Load Wide CSS Rules
	if (browserWidth >= 850){
		$("body").addClass("wide");
		$("body").removeClass("thin");
		changeLayout("wide");
	}

	//Load Thin CSS Rules
	if (browserHeight < 600){
		$("body").addClass("short");
		$("body").removeClass("tall");
	}
	//Load Wide CSS Rules
	if (browserHeight >= 600){
		$("body").addClass("tall");
		$("body").removeClass("short");
	}
}

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;
}

function getBrowserHeight(){
	if (window.innerHeight){
		return window.innerHeight;}  
	else if (document.documentElement && document.documentElement.clientHeight != 0){
		return document.documentElement.clientHeight;    }
	else if (document.body){return document.body.clientHeight;}      
		return 0;
}

//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] ); 
   } 
} 

//Run dynamicLayout function when page loads and when it resizes.
addEvent(window, 'load', dynamicLayout);
addEvent(window, 'resize', dynamicLayout);
