$(function() {

    var currIdx = 0;
    var pageBanner = "";
	
    function changeImage() {
        if(currIdx >= centralHightlights.length) {
            currIdx = 0;
        }
      //  alert($('#bannerPrincipal .image').length);
        //$('#bannerPrincipal .image').remove(":object");

        var highlight = centralHightlights[currIdx];
        //alert(highlight.imageUrl);
        $("#bannerPrincipal .pagination a.selected").removeClass("selected");
        $("#bannerPrincipal .pagination a:nth-child("+(currIdx+1)+")").addClass("selected");
        if(highlight.tipo=='imagem'){
            $('#bannerPrincipal .image #BannerFlash').remove();
            $("#bannerPrincipal .image").css("background-image", "url("+highlight.imageUrl+")");
            $("#bannerPrincipal .image").css("top", "7px");
        }else{
            $('#bannerPrincipal .image #BannerFlash').remove();
            var flashFile = '<object id="BannerFlash" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="711" height="182">'+
            '<param name="movie" value="'+highlight.imageUrl+'" />'+
            '<param name="quality" value="high" />'+
            '<param name="wmode" value="transparent" />'+
            '<param name="swfversion" value="6.0.65.0" />'+
            '<param name="expressinstall" value="../../Scripts/expressInstall.swf" />'+
            '<!--[if !IE]>-->'+
            '<object type="application/x-shockwave-flash" data="'+highlight.imageUrl+'" width="711" height="182">'+
            '<!--<![endif]-->'+
            '<param name="quality" value="high" />'+
            '<param name="wmode" value="transparent" />'+
            '<param name="swfversion" value="6.0.65.0" />'+
            '<param name="expressinstall" value="../../Scripts/expressInstall.swf" />'+
            '<!--[if !IE]>-->'+
            '  </object>'+
            '  <!--<![endif]-->'+
            '</object>';
            $('#bannerPrincipal .image').prepend(flashFile);
            $("#bannerPrincipal .image").css("background-image", "none");
            $("#bannerPrincipal .image").css("top", "7px");
            //$("#bannerPrincipal .image").css("left", "7px");
        }
        $("#bannerPrincipal .clickablearea").css("cursor", "pointer");
        $("#bannerPrincipal .clickablearea").attr("location.href",highlight.linkUrl);
        $('#bannerPrincipal .clickablearea').click(function () {
            window.location=$(this).attr("location.href");
            return false;
        });
    }
	
    function stopTimer() {
        $("#bannerPrincipal").stopTime();
    }
	
    function startTimer() {
        $("#bannerPrincipal").everyTime(19500, "changeImage", function() {
            ++currIdx;
           // $('#bannerPrincipal .image #BannerFlash').remove();
            changeImage();
        });
    }
	
    changeImage();

    if(centralHightlights.length > 0) {
        $("#bannerPrincipal .pagination a").click(function(event) {
            stopTimer();

            var href = this.href;
            currIdx = parseInt(href.substring(href.lastIndexOf("#")+1));
           // $('#bannerPrincipal .image #BannerFlash').remove();
            changeImage();
            startTimer();

            event.preventDefault();
        });
        startTimer();
    }
	
    
});
