

jQuery.noConflict();

jQuery(function () {



    /**** MENU ****/
    jQuery('a.linkMenu').mouseover(function () {

        jQuery(this).parent().parent().parent().find("div").prev().removeClass("menu");
        jQuery(this).parent().parent().parent().find("div").prev().addClass("menu_on");

        jQuery(this).parent().parent().parent().find("div").prev().prev().removeClass("menuEsq");
        jQuery(this).parent().parent().parent().find("div").prev().prev().addClass("menuEsq_on");


        jQuery(this).parent().parent().parent().find("div").next().next().removeClass("menuDt");
        jQuery(this).parent().parent().parent().find("div").next().next().addClass("menuDt_on");
    });

    jQuery('a.linkMenu').mouseout(function () {


        jQuery(this).parent().parent().parent().find("div").prev().removeClass("menu_on");
        jQuery(this).parent().parent().parent().find("div").prev().addClass("menu");

        jQuery(this).parent().parent().parent().find("div").prev().prev().removeClass("menuEsq_on");
        jQuery(this).parent().parent().parent().find("div").prev().prev().addClass("menuEsq");


        jQuery(this).parent().parent().parent().find("div").next().next().removeClass("menuDt_on");
        jQuery(this).parent().parent().parent().find("div").next().next().addClass("menuDt");
    });
    /**** FIM MENU ****/




    /***** CONTROLADOR NUMÉRICO ******/
    jQuery('#BannerFotos div').each(function (index) {
        var contador = jQuery('#BannerFotos div').index(this) + 1;

        if (jQuery('#BannerFotos div').index(this) == 0)
            jQuery('<li class="activo"></li>').appendTo('#controlador');
        else {
            jQuery('<li></li>').appendTo('#controlador');
        }
    });


    var posicaoControlador = 853 / 2 - jQuery('#controlador li').length * 10 / 2;
    jQuery('#controlador').css('left', posicaoControlador + 'px');

    var nValores = jQuery('#BannerFotos div');
    jQuery('#controlador li').click(function (index) {

        var cell = jQuery('div[class^="show"]')
        var indexActivo = cell.parent("div").children().index(cell);
        if (indexActivo != jQuery('#controlador li').index(this)) {
            //alert(jQuery('#controlador li').index(this) + 1);
            window.clearInterval(intval);
            //var current = (jQuery('#BannerFotos div.show') ? jQuery('#BannerFotos div.show') : jQuery('#BannerFotos div:first'));
            //if ( current.length == 0 ) current = jQuery('#BannerFotos div:first');
            var current = jQuery('#BannerFotos div.show');
            var next = jQuery(nValores[jQuery('#controlador li').index(this)]);
            efeitos(next, current);
        }
    });
    /***** FIM CONTROLADOR NUMÉRICO ******/


    /***** CONTROLADOR NUMÉRICO ******/
    jQuery('#setaAnterior img').click(function () {
        rotate('anterior');
        //alert('kjl');
        window.clearInterval(intval);
        intval = window.setInterval('rotate("anterior")', 6000)
    });

    jQuery('#setaSeguinte img').click(function () {
        rotate('seguinte');
        window.clearInterval(intval);
        intval = window.setInterval('rotate("seguinte")', 6000)

    });
    /***** CONTROLADOR SETAS ******/

    //Inicia o banner
    jQuery('#BannerFotos').css('display', 'block');
    theRotator();

});


function theRotator() {
    //jQuery('div.rotator').fadeIn(1000);
    //jQuery('div.rotator ul li').fadeIn(1000); // tweek for IE

    //Set the opacity of all images to 0
    jQuery('#BannerFotos div').css({ opacity: 0.0 });
    //Get the first image and display it (gets set to full opacity)
    jQuery('#BannerFotos div:first').css({ opacity: 1.0 });
    //Call the rotator function to run the slideshow, 6000 = change to next image after 6 seconds
    intval = window.setInterval('rotate("seguinte")', 6000)
}


function rotate(posicao) {

    if (posicao == 'seguinte') {


        //alert(('#BannerFotos div:first').siblings().length);
        //alert(jQuery('#BannerFotos div').next().length);	
        //alert('click seguinte');
        //Get the first image
        var current = (jQuery('#BannerFotos div.show') ? jQuery('#BannerFotos div.show') : jQuery('#BannerFotos div:first'));
        if (current.length == 0) current = jQuery('#BannerFotos div:first');
        //Get next image, when it reaches the end, rotate it back to the first image
        var next = ((current.next().length) ? ((current.next().hasClass('show')) ? jQuery('#BannerFotos div:first') : current.next()) : jQuery('#BannerFotos div:first'));
    }
    else if (posicao == 'anterior') {
        //alert('click anterior');
        //Get the first image
        var current = (jQuery('#BannerFotos div.show') ? jQuery('#BannerFotos div.show') : jQuery('#BannerFotos div:last'));
        //Se estiver na ultima foto
        if (current.length == jQuery('#BannerFotos div').next().length)
            current = jQuery('#BannerFotos div:first');
        //Get next image, when it reaches the end, rotate it back to the first image
        var next = ((current.prev().length) ? ((current.prev().hasClass('show')) ? jQuery('#BannerFotos div:last') : current.prev()) : jQuery('#BannerFotos div:last'));
    }

    efeitos(next, current);
};



function efeitos(next, current) {
    //Un-comment the 3 lines below to get the images in random order	
    //var sibs = current.siblings();
    //var rndNum = Math.floor(Math.random() * sibs.length );
    //var next = jQuery( sibs[ rndNum ] );

    //Set the fade in effect for the next image, the show class has higher z-index
    next.css({ opacity: 0.0 })
	.addClass('show').css("z-index", "2")
	.animate({ opacity: 1.0 }, 1000);

    //next.find("a").css("z-index", "1000");

    //Hide the current image
    current.animate({ opacity: 0.0 }, 1000)
	.removeClass('show').css("z-index", "1");

   // current.find("a").css("z-index", "80");
	

    var cell = jQuery('div[class^="show"]')
    var indexActivo = cell.parent("div").children().index(cell);
    var arrayBotoes = jQuery('#controlador li');
    jQuery('#controlador li').removeClass('activo');
    jQuery(arrayBotoes[indexActivo]).addClass('activo');
}




function addToFavorite() {
    /*
    if ((navigator.appVersion.indexOf("MSIE") > 0) && (parseInt(navigator.appVersion) >= 4)) {
    window.external.AddFavorite(location.href, unescape(document.title));
    }
    */

    if (window.sidebar) {
        // Mozilla Firefox Bookmark		
        window.sidebar.addPanel(document.title, location.href, "");
    }
    else if (window.external) {
        // IE Favorite		
        window.external.AddFavorite(location.href, document.title);
    }
    else if (window.opera && window.print) {
        // Opera Hotlist
        return true;
    }

}
