// Image rotation script
// Jason Norris
// jasonmnorris@gmail.com
// 11/21/2009


// We don't need thumbnails, descriptions or links so this should be pretty simple.
// Set all images to {position: absolute: top: 0; left: 0; display: none;}

// Set up the rotation
// Receives as an argument the ID of the parent element (probably a DIV) of our images and a timeout in ms
function createRotation(elementId, delay, speed)
{
	speed = speed * 2;
	delay = delay + speed;
	// Fade in the first image
	$("#gallery_image_0").fadeIn(speed);

	max = $("#" + elementId + ' > img').length - 1;

	// Set up our function to run
	setTimeout('rotateImages("' + elementId + '", ' + delay + ', ' + speed + ', 0, ' + max + ')', delay);
}

// Called periodically to rotate images to the next one
function rotateImages(elementId, delay, speed, index, max)
{
	// Fade the current image out
	$("#gallery_image_" + index).fadeOut(speed);

	var oldindex = index;

	// Go to the next image
	index = index + 1;
	if(index > max)
		index = 0;	

	//images[index].fadeOut(speied);
//	alert("Fading out image " + oldindex + " and fading in " + index);
	// Fade the next image in
	$("#gallery_image_" + index).fadeIn(speed);
	

	// Set timer
	setTimeout('rotateImages("' + elementId + '", ' + delay + ', ' + speed + ', ' + index + ', ' + max + ')', delay);
}



