$(document).ready(function(){
	$("#controls li a").click(function(){
            //Performed when a control is clicked
	    shuffle(); $(".banner").hide();
	    var rel = $(this).attr("rel");
	    if ( $("#" + rel).hasClass("current") ){
	        return false;
	    }
	    $("#" + rel).show();
	    $(".current").fadeOut().removeClass("current");
	    $("#" + rel).addClass("current");
	    $(".active").removeClass("active");
	    $(this).parents("li").addClass("active");
	    set_new_interval(7000);
	    return false;
	});
	
	//$(".banner").css("z-index", 1).hide();
	$(".banner").css("display","none");
	banner_switch();
	
});
function banner_switch(){
	//This function is called on to switch the banners out when the time limit is reached
	shuffle(); $(".banner").hide();
	var next =  $('.banner.current').next('.banner').length ? $('.banner.current').next('.banner') : $('#JQbanners .banner:first');
	$(next).show();
	$(".current").fadeOut().removeClass("current");
	$(next).addClass("current");
	var next_link = $(".active").next("li").length ? $('.active').next('li') : $('#controls li:first');
	$(".active").removeClass("active");
	$(next_link).addClass('active');
}

$(function() {
	//Initial timer setting
	slide = setInterval( "banner_switch()", 7000 );
});

function set_new_interval(interval){
	//Simply clears out the old timer interval and restarts it
	clearInterval(slide);
	slide = setInterval("banner_switch()", interval);
}

function shuffle(){
	//This function takes every .banner and changes the z-index to 1, hides them,
	//    then takes the ".current" banner and brings it above and shows it
	$(".banner").css("z-index", 1).hide();
	$(".banner").hide();
	$(".current").css("z-index", 2).show();
	
}

