thisImg=1;
function rotate(){
	if (document.getElementById) {
		var theElement1 = document.getElementById('image1Wrapper');
		var theImage1 = document.getElementById('image1');
		var theElement2 = document.getElementById('image2Wrapper');		
		var theImage2 = document.getElementById('image2');		

		if (theElement1 && theElement2) {
			// make sure the next image has been preloaded before proceeding (or if it's the first one, just proceed)
			if ((!rotatingImageArray[thisImg].complete && thisImg != 0) || rotatingImageArray[thisImg].src == blankImage.src) {
				// it's not ready, so set up to check again in a second, and jump out
				setTimeout("rotate()", 1000);
				return;
			}

			// figure out which one is in the back
			if (theElement1.style.zIndex > theElement2.style.zIndex) {
				// get it ready for the drop
				positionElementForDrop(theElement2, theElement1, theImage2);		

				// and now drop it down
				var positionChange = new Fx.Styles("image2Wrapper", {duration: 1500, transition: Fx.Transitions.bounceOut, onComplete: setupForNextRotation } );
				positionChange.start({
					'top': [theElement2.offsetTop, 0] 
				});
			}
			else {
				// get it ready for the drop				
				positionElementForDrop(theElement1, theElement2, theImage1);

				// and now drop it down
				var positionChange = new Fx.Styles("image1Wrapper", {duration: 1500, transition: Fx.Transitions.bounceOut, onComplete: setupForNextRotation } );
				positionChange.start({
					'top': [theElement1.offsetTop, 0] 
				});	

			}
		}
	}
}

function setupForNextRotation() {
	// setup for the next iteration
	thisImg++;
	// reset the index if we're past our array length
	if (thisImg >= rotatingImageArray.length) {
		thisImg = 0;
	}
	setTimeout("rotate()", 6*1000);
}

function positionElementForDrop(backElement, foreElement, imageToChange) {
	// move the element up high
	backElement.style.top = "-500px";
	// swap the z-indexes, so that it's now on top
	backElement.style.zIndex = 2;
	// and the previous "fore" is now in the back
	foreElement.style.zIndex = 1;
	// and swap in the new image
	imageToChange.src = rotatingImageArray[thisImg].src;
	imageToChange.alt = rotatingImageData[thisImg]['title'];
	imageToChange.title = rotatingImageData[thisImg]['title'];
}
