// Slideshow code adpated from js code lifted from http://www.codelifter.com. Some copyright them, but I ripped the heck out of it.
// Crossfade effect only in IE/Win via server-side detect. Hate to use something that's not a web standard, but it's so slick.

var slideShowSpeed = 5;     //in seconds
var crossFadeDuration = 2   //in seconds, IE/Win only
var initialPreloadMax = 6;
		
var timeout;
var nextImageIndex = 1;
var preLoad = new Array();
var isBlendTransitionsActive = false;

function startSlideShow(pics, doBlendTransitions)
{
	isBlendTransitionsActive = doBlendTransitions;
	var i = 0;

	//just preload a few images before starting slideshow. that should give us a decent buffer
	var initialPreloadCount = (pics.length < initialPreloadMax) ? pics.length : initialPreloadMax;
	for (i = 0; i < initialPreloadCount; i++) {
		preLoad[i] = new Image();
		preLoad[i].src = pics[i];        
	}
	timeout = setTimeout('runSlideShow()',slideShowSpeed*1000);
	
	for (i = i; i < pics.length; i++) { //finish preloading any remaining images
		preLoad[i] = new Image();
		preLoad[i].src = pics[i];
	}
}

function runSlideShow() {
	if (preLoad[nextImageIndex]) { 
	if (isBlendTransitionsActive)
	{
			document.images.SlideShow.style.filter="blendTrans(duration=2)";
			document.images.SlideShow.style.filter="blendTrans(duration=crossFadeDuration)";
			document.images.SlideShow.filters.blendTrans.Apply();
	}
	document.images.SlideShow.src = preLoad[nextImageIndex].src;
	if (isBlendTransitionsActive)
	{
			document.images.SlideShow.filters.blendTrans.Play();
	}
		nextImageIndex++;
		if (nextImageIndex == pics.length)
			nextImageIndex = 0;
	}
	timeout = setTimeout('runSlideShow()',slideShowSpeed*1000);
}

