
// ///////////////////////////////
// Konfiguration
// ///////////////////////////////

var cssswitcher_style 		= "standard";
var cssswitcher_cookie 		= "usercss";
var cssswitcher_cookie_days = 30;



// ///////////////////////////////
// Cookie-Funktionen
// ///////////////////////////////

function cookie_getValue(pos) {
   var end = document.cookie.indexOf(";", pos);
   if (end == -1) {
      end = document.cookie.length;
   }
   return unescape(document.cookie.substring(pos, end));
}

function cookie_get(name) {
   name += "=";
   var length = name.length;
   var cookieLength = document.cookie.length;
   var i = 0;
   while (i < cookieLength) {
      var j = i + length;
      if (document.cookie.substring(i, j) == name) {
         return cookie_getValue(j);
      }
      i = document.cookie.indexOf(" ", i) + 1;
      if (i == 0) {
         break;
      }
   }
   return null;
}

function cookie_set(name, value, days) {
   var exp = new Date();
   exp.setTime(exp.getTime() + (days * 24 * 60 * 60 * 1000));
   document.cookie = name + "=" + escape (value) + "; expires=" + exp.toGMTString();
}

function cookie_delete(name) {
   var exp = new Date();
   exp.setTime (exp.getTime() - 1);
   var value = cookie_get(name);
   if (value != null) {
      document.cookie = name + "=" + value + "; expires=" + exp.toGMTString();
   }
}

// ///////////////////////////////
// Style Switcher
// ///////////////////////////////

function switchStyle(style) {
 	if (!document.getElementsByTagName) {
		return;
	}
	var elems = document.getElementsByTagName("link");
 	for (var i = 0; i < elems.length; i++ ) {
	 	if (elems[i].getAttribute("rel").indexOf("style") != -1 
	 		&& elems[i].getAttribute("title")) {
	 		elems[i].disabled = true;
		 	if (elems[i].getAttribute("title") == style) {
				elems[i].disabled = false;
			}
		 }
	 }
}

function loadStyle() {
 	var cs = getStyleCookie();
 	if (cs && cs != cssswitcher_style) {
		switchStyle(cs);
 		cssswitcher_style = cs;
 	}
	//if(document.getElementById('cssSwitcher') != null) {
		markCssSwitcher(cs, cs);
	//}		
}

function setStyle(style) {
 	if (style != cssswitcher_style) {
 		switchStyle(style);
		//if(document.getElementById('cssSwitcher') != null) {
			markCssSwitcher(cssswitcher_style, style);
		//}				
 		cssswitcher_style = style;
 	}
}

window.onload = loadStyle;


function setStyleCookie() {
	cookie_set(cssswitcher_cookie, cssswitcher_style, cssswitcher_cookie_days);
}

function getStyleCookie() {
 	return cookie_get(cssswitcher_cookie);
}

function delStyleCookie() {
 	cookie_delete(cssswitcher_cookie);
}


function userSetStylesheet(style) {
	setStyle(style);
	setStyleCookie();
}


function markCssSwitcher(oldStyle, newStyle) {
	//var oldStyleLink = document.getElementById(oldStyle);
	//var newStyleLink = document.getElementById(newStyle);	
	//if(oldStyleLink != null) {
//		oldStyleLink.setAttribute('class', 'cssSwitchLink');
	//} 
	//if(newStyleLink != null) {
		//newStyleLink.setAttribute('class', 'cssSwitchLinkActive');
		document.getElementById(oldStyle).className = 'cssSwitchLink';
		document.getElementById(newStyle).className = 'cssSwitchLinkActive';
	//}
	
}