/** 
 * This class is useful to create simple immer switcher
 */

HyperlinkImageSwapper.prototype = new Object();
HyperlinkImageSwapper.constructor = HyperlinkImageSwapper;

/** 
 * @image the id of the image to be swapped 
 */
function HyperlinkImageSwapper(imageId) 
{

	/* private members */
	this.currentIndex = 0;
	
	/* public members */
	this.images = new Array();
	this.imageId = imageId;
	
}

/**
 * returns the image object wich is currently associated to this 
 * instance 
 */
HyperlinkImageSwapper.prototype.getImageObject = function() 
{	
	return document.getElementById(this.imageId);
}

/**
 * returns the next index of the image to use
 */
HyperlinkImageSwapper.prototype.getNextIndex = function() 
{
		var nextIndex = this.currentIndex+1;
        if (nextIndex > (this.images.length-1)) {
          nextIndex = 0;
        }
		return nextIndex;
}

/**
 * returns the next previous of the image to use
 */
HyperlinkImageSwapper.prototype.getPreviousIndex = function() 
{
		var nextIndex = this.currentIndex-1;
        if (nextIndex < 0 ) {
          nextIndex = this.images.length-1;
        }
		return nextIndex;
}

/**
 * swaps the associated image 
 */
HyperlinkImageSwapper.prototype.forward = function() 
{
	var image = this.getImageObject();
	if (image != null) {
			this.currentIndex = this.getNextIndex();
			image.src = this.images[this.currentIndex];

	}
}

/**
 * swaps the associated image 
 */
HyperlinkImageSwapper.prototype.backward = function() 
{
	var image = this.getImageObject();
	if (image != null) {
			this.currentIndex = this.getPreviousIndex();
			image.src = this.images[this.currentIndex];

	}
}

