//BEGIN class RotatingImage
//Maintains data and methods for creating an <img> tag that automatically rotates sources.
function RotatingImage(selfId, speed)
{
	this.images = new Array;
	this.captions = new Array;
	this.nextImage = 0;
	this.previousImage = 0;
	this.numImages = 0;
	this.selfId = selfId;		//The identifier name of THIS instance
	this.imageId = this.selfId + "Image";
	this.captionId = this.selfId + "Caption";
	this.speed = speed;
	this.lastTimeout = null;
	this.imageTemp = new Array;
	this.numThumbsPerRow = 4;
	this.urls = new Array;
	this.numUrls = 0;
		
	this.AddImage = AddImage;	
	this.RotateImage = RotateImage;
	this.NextImage = NextImage;
	this.GotoImage = GotoImage;
	this.PreviousImage = PreviousImage;
	this.WriteImage = WriteImage;
	this.WriteThumbs = WriteThumbs;
}
	
//Adds an image to our list of images to rotate
function AddImage(fileName, caption, url)
{
	//Preload it!
	this.imageTemp[this.numImages] = new Image();
	this.imageTemp[this.numImages].src = fileName;
	
	this.urls[this.numUrls] = url;
	this.numUrls++;
	
	this.images[this.numImages] = fileName;
	this.captions[this.numImages] = '<a href="' + url + '">' + caption + '</a>';
	this.numImages++;
}
	
//Begins rotating the image
function RotateImage()
{
	this.NextImage();
		
	if(this.speed != 0)
		timeoutSpeed = this.speed;
	else
		timeoutSpeed = Math.floor(Math.random()*8001 + 3000);

	this.lastTimeout = setTimeout(this.selfId + ".RotateImage()", timeoutSpeed);
}

function NextImage()
{
	document.getElementById(this.imageId).innerHTML = '<a class="logo" href="' + this.urls[this.nextImage] + '"><img src="' + this.images[this.nextImage] + '" /></a>';
	document.getElementById(this.captionId).innerHTML = this.captions[this.nextImage];

	//Set the previous image to the image before the current one.
	this.previousImage = this.nextImage - 1;
	if(this.previousImage < 0)
		this.previousImage = this.numImages - 1;

	//Set the next image to the image after the current one.
	this.nextImage++;
	if(this.nextImage == this.numImages)
		this.nextImage = 0;		
			
	//GHETTO fix for Mozilla, since a div onResize event doesn't seem to exist.
	//setTimeout('RepositionAllContent()', 0);
}

function PreviousImage()
{
	document.getElementById(this.imageId).innerHTML = '<a class="logo" href="' + this.urls[this.previousImage] + '"><img src="' + this.images[this.previousImage] + '" /></a>';
	document.getElementById(this.captionId).innerHTML = this.captions[this.previousImage];
	
	//Set the next image to the image after the current one.
	this.nextImage = this.previousImage + 1;	
	if(this.nextImage == this.numImages)
		this.nextImage = 0;	
	
	//Set the previous iamge to the image before the current one.
	this.previousImage--;
	if(this.previousImage < 0)
		this.previousImage = this.numImages - 1;
	
	//GHETTO fix for Mozilla, since a div onResize event doesn't seem to exist.
	//setTimeout('RepositionAllContent()', 0);

	//WTH is this shit? Delete it????
	/*
	if(this.previousImage == this.numImages)
		this.nextImage = 0;			
	*/
}

function GotoImage(index)
{
	document.getElementById(this.imageId).innerHTML = '<img src="' + this.images[index] + '" />';
	document.getElementById(this.captionId).innerHTML = this.captions[index];
	
	//Set the next image to the image after the current one.
	this.nextImage = index + 1;	
	if(this.nextImage == this.numImages)
		this.nextImage = 0;	
	
	//Set the previous iamge to the image before the current one.
	this.previousImage = index - 1;
	if(this.previousImage < 0)
		this.previousImage = this.numImages - 1;
}

function WriteImage()
{
	document.write('<table class="rotating_image"><tr><td id="' + this.imageId + '" class="rotating_image"><a class="logo" href="' + this.urls[0] + '"><img src="' + this.images[0] + '" /></a></td></tr></table><div id="' + this.captionId + '" ');
	if(this.captions[0] != "")
		document.write('class="rotating_image_caption"');
	document.write('>' + this.captions[0] + '</div>');
}

function WriteThumbs()
{
	if(this.numImages > 1)
	{
		document.write('<table>');
		document.write('<tr>');
		for(i=0; i<this.numImages; i++)
		{			
			document.write('<td onmouseover="this.style.cursor=' + "'pointer'" + '; ' + this.selfId + '.GotoImage(' + i + ')">');
			document.write('<img height="75px" src="' + this.images[i] + '" />');
			document.write('</td>');
			if((i+1)%this.numThumbsPerRow == 0)
				document.write('</tr><tr>');
		}
		if(i%this.numThumbsPerRow != 0)
			document.write('</tr>');
		document.write('</table>');
	}
}
//END class RotatingImage