// Copyright Duncan Stigwood (duncan@flamingegg.co.uk)
function style2hover() {
	if(document.location.hash) { 
		var e=document.location.hash;
		document.getElementById(e.substring(1)+"h").style.display='block';
		document.getElementById(e.substring(1)+"d").style.display='block';
	}
}
function style2hovers() {
	var x = document.getElementsByTagName('div');
	for (var i=0;i<x.length;i++){
		if (x[i].className == 'site'){
		    if(x[i].id) {
			x[i].onmouseover = function() {
				var y = document.getElementsByTagName('div');
				for (var j=0;j<y.length;j++){
					if (y[j].className == 'site'||y[j].className == 'site first') {
						var e = y[j].getAttribute('id');
						document.getElementById(e+"h").style.display = 'none';
						document.getElementById(e+"d").style.display = 'none';
						}
				}
				document.getElementById(this.id+"h").style.display='block';
				document.getElementById(this.id+"d").style.display='block';
				}
			}}
	}
	style2hover();
}
function style2remove() {
	var x = document.getElementsByTagName('div');
	for (var i=0;i<x.length;i++){
		if (x[i].className == 'site'||x[i].className == 'site first'){
		    if(x[i].id) {
			x[i].onmouseover = function() {};
			var e = x[i].getAttribute('id');
			document.getElementById(e+"h").style.display = '';
			document.getElementById(e+"d").style.display = '';
			}}
	}
}
// Copyright A List Apart
function switchsheet(title) {
   var i, a, main;
   for(i=1; i<10; i++){
	   if(document.getElementById("style"+i)) document.getElementById("style"+i).style.color="";
	   }
   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;
	   		document.getElementById(title).style.color="white";
			if(title=="style2") {style2hovers();} else {style2remove();}
	   }
     }
   }
}
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;
}
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;
}
window.onunload = function(e) {
  var title = getActiveStyleSheet();
  createCookie("style", title, 365);
}
/*************************************************************
** ONLOAD SCRIPT - adapted from the window.onload script
**    written by Dean Edwards - http://dean.edwards.name
**************************************************************/
function init() {
  // quit if this function has already been called
  if (arguments.callee.done) return;

  // flag this function so we don't do the same thing twice
  arguments.callee.done = true;

  // execute these items when page is loaded
  var cookie = readCookie("style");
  var title = cookie ? cookie : getPreferredStyleSheet();
  if(title=="null"||title=="default"){
	title=1;
  } else {
  	switchsheet(title); 
  }
};

/* for Mozilla */
if (document.addEventListener) {
  document.addEventListener("DOMContentLoaded", init, false);
}

/* for Internet Explorer */
/*@cc_on @*/
/*@if (@_win32)
  document.write("<script id='__ie_onload' defer src='javascript:void(0)'></script>");
  var script = document.getElementById("__ie_onload");
  script.onreadystatechange = function() {
      if (this.readyState == "complete") {
          init(); // call the onload handler
      }
  };
/*@end @*/

/* for Safari */
if (/WebKit/i.test(navigator.userAgent)) {  // sniff
  var _timer = setInterval(function() {
      if (/loaded|complete/.test(document.readyState)) {
          clearInterval(_timer);
          init();  // call the onload handler
      }
  }, 10);
}

/* for other browsers */
window.onload = function(e) {
  init();
}
/************************************************************
** END ONLOAD SCRIPT
*************************************************************/