checkBrowserWidth();

attachEventListener(window, "resize", checkBrowserWidth, false);




function checkBrowserWidth()
{
	var theWidth = getBrowserWidth();
	var a = new Date(); a = new Date(a.getTime() +1000*60*60*24*365);
	
	if (theWidth == 0)
	{
		addLoadListener(checkBrowserWidth);
		return false;
	}

	if (theWidth < 1005)
	{
		if (document.getElementsByTagName('body')[0]) document.getElementsByTagName('body')[0].className = 'w800';
		document.cookie = 'messie_resolution=w800; expires='+a.toGMTString()+';'; 


		if (theWidth < 785)
		{		
			if (document.getElementsByTagName('body')[0]) document.getElementsByTagName('body')[0].className = 'w640';
			document.cookie = 'messie_resolution=w640; expires='+a.toGMTString()+';'; 
		}
	}
	else
	{
		if (document.getElementsByTagName('body')[0]) document.getElementsByTagName('body')[0].className = 'w1024';
		document.cookie = 'messie_resolution=w1024; expires='+a.toGMTString()+';'; 
	}
	
	return true;
};




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

