

$(document).ready(function()
{
    $(document).everyTime(8000, 'homePromoTimer', autoplayNextPromo, 0);
    setControlStyle(1);

    for(var i = 1; i <= totalPromos; i ++)
    {
	    PromoDetails[i] = $("#PromoDetails"+i);
	    $("#Promo"+i).mouseenter(function(){ ShowSummary(); }).mouseleave(function(){ HideSummary(); });
    }
});

var currentPromo = 1;
var PromoDetails = new Array();

var autoplayNextPromo = function()
{
    var nextPromo = ((currentPromo + 1) > totalPromos ? 1 : (currentPromo + 1) );
    fadePromo(nextPromo);    
}

//autoplayNextPromo.periodical(8000);

function ShowSummary(eventObject)
{
    $(document).stopTime('homePromoTimer', autoplayNextPromo);
    var el = PromoDetails[currentPromo];
    el.animate({bottom:"0px"},100);
}

function HideSummary()
{
    $(document).everyTime(8000, 'homePromoTimer', autoplayNextPromo, 0);
    var el = PromoDetails[currentPromo];
    el.animate({bottom:"-150px"},100);
}

function fadePromo(newPromo)
{
    setControlStyle(newPromo);  
    HideSummary();
    
    var el = $("#Promo"+currentPromo);
    el.css({zIndex:"10"});

    var el2 = $("#Promo"+newPromo);
    el.css({zIndex:"0"});
    
    el.animate({opacity:"0"});
    el2.animate({opacity:"1"});
    /*
    // fade out current promo
    var el = $('Promo'+currentPromo);
    el.setStyle('z-index', '1');

    // fade in new promo   
    var el2 = $('Promo'+newPromo);
    el2.setStyle('opacity', '0');
    el2.setStyle('z-index', '8');

    el.fade(0);
    el2.fade(1); 
      */  
    // set current promo to new promo
    currentPromo = newPromo;
}

function setControlStyle(newPromo)
{
    document.getElementById('PromoLink'+currentPromo).className='';
    document.getElementById('PromoLink'+newPromo).className='current';
}
