//-------------------------------------------------
// Style Sheet Switcher functionality
// written by Paul Sowden: http://idontsmoke.co.uk/
//
// Referenced through A List Apart: 
// http://www.alistapart.com/articles/alternate/
//-------------------------------------------------

function nextImage(move) {
currentPhoto=document.bigImage.src;
lastSlash=currentPhoto.lastIndexOf('/') + 1
currentPhoto=currentPhoto.substring(lastSlash,currentPhoto.length)

for (n=0; n < photoArray.length; n++) {
		newPhoto=photoArray[n]
		lastSlash=photoArray[n].lastIndexOf('/') + 1
		newPhoto=newPhoto.substring(lastSlash,newPhoto.length)
		if (currentPhoto == newPhoto) {

	var nextID=n+move
	}
	}
	newPhoto=photoArray[nextID]
	
	if (nextID==photoArray.length) {
	nextID=0
	newPhoto=photoArray[0]
	}
	if (nextID==-1) {
	nextID=photoArray.length-1
	newPhoto=photoArray[nextID]
	}
	document.bigImage.src="";
	document.getElementById('captionText').firstChild.nodeValue = " ";
	eval("document.bigImage.src='" + newPhoto + "'");
	document.getElementById('captionText').firstChild.nodeValue = caption[nextID];
}


function helpPop(topic) {
openURL="../help/" + topic + ".html";
window.open(openURL,"helpWindow","WIDTH=350,HEIGHT=350,screenX=300");
}

function setActiveStyleSheet(pTitle) {
  var vLoop, vLink;
  for(vLoop=0; (vLink = document.getElementsByTagName("link")[vLoop]); vLoop++) {
    if(vLink.getAttribute("rel").indexOf("style") != -1 && vLink.getAttribute("title")) {
      vLink.disabled = true;
      if(vLink.getAttribute("title") == pTitle) vLink.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;
}

function addSPtoQS(obj) {
	obj.setAttribute("href", obj.href + "&sp=" + document.documentElement.scrollTop);
}

window.onload = function(e) {
  var cookie = readCookie("style");
  var title = cookie ? cookie : getPreferredStyleSheet();
  setActiveStyleSheet(title);
  
//  if (document.forms[0].inputSP)
 // {
//	window.scrollTo(0, document.forms[0].inputSP.value);
 // }
}

window.onunload = function(e) {
  var title = getActiveStyleSheet();
  createCookie("style", title, 365);
}
