$(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];
        $("#bannerPrincipal .pagination a.selected").removeClass("selected");
        $("#bannerPrincipal .pagination a:nth-child("+(currIdx+1)+")").addClass("selected");
        $("#bannerPrincipal .chImage").attr("src", highlight.imageUrl);
        $("#bannerPrincipal .imgUrl").attr("href", highlight.linkArticle);
        
        $("#image-txt").html(highlight.text);
        $("#image-subtxt").html(highlight.subtext);

        $("#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(5000, "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();
    }
	
    
});
