/*
* Requires: ImageSwapper.js
*
*/

/*
* This class provides a way to collect a set of images and have them
* continuously swap together.
*/
ClickImageSwapper = function(imageName, linkName, showMillis) 
{
   this.linkArray = new Array();
   this.linkName = linkName;
   this.imageSwapper = new ImageSwapper(imageName, showMillis);
};

/*
* Adds an image source/location to the list of 
* images used in the continuous swapping
*/
ClickImageSwapper.prototype.addImage = function(src, link) 
{
	this.imageSwapper.addImage(src);
	this.linkArray[this.linkArray.length] = link;
};

/*
* This is the method that starts the swapping, and then
* sets a time, based on the showMillis 
*/
ClickImageSwapper.prototype.startSwapping = function() 
{
	this.imageSwapper.swapImages();
	this.swapLink();


	this.imageSwapper.imageIdx++;
	if (this.imageSwapper.imageIdx == this.imageSwapper.imageArray.length) {
		this.imageSwapper.imageIdx = 0;
	}

	var self = this;
	setTimeout(function() { self.startSwapping(); }, this.imageSwapper.showMillis);
};

/*
* This resets the images source
*/
ClickImageSwapper.prototype.swapLink = function() {
    
    //make new image the foreground
    document.getElementById(this.linkName).href = this.linkArray[this.imageSwapper.imageIdx];

};

