<!--
/**
 * @author Oluwole Okunseinde.
 * Description: This file contains functions and variables for displaying and navigating through slide images.
 */

var strImagesPath;				// Full path to slide images.
var strExtension;				// Slide images file extension.
var strImgName;					// Slide image name.
var intNumSlides;				// Total number of slides.
var intCurrentSlideNum;			// Current slide number.
var strCommonPart;				// Common part of each slide name.

/**
 * Displays the slide specified by the slide name function parameter.
 * @param	strName	Name of the slide image to display.
 */
function LoadSlide(strName) {
  var strSlidePath = strImagesPath + strName + strExtension;
  var intNumberPart = 0;
  var intTemp = 0;
  
  if(strName.toLowerCase() == "first")
	intTemp = 1;
  else if(strName.toLowerCase() == "previous")
	intTemp = intCurrentSlideNum - 1;
  else if(strName.toLowerCase() == "next")
	intTemp = intCurrentSlideNum + 1;
  else if(strName.toLowerCase() == "last")
	intCurrentSlideNum = intNumSlides
  else
	intTemp = parseInt(strName.split(strCommonPart)[1]);

  if((("" + parseInt(intTemp)) == intTemp) != "" && (intTemp > 0) && (intTemp <= intNumSlides)) {
	strSlidePath = strImagesPath + strCommonPart + intTemp + strExtension;
	intCurrentSlideNum = intTemp;
  }
  else {
	strSlidePath = strImagesPath + strCommonPart + "1" + strExtension;
	intCurrentSlideNum = intTemp;
  }
  
  document.images[strImgName].src = strSlidePath;
}

/**
 * Initializes variables.
 */
function Init() {
  var objSlideImg = null;		// The slide image object.
  var strImgSrc = "";			// Image source.
  
  strImagesPath = "";
  strExtension = "";
  strImgName = "";
  intNumSlides = document.getElementsByTagName("li").length;
  intCurrentSlideNum = 0;
  
  if(document.images) {
	objSlideImg = document.getElementsByTagName("img")[0];
	
	if(objSlideImg != null) {
	  strImgName = objSlideImg.id;
	
	  if(strImgName == "")
		strImgName = objSlideImg.name;

	  if(strImgName != "") {
		strImgSrc = objSlideImg.src
		strImagesPath = strImgSrc.substring(0, (strImgSrc.lastIndexOf('/') + 1));
		strExtension = strImgSrc.substring(strImgSrc.lastIndexOf('.'), strImgSrc.length);
		strCommonPart = strImgSrc.substring((strImgSrc.lastIndexOf('/') + 1), strImgSrc.lastIndexOf('.'));
	  }
	}
  }
}

/**
 * Determines there is a hash slide name in the page URL which indicates that the user clicked on a slide link in the lecture 
 * notes. If there is a hash slide name this function will set the current slide to the slide specified in the page URL.
 */
function CheckURL() {
  var strSlideNameFromURL		// Name of the slide in the URL hash.
  var intNumberPart = 0;		// Number part of slide name.
  
  if(location.hash != "" && (location.hash).indexOf(strCommonPart) > -1) {
	strSlideNameFromURL = (location.hash).substring(1, (location.hash).length);
	LoadSlide(strSlideNameFromURL);
  }
  else
	LoadSlide("");
}

window.onload = function() {
  Init();
  CheckURL(); 
}
-->
