// JavaScript Document
	function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

addLoadEvent( function() { setPic()} )


var currImg = 0;


function setPic(myIndex) {
	patientLinks = document.getElementById("quickLink").getElementsByTagName("a");
	// set the handler for each image
  for (var i = 0; i < patientLinks.length; i++) {
    qLink = patientLinks[i];
    
    // create the onclick function
    qLink.onclick = gotoPatient;
  }
	if (myIndex == "" || myIndex == null || myIndex < 0)
		myIndex = 0;
		var patient = myIndex + 1;
	document.getElementById("patient").innerHTML = "Patient " + patient;
	document.getElementById("beforeSet").src = "images/gallery/patient" + myIndex + "Pre.jpg";	
	document.getElementById("afterSet").src = "images/gallery/patient" + myIndex + "Post.jpg";	
	document.getElementById("prevLink").onclick = processPrevious;
	document.getElementById("nextLink").onclick = processNext;
	if (myIndex != currImg)
	currImg = myIndex;
}

function gotoPatient() {
	clearClass();
	var patient = parseInt(this.name) + 1;
	document.getElementById("patient").innerHTML = "Patient " + patient;
	document.getElementById("beforeSet").src = "images/gallery/" + this.id + "Pre.jpg";	
	document.getElementById("afterSet").src = "images/gallery/" + this.id + "Post.jpg";
	
	function clearClass() {
	classNames = document.getElementById("quickLink").getElementsByTagName("a");
	// set the handler for each image
  for (var i = 0; i < classNames.length; i++) {
    cNames = classNames[i];
	 if (cNames.className == "selected") {
		 cNames.className = "";
		 								}
  												}
	}
  this.className = "selected";
  currImg = parseInt(this.name);
}



function processPrevious() {
	newSlide(-1);
}

function processNext() {
	newSlide(1);
}

function newSlide(direction) {
	
	var imgCt = 29;
	currImg = currImg + direction;
	if (currImg < 0) {
		currImg = imgCt-1;
	}
	if (currImg == imgCt) {
		currImg = 0;
	}
	clearClass();
	var patient = currImg + 1;
	document.getElementById("patient").innerHTML = "Patient " + patient;
	document.getElementById("beforeSet").src = "images/gallery/patient" + currImg + "Pre.jpg";	
	document.getElementById("afterSet").src = "images/gallery/patient" + currImg + "Post.jpg";
	function clearClass() {
	classNames = document.getElementById("quickLink").getElementsByTagName("a");
	// set the handler for each image
  for (var i = 0; i < classNames.length; i++) {
    cNames = classNames[i];
	 if (cNames.className == "selected") {
		 cNames.className = "";
		 }
  }
	}
  document.getElementById("patient" + currImg).className = "selected";
	
}


	

