// Edit these to change the value of the text in the search inputs
var ezSearchText     = 'Enter Search Terms to Find Books and Articles';
var googleSearchText = 'Enter Search Terms Here';
	
// How often the image rotates, in seconds.
var imageDelay = 4;

// Set to 1 to rotate images automatically, 0 to not           
var play       = 1;
var playButtonSrc  = "/images/hpmisc/play.gif";
var pauseButtonSrc = "/images/hpmisc/pause.gif";

// Do Not Edit These Lines ...
var totalImage = 0;           // Total number of images to rotate through
var riCurrent  = 0;           // Which Image we are currently On
var imageSrc   = new Array(); // Image src paths
var imageAlt   = new Array(); // Alternate Text for each image
var imageLnk   = new Array(); // Link for the current Image
var imageTtl   = new Array(); // Descriptive Title for Current Image Link
var imageLoc   = "/images/hpads/";
// ...
	
// Begin Editing Here
// Each 4 lines is a new image, edit only the text between quotes ("")
    
imageSrc[++riCurrent] = new createImage(imageLoc + "appalachian.gif");
imageAlt[riCurrent]   = "Application Collection";
imageLnk[riCurrent]   = "http://www.libraries.wvu.edu/appalachian/bibliography.htm";
imageTtl[riCurrent]   = "Application Collection";

imageSrc[++riCurrent] = new createImage(imageLoc + "ask_librarian.gif");
imageAlt[riCurrent]   = "Ask a Librarian";
imageLnk[riCurrent]   = "http://www.libraries.wvu.edu/ask/";
imageTtl[riCurrent]   = "Ask a Librarian";

imageSrc[++riCurrent] = new createImage(imageLoc + "elizas.gif");
imageAlt[riCurrent]   = "Elizas";
imageLnk[riCurrent]   = "http://www.libraries.wvu.edu/elizas/";
imageTtl[riCurrent]   = "Elizas";

imageSrc[++riCurrent] = new createImage(imageLoc + "guide_to_archives.gif");
imageAlt[riCurrent]   = "Guide to Archives and Manuscripts";
imageLnk[riCurrent]   = "http://findingaids.lib.wvu.edu/cgi/f/findaid/findaid-idx?c=wvcguide";
imageTtl[riCurrent]   = "Guide to Archives and Manuscripts";

//imageSrc[++riCurrent] = new createImage(imageLoc + "patents_trademarks.gif");
//imageAlt[riCurrent]   = "Patents and Trademarks";
//imageLnk[riCurrent]   = "http://www.libraries.wvu.edu/patents/";
//imageTtl[riCurrent]   = "Patents and Trademarks";

imageSrc[++riCurrent] = new createImage(imageLoc + "honor.gif");
imageAlt[riCurrent]   = "Honor with Books";
imageLnk[riCurrent]   = "http://www.libraries.wvu.edu/friends/images/honorwithbooks.pdf";
imageTtl[riCurrent]   = "Honor with Books";

//imageSrc[++riCurrent] = new createImage(imageLoc + "termpaper_clinic.gif");
//imageAlt[riCurrent]   = "Term Paper Clinic";
//imageLnk[riCurrent]   = "http://www.libraries.wvu.edu/instruction/clinic.htm";
//imageTtl[riCurrent]   = "Term Paper Clinic";

imageSrc[++riCurrent] = new createImage(imageLoc + "suggest.gif");
imageAlt[riCurrent]   = "Suggest a Purchase";
imageLnk[riCurrent]   = "http://www.libraries.wvu.edu/services/suggestions/";
imageTtl[riCurrent]   = "Suggest a Purchase";

//imageSrc[++riCurrent] = new createImage(imageLoc + "valentine.gif");
//imageAlt[riCurrent]   = "Vintage Valentine Cards";
//imageLnk[riCurrent]   = "http://www.libraries.wvu.edu/exhibits/valentine/";
//imageTtl[riCurrent]   = "Vintage Valentine Cards";

//imageSrc[++riCurrent] = new createImage(imageLoc + "refworks.gif");
//imageAlt[riCurrent]   = "Refworks";
//imageLnk[riCurrent]   = "http://www.libraries.wvu.edu/databases/cgi-bin/databases.pl?1185309093=invs";
//imageTtl[riCurrent]   = "Refworks";

//imageSrc[++riCurrent] = new createImage(imageLoc + "libqualc.gif");
//imageAlt[riCurrent]   = "Tell the Libraries What You Think";
//imageLnk[riCurrent]   = "http://www.libraries.wvu.edu/news/2009/04/12/tell-the-libraries-what-you-think/";
//imageTtl[riCurrent]   = "Tell the Libraries What You Think";



// Stop Editing Here
    
if ( window.addEventListener ) {
        var kkeys = [], konami = "38,38,40,40,37,39,37,39,66,65";
        window.addEventListener("keydown", function(e){
                kkeys.push( e.keyCode );
				if ( kkeys.toString().indexOf( konami ) >= 0 ) {
					kkeys = [];
					alert("Libraries are not made; they grow.\n- Augustine Birrell");
				}
        }, true);
}

totalCount = riCurrent;
riCurrent  = 0;
    
function randomBackground() {
	element = document.getElementById("mainDiv");
	element.style.backgroundImage = "url(/images/hpbg/" + (Math.floor(Math.random() * 3) +1) + ".gif)";
}

function createImage(image_location) {
	this.image = new Image();
  this.image.src = image_location;
}

function rotateImages(action) {
        
	if (action == "None") {
		riCurrent++;
	}
	if (action == "next") {
		riCurrent++;
		clearTimeout(timeout);
	}
	if (action == "previous") {
		--riCurrent;
		clearTimeout(timeout);
	}
	if (action == "play") {
		if (play == 0) {
			play = 1;
			riCurrent++;
			document.getElementById("playButton").src = pauseButtonSrc;
		}
		else {
			play=0;
			document.getElementById("playButton").src = playButtonSrc;
			clearTimeout(timeout);
		}
	}

	if (riCurrent > totalCount) {
		riCurrent = 1;
	}

	if (riCurrent <= 0) {
		riCurrent = totalCount;
	}

  document.getElementById("adLink").href  = imageLnk[riCurrent]; 
  document.getElementById("adLink").title = imageTtl[riCurrent]; 
  document.getElementById("adImage").src  = imageSrc[riCurrent].image.src;
  document.getElementById("adImage").alt  = imageAlt[riCurrent];
        
  if (play == 1) {       
	timeout = setTimeout("rotateImages('None')", imageDelay*1000);
  }
}  

function relocateOffCampusShow (input) {
	document.getElementById('offCampusEZSearchAuth').style.left = "12.5%";
}
	
function relocateOffCampusHide () {
	document.getElementById('offCampusEZSearchAuth').style.left = "-3000px";
}

function loadSearches () {
	document.getElementById("siteSearchInput").value = googleSearchText;
	document.getElementById("ezSearchInput").value = ezSearchText;
}

function clearFormInput (input) {

	element = input.id;
	var replace = ezSearchText;

	if (element == 'siteSearchInput')
	replace = googleSearchText;

	if (document.getElementById(element).value == replace) {
		document.getElementById(element).value=''
	}

	return;

}

function fillFormInput (input) {

	var element = input.id;
	var replace = ezSearchText;

	if (element == 'siteSearchInput')
	     replace = googleSearchText;

	if (document.getElementById(element).value == '') {
		document.getElementById(element).value = replace;
	}

}
