var rotator =
{
	top:0, left:0,
	startingOpacity:1,														// starting opacity of the images
	fadeSpeed:3,															// speed of transition in seconds
	rotationSpeed:10000,													// speed of rotation in milliseconds
	// id array of the html img tags
	imageIds:["rotator1","rotator2","rotator3"],
	// array of image sources								
	images:["Images/Rotators/rot1.jpg","Images/Rotators/rot2.jpg","Images/Rotators/rot3.jpg"],
	imageArray:Array(),														// array of images
	timer:null,																// return value of setInterval()
	currentImageIndex:0,													// this is the index of the current image displayed
	nextImageIndex:1,														// this is the index of the next image to display

	preloadImages:function()
	{
		// determine how many images we have
		var imageCount = rotator.images.length;
		
		// preload images
		for(var x = 0; x < imageCount; x++)
		{
			rotator.imageArray[x] = new Image();
			rotator.imageArray[x].src = rotator.images[x];
		}
	},
	
	startRotation:function()
	{
		// start the rotation
		rotator.timer = setInterval("rotator.displayNext()", rotator.rotationSpeed);
	},

	setImageProperties:function()
	{
		for(var x=0; x < rotator.imageIds.length;x++) 
		{
			// set some global styles for each image
			var id = document.getElementById(rotator.imageIds[x]);
			YAHOO.util.Dom.setStyle(id, 'opacity', 0);
			YAHOO.util.Dom.setStyle(id, 'position', 'absolute');
			YAHOO.util.Dom.setStyle(id, 'top', rotator.top + 'px');
			YAHOO.util.Dom.setStyle(id, 'left', rotator.left + 'px');
			// make the first image id have a higer z-index and 100% opaque so it displays
			if(x == 0)
			{
				YAHOO.util.Dom.setStyle(id, 'z-index', 99);
				YAHOO.util.Dom.setStyle(id, 'opacity', 1);
			}
		}
	},
	
	displayNext:function()
	{
		// fade out the current image
		var fadeOutAnim = new YAHOO.util.Anim(rotator.imageIds[rotator.currentImageIndex],{opacity:{from: 1, to: 0}},rotator.fadeSpeed);
		fadeOutAnim.animate();

		// fade in the next image
		var fadeInAnim = new YAHOO.util.Anim(rotator.imageIds[rotator.nextImageIndex],{opacity:{from: 0, to: 1}},rotator.fadeSpeed);
		fadeInAnim.animate();
		
		// update the current image index
		rotator.currentImageIndex = rotator.nextImageIndex;
		
		// restart at the beginning if we have reached the end of the array or increment the next image index
		if(rotator.currentImageIndex >= rotator.images.length - 1)
		{
			rotator.nextImageIndex = 0;
		}
		else
		{
			rotator.nextImageIndex++;
		}
	}
}
