// How long to wait on each item (in milliseconds)
var itemWait = 4000;

// Scrolling Speed (in milliseconds)
var animSpeed = 800;

var $j = jQuery.noConflict();

$j(document).ready(function(){
	
	// Show itemlinks and activate first one
	$j(".itemlinks li:first").addClass("active");
	$j(".items li:first").addClass("active");
	$j(".items li:first").css("z-index", "50");
	$j("li.course-syllabus:first").addClass("active");
	$j("li.course-syllabus:first").css("z-index", "50");

	// Set interval timer
	var slideLoop = null;
	if(itemWait > 0)
		slideLoop = setInterval(showNext, itemWait);
	
	// Timeout to slide in numbers
	setTimeout("showNumbers()", 1);
	
	$j(".itemlinks li").click(function() {
		
		// Clear interval timer
		clearInterval(slideLoop);
		
		// Show item
		if ($j(".items .active").length) showItem(this);
		
	});
	
	$j(".demo").click(function() {clearInterval(slideLoop);});
		
});

// Show next item function
function showNext() {

	if ($j(".itemlinks .active").next().length) showItem($j(".itemlinks .active").next());
	else showItem($j(".itemlinks li:first").get());
	
}

// Slide in numbers area
function showNumbers() {

	$j(".itemlinks").animate({ left: "0"}, 1500);
	
}

// Show specific item number
function showItem(item) {
	
	// Don't do anything if this tab is active
	if ($j(item).hasClass("active")) return false;
	
	// Stop animation
	$j(".items ol").stop();

	// Set active state
	$j(".itemlinks li").removeClass("active");
	$j(item).addClass("active");
	courseNum = $j(item).prevAll().length;
	course = $j(".items li").eq(courseNum);
	course.css("z-index", "49");
	
	courseSyllabus = $j("li.course-syllabus").eq(courseNum);
	courseSyllabus.css("z-index", "49").show();
	
	// Animate
	$j(".items .active").removeClass("active").fadeOut(animSpeed, function() {
		$j(this).css("z-index", "40").show();
		course.css("z-index", "50").addClass("active");
	});
	
	$j("li.course-syllabus.active").removeClass("active").fadeOut(animSpeed, function() {
		$j(this).css("z-index", "40");
		courseSyllabus.css("z-index", "50").addClass("active");
	});
	
}