jQuery(function(){

$(".main_image .desc").show();
$(".main_image .block").animate({ opacity: 0.85 }, 1 );
$(".banners ul li:first").addClass("active");

var TempoBanner=4500;
var playSlideshow;

$(".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(){
$(this).addClass("hover");
}, function() {
$(this).removeClass("hover");
});

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

$(function() {
if ( countLi > 1 ) playSlideshow = setInterval( "slideSwitchTimed()", TempoBanner );
});

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

});

function slideSwitchTimed() {
$active = $(".banners ul li.active").next();
if ( $active.length == 0 ) $active = $(".banners ul li:first");
slideSwitch();
}

function slideSwitchClick() {
slideSwitch();
}

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

$prev.removeClass("active");
$active.addClass("active");

var imgAlt = $active.find("a").attr("title");
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;}
