/*
* 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) 
{
	this.imageArray[this.imageArray.length] = src;
};

/*
* 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];

};

