/* Usage

<link href="../css/main_xl.css" rel="alternate stylesheet" title="x-large" type="text/css" media="screen" />
<a href="#" onclick="setActiveStyleSheet('normal'); return false;" id="norm">Normal</a>
<a href="#" onclick="setActiveStyleSheet('large'); return false;" id="large">Large</a>
<a href="#" onclick="setActiveStyleSheet('x-large'); return false;" id="x-large">X-Large</a>

*/

/* to resize height of #content */
/* defining this here as well to keep the browsers from throwing an error */ 
function prep_contentHeight(styleSheet){
	if(!document.getElementsByTagName || !document.getElementById){
		return false;
	}
	if(document.getElementById("content")){
		var content = document.getElementById("content");
		if(document.getElementById("insideContent")){
			var insideContent = document.getElementById("insideContent");
			var outershell = document.getElementById("outershell");
			var flashContent = document.getElementById("flashContent");
			var theH = insideContent.scrollHeight;
			//var theH = "foo";
			//alert(styleSheet);
				if(!flashContent){
					if(content.scrollHeight < insideContent.scrollHeight){
						content.style.height = (insideContent.scrollHeight + 60) + "px";
						if(styleSheet == "x-large"){
							outershell.style.height = (insideContent.scrollHeight + 355) + "px";
						}
						else {
							outershell.style.height = (insideContent.scrollHeight + 355) + "px";
						}
					}
				}
				else {
					if(content.scrollHeight < insideContent.scrollHeight){
						content.style.height = (insideContent.scrollHeight + 60) + "px";
						flashContent.style.height = 440 + "px";
						if(styleSheet == "x-large"){
							outershell.style.height = (insideContent.scrollHeight + 355) + "px";
						}
						else {
							outershell.style.height = (insideContent.scrollHeight + 355) + "px";
						}
					}
				}
				
			}
		}
		if(document.getElementById("indexContent") && navigator.appName != "Microsoft Internet Explorer"){
			var indexContent = document.getElementById("indexContent");
			var outershell = document.getElementById("outershell");
			outershell.style.height = (indexContent.scrollHeight + 295) + "px";
			}
	}

/* global resources */

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

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

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) {
  var cookie = readCookie("style");
  var title = cookie ? cookie : getPreferredStyleSheet();
  setActiveStyleSheetLoad(title);
}

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

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