/* Image Cycler. (C) D. Keith Higgs 1999, 2000, 2001
	 Written and maintained by Keith Higgs <dkh2@po.cwru.edu>
   This script is available free of charge.
	 You are free to modify or enhance this script in any way.  Please send 
	 copies of functional enhancements to the original script author at
	 dkh2@po.cwru.edu for inclusion in the archival version.
	 A web page where you may download the latest version of this script is
	 currently under consideration. Information regarding such a page will be
	 made available at http://www.cwru.edu/UL/pershomepages/K_Higgs.html when
	 it is ready.
*/

/* Installation:
		1) Save this file to your server with a name ending with .js

		2) Include the following tag in the head of your document:

		<script language="JavaScript" type="text/javascript" src=""></script>

				in which you insert the URL of the .js file into the src="" attribute.

		3) Include the following attribute into the BODY tag:
			 	onload="startPix();"
			 If you have multiple scripts to be started by the onload handler
				you can add them to the same argument, separating them with semicolons: 
					onload="foo();startPix();bar();"

		4) Insert the following script tag into your document at the point where
				you want the slideshow to appear:

		<script language="JavaScript" type="text/javascript">loadFirstPic()</script>  

		5) Also include a <noscript></noscript> block in your document, immediately after the 
                                script tage in step 4 to accomodate browsers that do not have 
                                Javascript support, or have it turned off.

                <noscript><img src="http://www.cwru.edu/UL/pix/homepage/ksl_20.jpg" alt="Slideshow" 
                          name="ChangingPix" border="0" style="clear:all" width="166" height="132" 
                          longdesc="Kelvin Smith Library as seen from the East side of Severence Hall" 
                          align="center">
                </noscript>
*/

// Begin ImageCycle!
// Create a new array and populate it with images.
//  Each element is a new Image.  
//  Create the image object then set the src attribute to the image URL. 
var Pix = new Array();
	Pix[0] = new Image();
	Pix[0].src = "PagePic100.jpg";
	Pix[1] = new Image();
	Pix[1].src = "PagePic101.jpg";
	Pix[2] = new Image();
	Pix[2].src = "PagePic102.jpg";
	Pix[3] = new Image();
	Pix[3].src = "PagePic103.jpg";
	Pix[4] = new Image();
	Pix[4].src = "PagePic104.jpg";
        Pix[5] = new Image();
	Pix[5].src = "PagePic105.jpg";
	
	
	
// Store the number array entries.
// Array elements are numbered (0 to(n-1)), This stores (n)
var howMany = Pix.length;

// set number of seconds between images.
// Adjust seconds * 1000 == milliseconds
// for use with setInterval() in startPix() below.
var timeDelay = 2;
timeDelay *= 1000;

function rndnumber(){
// Generate a random number ranging (0,n).
	var randscript = -1;
	while (randscript < 0 || randscript > howMany || isNaN(randscript)){
			randscript = parseInt(Math.random()*(howMany+1));
			--randscript;
	}
	return randscript
}

// Select the first image to be shown.
var PicCurrentNum = rndnumber();
// Create an image with a constant name.
var PicCurrent = new Image();
// Get URL for the image by reading the src attribute.
PicCurrent.src = Pix[PicCurrentNum].src;


function loadFirstPic() { 
// Does exactly what the name says it does.
	document.write("<img src=" + Pix[PicCurrentNum].src + " alt=\"Slideshow\" name=\"ChangingPix\" border=\"0\" style=\"clear:all\" width=\"100\" height=\"100\" longdesc=\"Slideshow, pictures of Kelvin Smith Library\" align=\"center\">");
}

function startPix() {	
// Set slideshow() to run at the specified interval.
	setInterval("slideshow()",timeDelay);	
}

function slideshow() {
// Define the slideshow() function you just scheduled.
// Increment the pointer because you are already viewing the current value.
	++PicCurrentNum; 
	if (PicCurrentNum == howMany) {
		// Cycle the pointer back to 0 if you try to go past the end of the array.
		PicCurrentNum = 0; 					 
	}
	// assign the new URL for the image.
	PicCurrent.src = Pix[PicCurrentNum].src;
	// Replace the image on the page!
	document["ChangingPix"].src = PicCurrent.src;
}
// End of ImageCycle -->
