///////////////////////////////////////////////////////////////////////////
// Rotator.js
//
// Description:
//     This provides the source for a rotator class object.
//
// Copyright 1999 BengalCore (http://www.bengalcore.com)
// Contact: Tom Holt (tmholt@bengalcore.com)
// Disclaimer:
//      You are welcome to use and modify this source as desired, as long
//      as this banner stays in place. Thanks, and enjoy.
///////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////
// get what browser we're using
var ie4 = (document.all) ? true : false;
var ns4 = (document.layers) ? true : false;

var gCurRotator;

///////////////////////////////////////////////////////////////////////
// constructor for rotator object
///////////////////////////////////////////////////////////////////////
function CRotator(whichImage, 	// which image on the page this is (indexed)
				  baseName, 	// base name of image - the idea is that 
				  				// all the images are named the same thing 
				  				// with an index at the end. For example, 
				  				// img1.jpg, img2.jpg, etc.
				  imageCount,	// number of images to cycle through
				  bUseRandom,   // cycle vs random images
				  bUseTrans)	// use transitions when switching
{
	// the first time this is called, document will be false. Ignore this call.
	if ( document == null ) return;

	// only for 4+ browsers
	if ( !(ie4 || ns4 ) ) return;

	// ****NOTE****************************************************************
	// variables - this is where you change the base directory for the images to 
	// rotate through, as well as the frequency of the rotation.
	this.m_baseName 	 = 'images/' + baseName;
	this.m_whichImage 	 = whichImage;
	this.m_imageCount 	 = imageCount;
	this.m_curImageCount = 1;
	this.m_hImage 		 = document.images[whichImage];
	this.m_bUseRandom    = bUseRandom;
	this.m_bUseTrans     = bUseTrans;
	this.m_nTransNumber  = 1;
	this.m_frequency     = 3000; // milliseconds
	this.m_extension     = ".jpg"; // generally .jpg or .gif
	// END variables section - you should not have to change anything below here.
	// ****NOTE****************************************************************	

	gCurRotator = this;

	// preload the images - note 1-based
	var i;
	var imageName;
	var image;
	for ( i = 1; i <= imageCount; i++ ) {
		 imageName =  this.m_baseName + i + this.m_extension;
		 window.status = 'Preloading image: ' + imageName;
		 image = new Image(10,10); // don't care about width/height
		 image.src = imageName;
	}
	

	// start timer
	setTimeout("NextImage()", this.m_frequency);
}

///////////////////////////////////////////////////////////////////////
// get a random number between 0 and max-1
///////////////////////////////////////////////////////////////////////
function getRandom(max) {
	return (parseInt(Math.random()*max));
}

///////////////////////////////////////////////////////////////////////
// swap out the rotator with the next image
///////////////////////////////////////////////////////////////////////
function NextImage()
{
	if ( gCurRotator.m_bUseRandom ) {
		gCurRotator.m_curImageCount = getRandom(gCurRotator.m_imageCount) + 1;
	}
	else {
		gCurRotator.m_curImageCount++;
		if ( gCurRotator.m_curImageCount > gCurRotator.m_imageCount ) {
			gCurRotator.m_curImageCount = 1;
		}
	}
	
	if ( gCurRotator.m_bUseTrans ) {
		if ( ie4 ) {
			var rotDiv = document.all("ROTATORDIV");
			rotDiv.filters[0].transition = gCurRotator.m_nTransNumber;
			rotDiv.filters[0].apply();
			rotDiv.filters[0].play(.5);

			// only do this if you want the style of the rotation to change
			gCurRotator.m_nTransNumber = (gCurRotator.m_nTransNumber + 1) % 24;		
		}
	}

	gCurRotator.m_hImage.src = gCurRotator.m_baseName + gCurRotator.m_curImageCount + gCurRotator.m_extension;
		
	setTimeout("NextImage()", gCurRotator.m_frequency);
}
