// How long to wait on each item (in milliseconds)
var itemWait = 8000;

// Scrolling Speed (in milliseconds)
var animSpeed = 800;

$(document).ready(function(){

	// Show itemlinks and activate first one
	$(".itemlinks li:first").addClass("active");
	$(".items li:first").addClass("active");

	// Set interval timer
	if ($(".items li").length > 1)	var slideLoop = setInterval(showNext, itemWait);
	else slideLoop = false;

	// Timeout to slide in numbers
	setTimeout("showNumbers()", 1);

	$(".itemlinks li").click(function() {

		// Clear interval timer
		clearInterval(slideLoop);

		// Show item
		if ($(".items .active").length && showItem(this)) return false;

	});

	$("#featured .items a").hover(function() {
		$(this).find("span").stop(true,true).fadeIn();
	}, function() {
		$(this).find("span").stop(true,true).fadeOut("fast");
	});

});

// Show next item function
function showNext() {

	if ($(".itemlinks .active").next().length) showItem($(".itemlinks .active").next());
	else showItem($(".itemlinks li:first").get());

}

// Slide in numbers area
function showNumbers() {

	//$(".itemlinks").animate({ left: 10}, 1500);

}

// Show specific item number
function showItem(item) {

	// Don't do anything if this tab is active
	if ($(item).hasClass("active")) return false;

	// Stop animation
	$(".items ul").stop();

	// Set active state
	$(".itemlinks li").removeClass("active");
	$(item).addClass("active");
	featureNum = $(item).prevAll().length;
	feature = $(".items li").eq(featureNum);
	feature.css("z-index", "49");

	// Animate
	$(".items .active").removeClass("active").fadeOut(animSpeed, function() {
		$(this).css("z-index", "40").show();
		feature.css("z-index", "50").addClass("active");
	});

	return true;

}