// AnimatedJPG object
// Copyright (c) 2003
// Matthew Henry Apr 27, 2003
// www.foosland.com

var animatedJpegIndex = 0;
var animatedJpegs = new Array();

function AnimatedJPEG(arrayInfo)
{
	animatedJpegs[animatedJpegIndex] = new AnimatedJPEGObject(arrayInfo);
	animatedJpegIndex++;
}

function AnimatedJPEGObject(arrayInfo) 
{
	var iNumImages = arrayInfo.length/2;
	this.m_arrayImages = new Array(iNumImages);
	this.m_arrayImageTiming = new Array(iNumImages);
	var inx;
	var jnx = 0;
	for (inx = 0; inx < arrayInfo.length; inx++, jnx++)
	{
		this.m_arrayImages[jnx] = arrayInfo[inx];
		inx++;
		this.m_arrayImageTiming[jnx] = arrayInfo[inx];
	}
	this.index = animatedJpegIndex;
	this.m_iFrameNum = 0;
	this.createHTML = _createHTML;
	this.animate = _animate;
	this.imageID = "AnimatedJPEG"+animatedJpegIndex;
	this.createHTML();
	this.animate(); // get the ball rolling.

	function _createHTML() 
	{
		var item;
		var inx;
		for (inx = 0; inx < this.m_arrayImages.length; inx++)
		{
			item = this.m_arrayImages[inx];
			var strImage;
			strImage = '<img src="'+item+'" alt="'+item+'" id="'+this.imageID+inx+'" style="display:none">';
			document.write(strImage);
		}
		document.write('<img id="showimage'+this.index+'" />');
		// Create a global function for the timeout function to call.
	}        

	function _animate() 
	{
    		var elemToShow = document.getElementById(this.imageID+this.m_iFrameNum);
    		var elemPermanentShow = document.getElementById("showimage"+this.index);
    		elemPermanentShow.src = elemToShow.src;
    		setTimeout("animatedJpegs["+this.index+"].animate()", 
            this.m_arrayImageTiming[this.m_iFrameNum]);
    		this.m_iFrameNum = (this.m_iFrameNum +1) % (this.m_arrayImages.length);
    		if (this.additionalanimation) this.additionalanimation();
	}
}
