var StyleSwitcher = {
	cookiename : "StyleSwitcher",
	cookieLifeTime : 30, //in days
	selectedClassName : "selected",
	setStyle : function (styleTitle, aTag) {
		StyleSwitcher._setCookie(StyleSwitcher.cookiename, styleTitle, StyleSwitcher.cookieLifeTime);
		if (!document.getElementsByTagName) return;
		var el = document.getElementsByTagName("link");
		for (var i = 0; i < el.length; i++ ) {
			if (el[i].getAttribute("title") == styleTitle) el[i].disabled = false;
			else {
				if (el[i].getAttribute("rel").indexOf("style") != -1 && el[i].getAttribute("title")) {
					el[i].disabled = true;
				}
			}
		}
		/*
		var ta = document.createElement("textarea");
		ta.style.width="100%";
		ta.style.height = "300px";
		ta.value = document.getElementsByTagName("HEAD")[0].innerHTML;
		 document.getElementsByTagName("BODY")[0].appendChild(ta);
		*/
		StyleSwitcher.setSelected(aTag);
	},
	setSelected : function(aTag) {
		var links = aTag.parentNode.getElementsByTagName("A");
		aTag.className += " "+StyleSwitcher.selectedClassName;
		for(var i=0;i<links.length;i++) {
			if(links[i].onclick) {
				if(links[i].onclick.toString().match('StyleSwitcher.setStyle') && links[i] != aTag) {
					links[i].className = links[i].className.replace(StyleSwitcher.selectedClassName, "");
				}
			}
		}
	},
	_setCookie : function (name, value, expdays) {
		var now = new Date();
		var exp = new Date(now.getTime() + (1000*60*60*24*expdays));
		document.cookie = name + "=" + escape(value) + ";" +
			"expires=" + exp.toGMTString() + ";" +
			"path=/";
	},
	_delCookie : function (name) {
		var now = new Date();
		var exp = new Date(now.getTime() - 1);
		document.cookie = name + "=;" +
			"expires=" + exp.toGMTString() + ";" +
			"path=/";
	}
}
