// <![CDATA[
/* Zufallsstylesheetauswahl (inkl. zugeordnetes Bild class="strich") nach http://www.alistapart.com/articles/alternate/
geaendert durch Subhash (office@subhash.at) */
function waehleFarbe() {
	var i, j;
	dieFarben = new Array("braun", "blau", "pink", "rot", "gruen");
	var title = getActiveStyleSheet() ? getActiveStyleSheet() : getPreferredStyleSheet();
	for (i=0; i < dieFarben.length; i++) {
		if (dieFarben[i] == title) {
			break;
		}
	}
	wahlFarben = new Array();
	j = 0;
	for (i=0; i < dieFarben.length; i++) {
		if (dieFarben[i] != title) {
			wahlFarben[j] = dieFarben[i];
			j++;
		}
	}
	zufall = Math.round(Math.random() * (wahlFarben.length - 1));
	setActiveStyleSheet(wahlFarben[zufall]);
}

function setActiveStyleSheet(title) {
  var i, a, b, 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;
    }
  }
  for(i=0; (b = document.getElementsByTagName("img")[i]); i++) {
    if(b.getAttribute("class") && b.getAttribute("class").indexOf("strich") != -1) {
      b.src = "img/strich" + title + ".gif";
    }
    else if (document.all) {
			for(i=0; (b = document.all.tags("img")[i]); i++) {
				if (document.all.tags("img")[i].className == "strich") {
      		b.src = "img/strich" + title + ".gif";
				}
			}
		}
	}
}

function getActiveStyleSheet() {
  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;
}

function getPreferredStyleSheet() {
  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;
}

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) {
	/* setze beim Aufruf der Startseite den Stil auf "braun" zurueck: */
	if ((window.location.href.indexOf("index.html") != -1) || (window.location.href.indexOf(".html") == -1)) {
 		createCookie("pnstyle", "braun", 90);
 	}
	/* initFlash(); */
	initNavig("contact"); /* siehe navig.js */
	initNavig("load");
	initNavig("link");
	initNavig("start");
	initNavig("gigs");
	initNavig("listen");
	initNavig("profile");
	initNavig("bands");
	
  var cookie = readCookie("pnstyle");
  var title = cookie ? cookie : getPreferredStyleSheet();
  setActiveStyleSheet(title);
}

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

var cookie = readCookie("pnstyle");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);
// ]]>
