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

	// check current class for existent .dark
	var current = document.getElementsByTagName('body')[0].className;
	var currentpos = current.indexOf('dark');
	var dark = '';
	if (currentpos>0) {
		var dark = ' dark';
	}
	
	if (theWidth == 0)
	{
		addLoadListener(checkBrowserWidth);
		return false;
	}

	if (theWidth < 870) {		

		if (document.getElementsByTagName('body')[0]) document.getElementsByTagName('body')[0].className = 'w2'+dark;
		document.cookie = 'decaf_resolution=w2; expires='+a.toGMTString()+';'; 

		if (theWidth < 641) {		

			if (document.getElementsByTagName('body')[0]) document.getElementsByTagName('body')[0].className = 'w1'+dark;
			document.cookie = 'decaf_resolution=w1; expires='+a.toGMTString()+';'; 
		}
	}
	else {

		if (document.getElementsByTagName('body')[0]) document.getElementsByTagName('body')[0].className = 'w3'+dark;
		document.cookie = 'decaf_resolution=w3; 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;
};


