var totalBanners = 0;
var nPromoTimerIndex = -1;
var ptrPromoTimer = null;

$(document).ready(function() {	
	try {
		if ($("#promo")) {
            totalBanners = $("#promo ul img").size()
            
            $("#promo ul img").hover(function() {
                StopPromoTimer();
                nPromoTimerIndex = $("#promo ul img").index(this);
                
                $("#promo div").each(function(){
                    $(this).removeClass('hover');    
                });
                
                var sPromoSrc = this.getAttribute("alt");
                var sPromoHref = $(this).parent().attr("href");
                
                $("#promo-main").attr("src", sPromoSrc);
                $("#promo-main").parent().attr("href", sPromoHref);
                
                $(this).parent().parent().addClass('hover');
            },
            function(){
                StartPromoTimer();
            });
            
            StartPromoTimer();
            PromoTimerCallback();
		};
	}
    catch(e) {
	}
});

function StartPromoTimer() {
    StopPromoTimer();
    ptrPromoTimer = setInterval('PromoTimerCallback();', 5000);
}

function StopPromoTimer() {
    if (ptrPromoTimer) clearInterval(ptrPromoTimer);
    ptrPromoTimer = null;
}

function PromoTimerCallback()
{
    nPromoTimerIndex++;
    
    if (nPromoTimerIndex == totalBanners)
        nPromoTimerIndex = 0;

    $("#promo ul img").each(function(i) {
        if (nPromoTimerIndex == i) {
            $(this).hover();
        }
    });
}
