$(function () {
    $('.menu').click(function (e) {
        e.stopPropagation();
        var href = $(this).find('a').attr("href");
        if (href) {
            window.location = href;
        }
    });
    $('.menu').mouseenter(function (index) {
        $(this).removeClass("menuBG").addClass("menuBG_on");
        $(this).find('a').css("color", "#a0a0a0");

        /*if ($(".menu").index(this) == 0) {
        $(".menu_curva").removeClass().addClass("menu_curva_on");
        }*/

    }).mouseleave(function () {
        $(this).removeClass("menuBG_on").addClass("menuBG");
        $(this).find('a').css("color", "#555555");

        /*if ($(".menu").index(this) == 0) {
        $(".menu_curva_on").removeClass().addClass("menu_curva");
        }*/
    });

    /** BANNER HOME **/
    $("#desSlideshow2").desSlideshow({
        autoplay: 'enable', //option:enable,disable
        slideshow_width: '960', //slideshow window width
        slideshow_height: '312', //slideshow window height
        thumbnail_width: '266', //thumbnail width
        time_Interval: '4000', //Milliseconds
        directory: 'img/'// flash-on.gif and flashtext-bg.jpg directory
    });

    $("#desSlideshow2_fr").desSlideshow({
        autoplay: 'enable', //option:enable,disable
        slideshow_width: '960', //slideshow window width
        slideshow_height: '312', //slideshow window height
        thumbnail_width: '266', //thumbnail width
        time_Interval: '4000', //Milliseconds
        directory: 'img_fr/'// flash-on.gif and flashtext-bg.jpg directory
    });

    $("#desSlideshow2_en").desSlideshow({
        autoplay: 'enable', //option:enable,disable
        slideshow_width: '960', //slideshow window width
        slideshow_height: '312', //slideshow window height
        thumbnail_width: '266', //thumbnail width
        time_Interval: '4000', //Milliseconds
        directory: 'img_en/'// flash-on.gif and flashtext-bg.jpg directory
    });

    $("#desSlideshow2_es").desSlideshow({
        autoplay: 'enable', //option:enable,disable
        slideshow_width: '960', //slideshow window width
        slideshow_height: '312', //slideshow window height
        thumbnail_width: '266', //thumbnail width
        time_Interval: '4000', //Milliseconds
        directory: 'img_es/'// flash-on.gif and flashtext-bg.jpg directory
    });
    /** FIM BANNER HOME **/

    /** REFERÊNCIAS **/
    $(".referenciaPequena").click(function (index) {
        var imagemGrande = "img/" + $(this).find("img").attr("id") + "_grd.jpg";
        $("#imagemGrande").attr("src", imagemGrande);
        return false;
    });
    /** FIM REFERÊNCIAS **/


    /** GALERIAS **/
    $(".thumb").click(function (index) {
        var lengthCaminho = $(this).find("img").attr("src").lastIndexOf("/");
        var caminhoImagem = $(this).find("img").attr("src").substring(0, lengthCaminho)
        //alert(lengthCaminho);
        //alert(caminhoImagem);
        var imagemGrande = caminhoImagem + "/" + $(this).find("img").attr("id") + "_grd.jpg";
        $("#galeriaGrande").attr("src", imagemGrande);
        return false;
    });
    /** FIM GALERIAS **/

    /** MAPAS CONTACTOS **/
    $("[id^=tab]").click(function (index) {
        //var actual = $("[id^=tab]").index(this) + 1;
        var actual = $(this).attr("id").substring(3);

        $("[id^=tab]").not($(this)).each(function () {

            //var restantes = $("[id^=tab]").index(this) + 1;
            var restantes = $(this).attr("id").substring(3);
            
            
            $(this).css({ 'background': 'url(img/tab' + restantes + '_bg.gif)' });

            $("[id=mapa" + restantes + "]").css("display", "none");
        });

        $(this).css({ 'background': 'url(img/tab' + actual + '_bg_sel.gif)' });

        $("[id=mapa" + actual + "]").css("display", "block");
    });
    /** FIM MAPAS CONTACTOS **/


    /** MENU PRODUTOS **/

    $("#firstpane div.menu_head").click(function (index) {
        /*$(this).next().next("div.menu_body").slideToggle(300).siblings("div.menu_body").slideUp('fast');*/

        /**** MOSTRA/ESCONDE ****/
        $("#firstpane div.menu_head").not($(this)).next().next().hide();
        $(this).next().next().toggle();

        /**** SETA ****/
        $("#firstpane div.menu_head").not($(this)).next().removeClass('bg_on');
        $(this).next().toggleClass('bg_on');

        /**** BOLD ****/
        $("#firstpane div.menu_head").not($(this)).removeClass('bold');
        $(this).toggleClass('bold');

    });



    /** FIM MENU PRODUTOS **/


    /** FOTOS MODULACOES **/
    var larguratotal = $('#modulacoesFotos div img').width() * $('#modulacoesFotos div img').length;
    $('#modulacoesFotos').width(larguratotal);

    $('#proximaModulacao').click(function () {
        //alert("proximaModulacao");
        var largura = $('#modulacoesFotos div img:first').width();
        $('#modulacoesFotos').width(larguratotal);

        if (!$('#modulacoesFotos').is(':animated')) {





            var legenda = $('#modulacoesFotos div:first').next().find('img').attr("alt");
            $('#legenda').text(legenda);

            $('#modulacoesFotos').animate({ 'margin-left': '-=' + largura }, 500, function () {
                $('#modulacoesFotos div:first').appendTo($('#modulacoesFotos'));
                $('#modulacoesFotos').css('margin-left', '0');
            });
        }
    });


    $('#anteriorModulacao').click(function () {
        //alert("proximaModulacao");
        var largura = $('#modulacoesFotos div img:first').width();
        $('#modulacoesFotos').width(larguratotal);

        if (!$('#modulacoesFotos').is(':animated')) {

            $('#modulacoesFotos div:last').prependTo($('#modulacoesFotos'));
            var legenda = $('#modulacoesFotos div:first').find('img').attr("alt");
            $('#legenda').text(legenda);

            $('#modulacoesFotos').css('margin-left', -largura);
            $('#modulacoesFotos').animate({ 'margin-left': '+=' + largura }, 500, function () {

            });
        }
    });

    var legenda = $('#modulacoesFotos div:first').find('img').attr("alt");
    $('#legenda').text(legenda);

    /** FIM MODULACOES **/

});




/** MARCAR MENUS LATERAIS **/
function marcaMenuLateral(categoria) {
    if (categoria != 0) {
        var arrayCategorias = $(".menu_body div");
        $(".menu_head").addClass("bold");
        $(".menu_head").next().toggleClass('bg_on');
        $(".menu_head").next().next().toggle();
        $(arrayCategorias[categoria - 1]).addClass("activo");
    }
}

function marcaMenuLateralProdutos(categoria, subCategoria) {
    var arrayCategorias = $(".menu_head");
    $(arrayCategorias[categoria - 1]).addClass("bold");
    $(arrayCategorias[categoria - 1]).next().toggleClass('bg_on');
    $(arrayCategorias[categoria - 1]).next().next().toggle();
    var arraySubcategorias = $(arrayCategorias[categoria - 1]).next().next().children("div");
    $(arraySubcategorias[subCategoria - 1]).addClass("activo");
}
/** FIM MARCAR MENUS LATERAIS **/




