function Stylemanager()
{
	this.cookie = cookieManager.getCookie("style");
	this.setActiveStyleSheet(this.cookie ? this.cookie : "");
	this.htmlText = this.showStyleSelector();
}

Stylemanager.prototype.showStyleSelector = function()
{
	var i, a, main;
	var thtml = "\n<ul>";
	thtml += "\n  <li><a href=\"#\" onclick=\"styleManager.setActiveStyleSheet('');" +
			"\" class=\"standard\"  title=\"Webseiten-Stil auf Standard setzen\"><span>Standard</span></a></li>\n";
	for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
		if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title"))
		{
			thtml += "\n  <li><a href=\"#\" " +
				   "onclick=\"styleManager.setActiveStyleSheet('" +
				   a.getAttribute("title") + "')\"";
			if (a.getAttribute("title") == "Kleinbildschirm")
				{ thtml += " class=\"mobile\""; }
			else if (a.getAttribute("title") == "Schwarz-Weiss")
				{ thtml += " class=\"schwarzweiss\""; }
			thtml += " title=\"Webseiten-Stil auf " + a.getAttribute("title") + " setzen\">";
			// thtml += a.getAttribute("title");
			thtml += "<span>" + a.getAttribute("title") + "</span>";
			thtml += "</a></li> ";
		}
	}
	thtml += "\n  <li><a href=\"#\" onclick=\"styleManager.setActiveStyleSheet('');" +
	   		"\" class=\"nomobile\"  title=\"Webseiten-Stil auf Normalbildschirm (Standard) setzen\"><span>Normalbildschirm (Standard)</span></a></li>\n";
	thtml += "</ul>";
	return thtml;
}

Stylemanager.prototype.setActiveStyleSheet = function(title)
{
	var i, a, main;
	for(i=0; (a = document.getElementsByTagName("link")[i]); i++)
	{
		if(a.getAttribute("rel") && a.getAttribute("rel").indexOf("style") != -1)
		{
			a.disabled = true;
			if(title == "" && a.getAttribute("title") == null)
			{
				a.disabled = false;
				cookieManager.setCookie("style", "", 365);
			}
			if(a.getAttribute("title") == title)
			{
				a.disabled = false;
				cookieManager.setCookie("style", title, 365);
			}
		}
	}
}

Stylemanager.prototype.getActiveStyleSheet = function()
{
	var i, a;
	for(i=0; (a = document.getElementsByTagName("link")[i]); i++)
	{
		if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
	}
	return null;
}

/*Stylemanager.prototype.getPreferredStyleSheet = function() {
	var i, a;
	for(i=0; (a = document.getElementsByTagName("link")[i]); i++)
	{
		if(a.getAttribute("rel").indexOf("style") != -1
		   && a.getAttribute("rel").indexOf("alt") == -1
		   && a.getAttribute("title")
		   ) return a.getAttribute("title");
	}
	return null;
}*/


var styleManager = new Stylemanager();
