// 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 Nico Thomaier
function dynamicLayout(){
	var browserWidth = getBrowserWidth();

	//Load Thin CSS Rules
	if (browserWidth < 800){
    document.body.setAttribute('id','smallBody'); 
	}
	
	if (browserWidth >= 800){
		document.body.removeAttribute('id');
		var IE=(document.all); // IE won't properly replace all elements
		if (IE) window.setTimeout(fixIE,200);
	}
}

function fixIE() {
    // alert ('ich bin der dämliche IE :P. Und ich brauche wie immer in sachen CSS ein bisserl Starthilfe');
    setStyle('#left','margin-left','-250px'); // IE won't properly replace all elements
}

function getStyleSheet(name)
{
     if(!name || !document.styleSheets) return null;
    var i = document.styleSheets.length;
    while(i--)
    {
        var rules = document.styleSheets[i].rules ? document.styleSheets[i].rules :
        document.styleSheets[i].cssRules;
        var j = rules.length;
        while(j--) { if(rules[j].selectorText == name) return rules[j]; }
    }
     return null;
}

function setStyle(name, attr, value)
{
    var rule = getStyleSheet(name);
    if(!rule) return null;
    if(value) rule.style[attr] = value;
    return rule.style[attr];
}

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

