//Master JavaScript library
//M.A.Foustok
//Created: November 28, 2002
//Last modified: November28,2002

//----------------------------------------IMAGE ANIMATION------------------
var timerID = null;
var globalAnimation = new Array();
var imagesAvailable = (document["images"] != null);

//Start up the animation
function startAnimation(i)
{
	if (globalAnimation.length > 0)
	{
		timerID = window.setInterval(switchSrc,i);
	}
}

//Stop the animation
function stopAnimation()
{
	if (timerID != null)
	{
		clearInterval(timerID);
	}
}

//Perform animation update
function switchSrc()
{
	for(var i = 0;i<globalAnimation.length;i++)
	{
		id = globalAnimation[i];
		id.current++;					//Next image
		id.current %= id.count;				//keep within bounds
		id.setSrc(id.current);
	}
}

//adds an image object to the animator
function addImage(i)
{
	i.setSrc(0);						//Set initial iamge
	globalAnimation.push(i);				//add to list
}

//Constructor for animated image object
//{object},[{url}[,{url]]
function animatedImage(e)
{
	//set an new source, assuming loading has been completed
	function setSrc(n)
	{
		this.entity.src = this.sources[n].src;
	}
	
//Construct the object
	this.entity = e;				//the object
	this.count = animatedImage.arguments.length-1;	//Number of URL's
	this.sources = new Array(this.count)
	this.current = 0;				//starting image

//setup the list of images
	for (var i=0; i< this.count ;i++)
	{
		this.sources[i] = new Image();
		this.sources[i].src = animatedImage.arguments[i+1];
	}

//Object methods
	this.setSrc = setSrc;
}
//----------------------------------------END IMAGE ANIMATION------------------
