/* Image Preview Switcher
 * 
 * Author: Aaron M. Bond
 *
 * (Based on example here: http://jonraasch.com/blog/a-simple-jquery-slideshow)
 */

var initKickoff = false;

$(document).ready(function() {
	/* Don't know why I have to do this
	 * goofiness, but WebKit browsers won't
	 * initially work on setInterval alone.  
	 * This ensures a true kickoff.
	 */
	setTimeout(previewShift, 5000);	
});

function previewShift()
{
	var currentActive = $('#slidePreview IMG.showingImage');
	var nextImage = currentActive.next();
	if (currentActive.size() == 0) {
		currentActive = $('#slidePreview').children().last();
	}
	if (nextImage.size() == 0) {
		nextImage = $('#slidePreview').children().first();
	}
	nextImage.addClass('nextImage');
	nextImage.css({opacity: 1.0});
	currentActive.animate({opacity: 0.0}, 1000, function() {
		currentActive.removeClass('showingImage');
		nextImage.addClass('showingImage');
		nextImage.removeClass('nextImage');
	});
	/* See comment in $().ready function... */
	if (!initKickoff) {
		setInterval(previewShift, 5000);	
		initKickoff = true;
	}
}

