// written by Chris Oakman
// please send all questions to chris.oakman@gmail.com
// 
// this script is pretty complicated, so I tried to comment most everything
// if you have any questions about it, please feel free to e-mail me
// 
// Note: if you only want to add/remove some images, please ONLY modify the section marked below!

// Set slideShowSpeed (seconds)
var slideShowSpeed = 5;
// Duration of crossfade (seconds)
var crossFadeDuration = 3;
// Specify the image files
var Pic = new Array();

// EDIT THIS SECTION ONLY TO ADD/REMOVE/CHANGE THE IMAGES DISPLAYED
// NO FURTHER MODIFICATION OF THE SCRIPT SHOULD BE NECESSARY FOR
// YOUR CHANGES TO TAKE PLACE
//#####################################################################
//
Pic[0] = 'images/slideshow/a.jpg';
Pic[1] = 'images/slideshow/b.jpg';
Pic[2] = 'images/slideshow/c.jpg';
Pic[3] = 'images/slideshow/d.jpg';
Pic[4] = 'images/slideshow/e.jpg';
Pic[5] = 'images/slideshow/f.jpg';
Pic[6] = 'images/slideshow/g.jpg';
Pic[7] = 'images/slideshow/h.jpg';
Pic[8] = 'images/slideshow/i.jpg';
Pic[9] = 'images/slideshow/j.jpg';
//
//#####################################################################
//

// do not edit anything below this line
var t;
var j = Math.floor(Math.random() * Pic.length);
var p = Pic.length;
var loaded = false;

//---------------------------------------
var counter = 0;
var beenUsed = new Array();
for (i = 0; i < p; i++)
{
	beenUsed[i] = false;
}
beenUsed[j] = true; // first image
//---------------------------------------

var preLoad = new Array();

function runpreLoad() // this function is so that people on a slow connection can view page content
	 	      // without having to download all of the images beforehand, they just see the 
		      // original image until the slideshow is ready to start
{
	for( i=0; i<p; i++)
		{
			preLoad[i] = new Image();     // preload ALL
			preLoad[i].src=Pic[i];
		}
	t = setTimeout('runSlideShow()', (crossFadeDuration * 1000) );
};

function runSlideShow() 
{
	if (document.all) 	// IE
				// Note: images change for Netscape, Mozilla, etc, but
				// they loose the nifty blending transition effect
	{
		document.images.SlideShow.style.filter="blendTrans(duration=crossFadeDuration)";
		document.images.SlideShow.filters.blendTrans.Apply();
	}
	document.images.SlideShow.src = preLoad[j].src;
	if (document.all) 
	{
		document.images.SlideShow.filters.blendTrans.Play();
	}
		
	// Code to iterate randomly every 'p' images
	//------------------------------------------	
	counter++;	
	if (counter >= p)
	{	
		for(i = 0; i <= p; i++)
			beenUsed[i] = false;
		counter = 0;
	}	

	j = Math.floor(Math.random() * p); // so that the last image of one iteration won't 
					   // be the first image of the next one
	while (beenUsed[j])
		j = Math.floor(Math.random() * p); 
	beenUsed[j] = true;
	//------------------------------------------
	
	t = setTimeout('runSlideShow()', (slideShowSpeed * 1000));
}
