// Slide show cross fader
// Pass the parent id's wrapper, speed of fade, hold length, isIE
// Author: Dale Hughes - Creature Works Labs - May 2011
function doSlideshow(slidesWrapper,disSpeed,hold,isIE) {

//var me = this;
	var fps = 20;
	var refreshRate = 1000/fps;
	var outgoing = 0;
	var incoming = 1;
	var decayInc = 1.0 / (disSpeed * fps);
	var outOpacity = 1.0;
	var inOpacity = 0.0;

	// get an array of the ids of the images.
	// This works if using the style of the wrapper "slideshowWrapper"
	//var slides = $("div.slideshowWrapper > img").map(function() {
	//    return this.id;
	//}).get();

	// But in case we have more than one slideshow on the same page, we'll use the id of the wrapper.
	var slides = $("div#"+slidesWrapper+" > img").map(function() {
	    return this.id;
	}).get();


	if (isIE)
		document.getElementById(slides[0]).style.filter="alpha(opacity="+parseInt(outOpacity*100)+")";
	else 
		document.getElementById(slides[0]).style.opacity=outOpacity;
	
	this.fade = function() {
		outOpacity -= decayInc;
		inOpacity  = 1.0 - outOpacity;
		if (outOpacity < .01) {
			outOpacity = 0.0;
			inOpacity = 1.0;
		}
		
		if (isIE) {
			document.getElementById(slides[incoming]).style.filter="alpha(opacity="+parseInt(inOpacity*100)+")";
			document.getElementById(slides[outgoing]).style.filter="alpha(opacity="+parseInt(outOpacity*100)+")";
		}
		else {
			document.getElementById(slides[incoming]).style.opacity=inOpacity;
			document.getElementById(slides[outgoing]).style.opacity=outOpacity;
		}

		if (outOpacity == 0.0) {
			outOpacity = 1.0;
			inOpacity = 0.0;
			outgoing = incoming;
			incoming = outgoing + 1;
			if (incoming > slides.length -1) 
				incoming = 0;
			//setTimeout(function() {me.fade()},hold*1000);
			setTimeout("this.fade()",hold*1000);
		}
		else 
			setTimeout("this.fade()",refreshRate);
			//setTimeout(function() {me.fade()},refreshRate);
	};
	setTimeout("this.fade()",hold*1000);

}

