/**
 *	Copyright ©2006 Wilson Wise. All rights reserved.
 *	
 *	A very simple Slideshow.
 *	
 *	How to use:
 *	
 *	In <head> define your show and slides:
 *	
 *		var slidesArray = new Array();
 *		slidesArray.push('foo.img');
 *		slidesArray.push('bar.img');
 *		
 *		var slidesDomElementId = 'slidesDomElementId';
 *		
 *		var slideShowSpeedInSeconds = 4;
 *		
 *		var mySlideShow = new Slideshow( slidesArray, slidesDomElementId, slideShowSpeedInSeconds ); 
 *
 *	Next, onload call the load method passing it the variable name of your slide show:
 *	
 *		window.onload = function() {
 *			mySlideShow.load('mySlideShow');
 *		}
 *		
 *	All that is left is to place a <img> tag somewhere on the page with the id you specified in slidesDomElementId:
 *	
 *		<img id="slidesDomElementId" />
 *
 */
function Slideshow(arr, strId, speed) {
	// Locals
	this.imgID		  = strId;
	this.slideShow    = arr;
	this.currentSlide = -1;
	this.showSpeed    = speed*1000; // secs
	this.showName     = '';
	this.t;
}
	
// Methods
Slideshow.prototype.load = function(name) {
	this.showName  = name;
	// Preload images
	var len = this.slideShow.length;
	var img = new Image();
	for ( var i = 0; i < len; i++ ) {
		img.src = this.slideShow[i];
	}
	this.play();
};
Slideshow.prototype.play = function() {
	this.currentSlide = (this.currentSlide + 1 < this.slideShow.length) ? this.currentSlide + 1 : 0;
	this.display();
	this.t = setTimeout(this.showName + '.play()', this.showSpeed);
};
Slideshow.prototype.display = function() {
	if ( this.currentSlide > -1 ) this.ele().src = this.slideShow[this.currentSlide];
};
Slideshow.prototype.ele = function(str) {
	if ( window.all )
		return window.all[this.imgID];
	else
		return document.getElementById(this.imgID);
};
