document.observe('dom:loaded', function(){
	var qsvars = window.location.href.toQueryParams();	
	var jar = new CookieJar({domain: '.mycommunitystorage.com', path: '/'});
	
	if(jar.get('DisplayVersion') == null)
		jar.put('DisplayVersion', 'Desktop');
	
	if(jar.get('BypassMobileCheck') == null)
		jar.put('BypassMobileCheck', '0');
	
	if(qsvars.bypassmobilecheck)
	{		
		jar.put('BypassMobileCheck', qsvars.bypassmobilecheck);
	}
	
	if(jar.get('BypassMobileCheck') == '0')
	{
		var screen = document.viewport.getDimensions();
		
		if(screen.width < 700 || window.innerWidth < 700)
		{
			jar.put('DisplayVersion', 'Mobile');
		}
		else if(screen.height < 700 || window.innerHeight < 700)
		{
			jar.put('DisplayVersion', 'Mobile');
		}
		else
		{
			jar.put('DisplayVersion', 'Desktop');
		}
	}
	else if(jar.get('BypassMobileCheck') == '1')
	{
		jar.put('DisplayVersion', 'Desktop');
	}
	
	if(jar.get('DisplayVersion') == 'Mobile')
		window.location.href = "http://mobile.mycommunitystorage.com";	
});

