/*
	slideshow.js
	class for a slide show of pictures
*/

/*
*	class: SlideShow
*	path is url path to directory containing pictures
*	pics is an array of filenames containing the picture to show
*	IdTag is the id of the img tag to use for the slide show ( can be the element itself )
*	time is the lenght of time between each picture
*/
function SlideShow(path, pics, IdTag, time)
{
	this.path = path;
	this.pics = pics;
	this.time = time
	if ( typeof(IdTag) == "string" )
		this.el = document.getElementById(IdTag);
	else
		this.el = IdTag;
}

SlideShow.prototype.preload = function()
{
	this.el.src = this.path + this.pics[0];
	for ( var i = 0; i != this.pics.length; i++ )
	{
		var img = new Image();
		img.src = this.path + this.pics[i];
	}
}

SlideShow.prototype.start = function()
{
	var obj = this;
	var doChange = function() {obj.changeImage.call(obj);};
	
	this.ref = 0;
	
	if ( this.timer != undefined )
		clearInterval(this.timer);
		
	this.timer = setInterval(doChange, this.time);
}

SlideShow.prototype.changeImage = function()
{
	this.ref++;

	if ( this.ref == this.pics.length )
		this.ref = 0;
	
	this.el.src = this.path + this.pics[this.ref];
}
		

SlideShow.prototype.toString = function()
{
	return this.pics.length + " images in " + this.path + ". Image id is " + this.el.id;
}
