// JavaScript Document

/***********************************************
* Flexi Slideshow- © Dynamic Drive (www.dynamicdrive.com)
* This notice must stay intact for use
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/

/*
 *	User note: This script requires functions in usefulfxns.js ( readDir() ).
 *				Make sure it is also included in index.php.
 */


/*************************
*	Slideshow variables
*************************/

	var variableslide=new Array();
	//variableslide[x]=["path to image", "OPTIONAL link for image", "OPTIONAL text description (supports HTML tags)"]
	
	var slideshowdir = "images/slideshow";			// the directory containing the pictures for the slideshow

	/*
		Each index of picNameArray will be the name of a picture in the slideshowdir folder.
		***Now to add/remove pictures from the slideshow simply add/remove them from the slideshow folder!***
	*/
	var picNameArray = readDir(slideshowdir);
													
	//configure the below 3 variables to set the dimension/background color of the slideshow
	var slidewidth='560px'; 	//set to width of LARGEST image in your slideshow
	var slideheight='718px'; 	//set to height of LARGEST iamge in your slideshow, plus any text description
	var slidebgcolor='#000000';
	
	//configure the below variable to determine the delay between image rotations (in miliseconds)
	var slidedelay=4000;
	
	////Do not edit pass this line////////////////
	// I did, fight me.
	
	var ie=document.all;
	var dom=document.getElementById;
	
	var currentslide=0;

/**************************
*	Slideshow Functions
**************************/

/*
 * @author DynamicDrive
 *
 * Starts the slideshow.
 */
function start_slider(){
	crossrotateobj=dom? document.getElementById("slidedom") : ie? document.all.slidedom : document.slidensmain.document.slidenssub;

	if (document.layers)
		document.slidensmain.visibility="show";
		
	rotateimages();
}

/*
 *@author DynamicDrive
 *
 * Handles the switching of images in the slideshow.
 *
 * Indented by Clint to make it readable.
 */
function rotateimages(){
	contentcontainer='<center>';
	
	if (variableslide[currentslide][1]!="")
		contentcontainer+='<a href="../'+variableslide[currentslide][1]+'">';
		
	contentcontainer+='<img src="../'+variableslide[currentslide][0]+'" border="0" vspace="3">';
	
	if (variableslide[currentslide][1]!="")
		contentcontainer+='</a>';
	
	contentcontainer+='</center>';
	
	if (variableslide[currentslide][2]!="")
		contentcontainer+=variableslide[currentslide][2];
	
	slidedelay = 4000;
	
	if (document.layers){
		crossrotateobj.document.write(contentcontainer);
		crossrotateobj.document.close();
	}
	else if (ie||dom)
		crossrotateobj.innerHTML=contentcontainer;
	
	if (currentslide!=variableslide.length-1){
		currentslide++;
		setTimeout("rotateimages()",slidedelay);
	} else { 
		currentslide=0;
		variableslide.sort( randOrd );
		setTimeout("rotateimages()",slidedelay);
	}	
} 

/*
 * @author John
 *
 * Returns a random number.  Used to randomize the order of slideshow pics.
 */
function randOrd(){ return (Math.round(Math.random())-0.5); }

/*
 * @Clint 
 *
 * Compiled all the code that needs to run for the slideshow into one place. DynamicDrive originally
 *	had it scattered all over the place.
 */
function runSlideShow(){

	/*
	// Uncomment this to see all of the pics that will be added to the slideshow 
	// This is just the fxn printArray from usefulfxns.js but usefulfxns might not be included
	//		so functionality is put here just in case
		var pics;
		for(i = 0; i < picNameArray.length; i++){
			pics += picNameArray[i] + "\n";
		}
		alert(pics);
	*/
	
	for (i = 0; i < picNameArray.length; i++){
		variableslide[i] = [slideshowdir + "/" + picNameArray[i], '', ''];
	}
	
	variableslide.sort( randOrd );
	
	for (i=0;i<variableslide.length;i++){
		var cacheimage=new Image();
		cacheimage.src=variableslide[i][0];
	}
	
	if (ie||dom)
		document.write('<div id="slidedom" style="width:'+slidewidth+';height:'+slideheight+'; background-color:'+slidebgcolor+'"></div>');
	
	if (ie||dom)
		start_slider();
	else if (document.layers)
		window.onload=start_slider;

}





