// Height of the elements in the scroll showcase (in pixels)
var itemHeight = 420;

// How long to wait on each item (in milliseconds)
var itemWait = 4000;

// 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");
	$(".itemlinks").fadeIn(500);
	
	// Set interval timer
	var slideLoop = setInterval(showNext, itemWait);
	
	$(".itemlinks li").click(function() {
		
		// Clear interval timer
		clearInterval(slideLoop);
		
		// Show item
		if ($(".items .active").length) showItem(this);
		
	});
		
});

// Show next item function
function showNext() {

	if ($(".itemlinks .active").next().length) showItem($(".itemlinks .active").next());
	else showItem($(".itemlinks li:first").get());
	
}

// 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");
	});
	
}
