

function getBrowserWidth(){
   if (window.innerWidth){
		//console.log(window.innerWidth);
        return window.innerWidth;  
   } else if (document.documentElement && document.documentElement.clientWidth != 0){
		//console.log(document.documentElement.clientWidth);
        return document.documentElement.clientWidth;    
   } else if (document.body){ 
		//console.log(document.body.clientWidth);
		return document.body.clientWidth;
	}      
    
    return 0;
}



function changeLayout(description){
	$('link[@rel*=style][title]').each(
		function(i) {
			this.disabled = true;
			if (
				(this.getAttribute('title') == description) || 
				(this.getAttribute('title') == 'default') || 
				(this.getAttribute('title') == 'default-ie') || 
				(this.getAttribute('title') == 'default-ie6')) {
					this.disabled = false;
					activeStylesheetIndex = i;
				}
		}
	);

}


function dynamicLayout(){

    var browserWidth = getBrowserWidth();
    
    //var pageSize = tb_getPageSize();
    //var browserWidth = pageSize[0];
    
    if (browserWidth < 1585){
        changeLayout("wide");
    }
    
    //Load Wider CSS Rules
    if ((browserWidth >= 1585) && (browserWidth <= 2144)){
        changeLayout("wider");
    }
    
    //Load Widest CSS Rules
    if (browserWidth > 2144){
        changeLayout("widest");
    }
}


function addEvent( obj, type, fn ) {
  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] );
  } else
    obj.addEventListener( type, fn, false );
}

function removeEvent( obj, type, fn ) {
  if ( obj.detachEvent ) {
    obj.detachEvent( 'on'+type, obj[type+fn] );
    obj[type+fn] = null;
  } else
    obj.removeEventListener( type, fn, false );
}



