/*
* Requires: imageutils.js
*
*/

/*
* This class provides a way to collect a set of images and have them
* continuously swap together.
*/
ImageSwapper = function(imageName, showMillis) 
{
   this.imageArray = new Array();
   this.imageIdx = 0;
   this.imageName = imageName;
   this.showMillis = showMillis;
};

/*
* Adds an image source/location to the list of 
* images used in the continuous swapping
*/
ImageSwapper.prototype.addImage = function(src) 
{
	var tmpImg = new Image();
	tmpImg.src = src;
	this.imageArray[this.imageArray.length] = tmpImg;

	// trick using a hidden div
	// create a hidden div to allow the image to load
//	document.write("<div style=\"display:none;\"><img src=\""
//		+ src + "\"></div>");
};

/*
* This is the method that starts the swapping, and then
* sets a time, based on the showMillis 
*/
ImageSwapper.prototype.startSwapping = function() 
{
	this.swapImages();
	this.imageIdx++;
	if (this.imageIdx == this.imageArray.length) {
		this.imageIdx = 0;
	}

	var self = this;
	setTimeout(function() { self.startSwapping(); }, this.showMillis);
};


/*
* This resets the images source
*/
ImageSwapper.prototype.swapImages = function() {
    
    //make new image the foreground
    document.getElementById(this.imageName).src = this.imageArray[this.imageIdx].src;

};
