/* 
GDRotator: by randy bacon 05/23/2006 rotates images on a page
*/

//keep track OH your class here by image id
var g_GDROjbects;

function GDRAddObj(itemId, oitemId)
{
	if (typeof(g_GDROjbects) == "undefined")
		g_GDROjbects = new Array();
			
	g_GDROjbects[itemId] = oitemId;
}

function GDRGetObj(itemId)
{
	return g_GDROjbects[itemId];
}

//class wrapper for the image rotator
function GDRotator(imgElementId, timeBNImage, imgPath)
{
	//class members
	this.imgElementId = imgElementId;
	this.timeBNImage = timeBNImage;
	this.imgPath = imgPath;
	this.imgElement;
	this.imagesToRotate;
	this.currentImg = 0;
	this.totalImgs = 0;
	this.rotateTimer;
	
	this.AddImagesToRotate = function()
	{		
		this.imgElement = document.getElementById(this.imgElementId);
		if( !this.imgElement )
		{
			alert("The image you have selected could not be found.  Please verify the ID you are trying to rotate.");
			return;
		}
		//add this object to our global list
		GDRAddObj(this.imgElementId, this);
		//get the image args
		this.imagesToRotate = new Array();
		for(var i=0; arguments[i]; i++)
		{
			this.imagesToRotate[i] = new Image();
			this.imagesToRotate[i].src=this.imgPath + arguments[i];
			this.totalImgs++;
		}	
	}	
	
	this.RotateImages = function()
	{
		//start timer to rotate the images
		var sFunc="GDRGetObj('" + this.imgElementId + "').RotateMyImage()";
		setTimeout(sFunc, this.timeBNImage)
	}
	
	this.RotateMyImage = function()
	{
		//set to new source
		this.currentImg++;
		if( this.currentImg >= this.totalImgs )
			this.currentImg = 0;

		//set image source to new image
		var tempItem =  eval('document.' + this.imgElementId);
		tempItem.src = this.imagesToRotate[this.currentImg].src;
		
		//rotate it again
		var sFunc="GDRGetObj('" + this.imgElementId + "').RotateMyImage()";
		setTimeout(sFunc, this.timeBNImage)
	}
}