/**
 * Slide show navigation with automatic rotation.
 *
 * Requires jQuery 1.4+
 *
 * @author Vladimir Dzhuvinov
 * @version 2010-07-27
 */

var rotateDelay = 10000;
var rotateEnable = true;


function showSlide(slide) {

	if (typeof slide !== "object")
		return;
		
	// Slide already selected?
	if ($(slide).hasClass("active"))
		return;

	// Hide others
	$("ul#index-slide-show-nav li").removeClass("active");
	$(".index-slide").hide();

	// Show selected
	$(slide).addClass("active");
	var activeTab = $(slide).find("a").attr("rel");
	$(activeTab).fadeIn();
}


function showNextSlide() {

	var next = $("ul#index-slide-show-nav li.active + li");
	
	// Rewind
	if (next.length === 0)
		next = $("ul#index-slide-show-nav li:first-child");

	if (next.length > 0)
		showSlide(next[0]);
}


function rotate() {

	if (! rotateEnable)
		return;

	showNextSlide();
	window.setTimeout(rotate, rotateDelay);
}


$(document).ready(function() {

	$("ul#index-slide-show-nav li").mouseenter(function() {

		// Stop rotation
		rotateEnable = false;

		showSlide(this);
		
		return false;
	});
	
	if (rotateEnable)
		window.setTimeout(rotate, rotateDelay);

});

