function __StyleSwitcher()
{
}

__StyleSwitcher.prototype.init = function()
{
	var pref = this.getCookie('__style');
	if(pref)
	{
		this.setActive(pref, true);
	}
}
__StyleSwitcher.prototype.setActive = function(title, no_save)
{
	// disable/enable correct style sheet
	var styles = document.getElementsByTagName("link");
	for(var i = 0; i < styles.length; i++)
	{
		var s = styles[i];
		if(s.getAttribute("rel").indexOf("style") != -1 && s.getAttribute("title"))
		{
			s.disabled = true;
			if(s.getAttribute("title") == title)
			{
				s.disabled = false;
			}
		}
	}

	// save preference in cookie
	if(!no_save)
	{
		this.setCookie('__style', title, 365);
	}
}
__StyleSwitcher.prototype.setCookie = function(name,value,days)
{
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else
	{
		expires = "";
	}
	document.cookie = name+"="+value+expires+"; path=/";
}

__StyleSwitcher.prototype.getCookie = function(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0) == ' ')
		{
			c = c.substring(1,c.length);
		}
		if (c.indexOf(nameEQ) == 0)
		{
			return c.substring(nameEQ.length, c.length);
		}
	}
	return null;
}


var StyleSwitcher = new __StyleSwitcher();
StyleSwitcher.init();
window.onload = function() { StyleSwitcher.init(); }

