// ----------------------------------------------
// StyleSwitcher functions written by Paul Sowden
// http://www.idontsmoke.co.uk/ss/
// - - - - - - - - - - - - - - - - - - - - - - -
// For the details, visit ALA:
// http://www.alistapart.com/stories/alternate/
// ----------------------------------------------

// new styleswitcher **edit by as on 301105:
// changes between default (small.css), small (x-small.css) and large (medium.css) text size
// BUT just in default color!!!

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

function setStyle() {
var style = readCookie("wstyle");
if (style != null) {
setActiveStyleSheet(style, 0);
}
}

function createCookie(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=/;";
}

function readCookie(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;
}

if (window.addEventListener) window.addEventListener("load",setStyle,false);
else if (window.attachEvent) window.attachEvent("onload",setStyle);




// old styleswitcher, with bugs **edit by as on 301105:

/*function fontsizeup() {
  active = getActiveStyleSheet();
  switch (active) {
    case 'A--' : 
      setActiveStyleSheet('A-');
      break;
    case 'A-' : 
      setActiveStyleSheet('A');
      break;
    case 'A' : 
      setActiveStyleSheet('A+');
      break;
    case 'A+' : 
      setActiveStyleSheet('A++');
      break;
    case 'A++' :
      break;
    default :
      setActiveStyleSheet('A+'); //vorher 'A'
      break;
  }
}

function fontsizedown() {
  active = getActiveStyleSheet();
  switch (active) {
    case 'A++' : 
      setActiveStyleSheet('A+');
      break;
    case 'A+' : 
      setActiveStyleSheet('A');
      break;
    case 'A' : 
      setActiveStyleSheet('A-');
      break;
    case 'A-' : 
      setActiveStyleSheet('A--');
      break;
    case 'A--' : 
       break;
    default :
      setActiveStyleSheet('A-');
      break;
  }
}

//Da der alternative Styleswitcher im Zusammenhang mit den Relative Font-size nicht optimal funktioniert,
//gibt es jetzt nur Schriftgrößen wechsel zwischen A+, A und A-
//Code an bestimmten Stellen ist überflüssig, bleibt aber vorerst stehen, falls das Problem doch einmal gelöst werden kann. *Astrid*
function fontSizeDefault() {
  active = getActiveStyleSheet();
  switch (active) {
    default :
      setActiveStyleSheet('A');
      break;
  }
}


function setActiveStyleSheet(title) {
  var i, a, main, activ, actTitle;
  activ = getActiveStyleSheet();
  actTitle = null;
  //alert("activ ist: " + activ + " und actTitle ist: " + actTitle);
  //if((title=='default' || title=='blueyellow' || title=='blackwhite') && (activ.indexOf('A++') != 1 || activ.indexOf('A+') != 1 || activ.indexOf('A') != 1 || activ.indexOf('A-') != 1 || activ.indexOf('A--') != 1 || activ.indexOf('null') != 1)) actTitle=activ;
  //if((title=='A++' || title=='A+' || title=='A' || title=='A-' || title=='A--') && (activ.indexOf('default') != -1 || activ.indexOf('blueyellow') != -1 || activ.indexOf('blackwhite') != 1 || activ.indexOf('null') != 1)) actTitle=activ;
  if((title=='default' || title=='blueyellow' || title=='blackwhite') && (activ=='A++' || activ=='A+' || activ=='A' || activ=='A-' || activ=='A--' || activ=='null')) actTitle=activ;
  if((title=='A++' || title=='A+' || title=='A' || title=='A-' || title=='A--') && (activ=='default' || activ=='blueyellow' || activ=='blackwhite' || activ=='null')) actTitle=activ;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
	  if(actTitle!=null)
	  	if(a.getAttribute("title") == actTitle) a.disabled = false;
    }
  }
}

function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1  		//Is it a link to a style sheet?
		&& a.getAttribute("title") 							//Is there a title attribute?
		&& !a.disabled) return a.getAttribute("title");		//Is stylesheet active?
  }
  return null;	//vorher null
}

function printActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) {
		alert("aktuelles Stylesheet: " + a.getAttribute("title"));
	}	
  }
}

function getPreferredStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 		//Is it a link to a style sheet?
       && a.getAttribute("rel").indexOf("alt") == -1 		//Does the rel attribute contain not the keyword "alternate"?
       && a.getAttribute("title") 							//Is there a title attribute?
       ) return a.getAttribute("title");
  }
  return null;
  //return ('A');		//vorher hier 'A-'
}

function createCookie(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=/";
}

function readCookie(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;
}

window.onload = function(e) {
  var cookie = readCookie("style");
  var title = cookie ? cookie : getPreferredStyleSheet();
  setActiveStyleSheet(title);
}

window.onunload = function(e) {
  var title = getActiveStyleSheet();
  createCookie("style", title, 365);
}

//var cookie = readCookie("style");
//var title = cookie ? cookie : getPreferredStyleSheet();
//setActiveStyleSheet(title);

var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
if (title == 'null') {
  title = getPreferredStyleSheet();
}

setActiveStyleSheet(title);*/
