
checkBrowserWidth();

attachEventListener(window, "resize", checkBrowserWidth, false);




function checkBrowserWidth()
{
	var theWidth = getBrowserWidth();
	
	
	
	if (theWidth.widthValue == 0)
	{
		var resolutionCookie = document.cookie.match(/(^|;)tmib_res_layout[^;]*(;|$)/);

		if (resolutionCookie != null)
		{
			setStylesheet(unescape(resolutionCookie[0].split("=")[1]));
		}
		
		addLoadListener(checkBrowserWidth);
		
		return false;
	}


	//window.status = theWidth.browser + ' ' + theWidth.widthValue;


	if (theWidth.widthValue >= 995 && theWidth.browser == 'IE'  )
	{
		setStylesheet("1024 x 768");
		document.cookie = "tmib_res_layout=" + escape("1024 x 768");
	}
	else if (theWidth.widthValue < 995 && (theWidth.browser == 'IE' || theWidth.browser == 'OTHER') )
	{
		setStylesheet("800");
		document.cookie = "tmib_res_layout=" + escape("800");
	}
	else if (theWidth.widthValue >= 1007 && theWidth.browser == 'SAFARI')
	{
		setStylesheet("1024 x 768");
		document.cookie = "tmib_res_layout=" + escape("1024 x 768");
	}
	else if (theWidth.widthValue < 1007 && theWidth.browser == 'SAFARI')
	{
		setStylesheet("800");
		document.cookie = "tmib_res_layout=" + escape("800");
	}	
	else if (theWidth.widthValue >= 1016 && theWidth.browser == 'FF')
	{
		setStylesheet("1024 x 768");
		document.cookie = "tmib_res_layout=" + escape("1024 x 768");
	}
	else if (theWidth.widthValue < 1016 && theWidth.browser == 'FF')
	{
		setStylesheet("800");
		document.cookie = "tmib_res_layout=" + escape("800");
	}			
	else
	{
		setStylesheet("800");
		document.cookie = "tmib_res_layout=" + escape("800");
	}
	
	return true;
};


function getBrowser()
{
	var ua = navigator.userAgent;
	var oBrowser = new Object();
	
	oBrowser.isMSIE = (navigator.appName == "Microsoft Internet Explorer");
	oBrowser.isMSIE5 = oBrowser.isMSIE && (ua.indexOf('MSIE 5') != -1);
	oBrowser.isMSIE5_0 = oBrowser.isMSIE && (ua.indexOf('MSIE 5.0') != -1);
	oBrowser.isGecko = ua.indexOf('Gecko') != -1;
	oBrowser.isSafari = ua.indexOf('Safari') != -1;
	oBrowser.isOpera = ua.indexOf('Opera') != -1;
	oBrowser.isMac = ua.indexOf('Mac') != -1;
	oBrowser.isNS7 = ua.indexOf('Netscape/7') != -1;
	oBrowser.isNS71 = ua.indexOf('Netscape/7.1') != -1;
	
	return oBrowser;
}

function getBrowserWidth()
{
	var oWidth = new Object();
	oWidth.browser = '';
	oWidth.widthValue = 0;
	
	if (window.innerWidth)
	{
		var oBrowser = getBrowser();
		if( oBrowser.isSafari )
			oWidth.browser = 'SAFARI';
		else
			oWidth.browser = 'FF';
			
		oWidth.widthValue = window.innerWidth;
		//return window.innerWidth;
	}
	else if (document.documentElement && document.documentElement.clientWidth != 0)
	{
		oWidth.browser = 'IE';
		oWidth.widthValue = document.documentElement.clientWidth;
		
	}
	else if (document.body)
	{
		oWidth.browser = 'OTHER';
		oWidth.widthValue = document.body.clientWidth;
		
	}
	
	return oWidth;
};




function setStylesheet(styleTitle)
{
	var currTag;

	if (document.getElementsByTagName)
	{
		for (var i = 0; (currTag = document.getElementsByTagName("link")[i]); i++)
		{
			if (currTag.getAttribute("rel").indexOf("style") != -1 && currTag.getAttribute("title"))
			{
				currTag.disabled = true;

				if(currTag.getAttribute("title") == styleTitle)
				{
					currTag.disabled = false;
				}
			}
		}
	}
	
	return true;
};