jQuery(function(){

$(".main_image .desc").show(); //Show Banner
$(".main_image .block").animate({ opacity: 0.85 }, 1 ); //Set Opacity
$(".banners ul li:first").addClass("active"); //Add the active class (highlights the very first list item by default)

var TempoBanner=3000;

//runs function on click
$(".banners ul li").click(function () {
if ($(this).is(".active")) { 
		return false; 
	} else {
clearInterval(playSlideshow);
playSlideshow = setInterval("slideSwitchTimed()", TempoBanner );
$active = $(this);
slideSwitchClick();
}
return false;
})
.hover(function(){ //Hover effects on list-item
$(this).addClass("hover"); //Add class “hover" on hover
}, function() {
$(this).removeClass("hover"); //Remove class “hover" on hover out
});

var countLi = 0;
$('.banners ul li').each(function(i) { countLi++; });
									
									

 //runs function, set timer here
$(function() {
//setInterval( ’slideSwitchTimed()’, 6000 );
if ( countLi > 1 ) playSlideshow = setInterval( "slideSwitchTimed()", TempoBanner );
});

//pauses on hover
$(".main_image").hover(function() {
clearInterval(playSlideshow);
//$(".main_image .block").slideToggle();
},
function() {
if ( countLi > 1 ) playSlideshow = setInterval( "slideSwitchTimed()", TempoBanner );
//$(".main_image .block").slideToggle();
});

});

function slideSwitchTimed() {
$active = $(".banners ul li.active").next();
if ( $active.length == 0 ) $active = $(".banners ul li:first"); //goes back to start when finishes
slideSwitch();
}

function slideSwitchClick() {
slideSwitch();
}

function slideSwitch() {
var $prev = $(".banners ul li.active");

//Show active list-item
$prev.removeClass("active");
$active.addClass("active");

//Set Variables
var imgAlt = $active.find("a").attr("title"); //Get Alt Tag of Image
var imgSrc = $active.find("a").attr("rel"); 
var imgLink = $active.find("a").attr("href"); 
var imgDesc = $active.find(".block").html(); 
var imgDescHeight = $(".main_image").find(".block").height(); 

$(".main_image #img").animate({ opacity: 0}, 250 );	
$(".main_image .block").animate({ opacity: 0, marginBottom: -imgDescHeight }, 250 , function() {
$(".main_image .block").html(imgDesc).animate({ opacity: 0.85, marginBottom: "0" }, 250 );
if(imgLink!=""){
$(".main_image #img").html("<a href=\""+imgLink+"\" title=\""+imgAlt+"\"><img src=\""+imgSrc+"\" alt=\""+imgAlt+"\" border=\"0\"></a>");
}else{
$(".main_image #img").html("<img src=\""+imgSrc+"\" alt=\""+imgAlt+"\" border=\"0\">");
}
$(".main_image #img").animate({ opacity: 1}, 250 );
});


return false;
}
