//Objeto padrao lcc
var app = {
    init: function() {
        AOS.init({
            once: true
        });

        app.loadSticky();
        window.onscroll = function() {app.loadSticky();};

        app.loadToUp();
        app.changelang();
        app.loadButtons();
        app.loadMenu();
        app.animacaoLead();
        app.setStrongMovidos();

        //app.galeria( elemento, qtd, nav, dots, loop, autoplay, hoverPause, animateIn, animateOut, dotNumero)
        app.galeria('.owl-carousel', {"small":1,"medium":1,"large":1}, true, false, true, false, true, false, false, false, false);
        //app.galeria('#materiais-home', {"small":1,"medium":1,"large":3}, true, false, true, false, true, false, false, false, false);
        //app.galeria('#galeria-numeros', {"small":1,"medium":1,"large":4}, false, true, true, false, true, false, false, false, false);
        app.galeria('.carrossel-depoimentos', {"small":1,"medium":1,"large":3}, true, true, false, false, true, false, false, false, true);
        app.galeria('.carousel-noticias', {"small":1,"medium":1,"large":3}, true, true, false, false, true, false, false, false, false);

        app.navAdvogado();
        app.modalNews();
        app.changeExpertise();
        app.resetForm();
        app.showHidePesquisa();
        app.menuServico();

        jQuery('#swipper-translate').click(function(e){
            e.prevendDefault();
            jQuery('#Ellipse_1').attr('cy','10');
            window.location.href = jQuery(this).attr('href');
        });
    },
    loadSticky: function () {
        var height = jQuery(window).scrollTop();
        var navbar = document.getElementById("navbar");

        if (height >= 1 || jQuery('body').hasClass('page-template-page-politica-privacidade')
             || jQuery('body').hasClass('error404')) {
            navbar.classList.add("sticky");
            navbar.classList.remove("position-absolute");
            navbar.classList.add("position-fixed");
        } else {
            if(!jQuery('#navbarCollapse').hasClass('in')){
                navbar.classList.remove("sticky");
            }
            navbar.classList.remove("position-fixed");
            navbar.classList.add("position-absolute");
        }

        if(height > 200){
            jQuery('.to-top').addClass('show');
        }else{
            jQuery('.to-top').removeClass('show');
        }

        var $height =jQuery('body').height() - 750;

        if(jQuery('.menu-flutuante').val() != undefined){

            if(jQuery('.menu-flutuante').offset().top > $height){
                jQuery('.menu-flutuante').addClass('menu-flutante-bottom');
            }else{
                jQuery('.menu-flutuante').removeClass('menu-flutante-bottom');
            }
        }
        jQuery('.navbar-toggler').on('click',function(){
            if(height==0){
                if(jQuery('#navbarCollapse').hasClass('in')){
                    navbar.classList.remove("sticky");
                }else{
                    navbar.classList.add("sticky");
                }
            }
        });

    },
    loadToUp : function(){
        jQuery('.to-top').click( function(e) {
            e.preventDefault();
            document.body.scrollIntoView({behavior: 'smooth', block: 'start'});
            return false;
        });
    },
    changelang: function(){
        jQuery('.lang').change(function(){
            var $val = jQuery(this).val();
            window.location.href = $val;
        })
    },
    loadButtons: function(){
        jQuery('.btn').each(function(){
            var $conteudo = jQuery(this).find('span').html();
            jQuery(this).find('span').after('<p>'+$conteudo+'</p>');
        });
    },
    loadMenu: function(){
        // jQuery('.menu-item a').hover(function(){
        //     console.log(jQuery(this).parent().parent().hasClass('nav'));
        //     console.log(jQuery(this).parent().parent().attr('class'));
        //     if(!jQuery(this).parent().parent().hasClass('dropdown-menu') || jQuery(this).hasClass('dropdown-toggle')){
        //         jQuery('.dropdown-menu').each(function(){
        //             // jQuery(this).hide();
        //         });
        //     }
        // });
        jQuery(".dropdown-toggle").mouseenter(function(){
            jQuery('.dropdown-menu').each(function(){
                 jQuery(this).hide();
            });
            jQuery(this).parent().find('.dropdown-menu').show();
        });
    },
    animacaoLead: function(){
        if(jQuery("#animation span:first-child").html() != undefined){

            setInterval(function(){
                jQuery("#animation span:first-child").animate({ "right": "0", "left":"80px" }, "slow", function(){
                    setTimeout(function(){
                        jQuery("#animation span:first-child").animate({ "left": "0", "right":"80px" }, "slow");
                        jQuery('.counter').countTo('restart');
                    },5000);
                } );
                jQuery("#animation span:last-child").animate({ "left": "0", "right":"80px" }, "slow", function(){
                    setTimeout(function(){
                        jQuery("#animation span:last-child").animate({ "right": "0", "left":"80px" }, "slow");
                    },5000);
                }  );
            },10000);
        }

    },
    galeria:function(elemento, qtd, nav, dots, loop, autoplay, hoverPause, animateIn, animateOut, dotNumero, dotAjusta){
        var owl;
        if(jQuery(elemento).html() != undefined) {
            owl = jQuery(elemento).owlCarousel({
                loop: loop,
                autoplay: autoplay,
                animateIn: animateIn,
                animateOut: animateOut,
                //autoplaySpeed: 1000,
                nav: nav,
                dots: dots,
                //dotsData: true,
                autoplayHoverPause: hoverPause,
                responsiveClass: true,
                responsive: {
                    0: {
                        items: qtd.small
                    },
                    600: {
                        items: qtd.medium
                    },
                    1000: {
                        items: qtd.large
                    }
                }
            });
            if(dotAjusta == true) {

                var div = jQuery(elemento + ' .owl-stage-outer .owl-stage'),
                    dots = jQuery(elemento + ' .owl-dots'),
                    height = 0,
                    diferenca = 0;
                jQuery(div).find('.owl-item.active .item-depoimento').each(function () {
                    if(jQuery(this).outerHeight() > height){
                        height = jQuery(this).outerHeight();
                    }
                });
                diferenca = (div.outerHeight() - height)-40;
                jQuery(dots).css('marginTop','-'+diferenca+'px')

                owl.on('translated.owl.carousel', function (e) {
                    var div = jQuery(elemento + ' .owl-stage-outer .owl-stage'),
                        dots = jQuery(elemento + ' .owl-dots'),
                        height = 0,
                        diferenca = 0;
                    jQuery(div).find('.owl-item.active .item-depoimento').each(function () {
                        if(jQuery(this).outerHeight() > height){
                            height = jQuery(this).outerHeight();
                        }
                    });
                    diferenca = (div.outerHeight() - height)-40;
                    jQuery(dots).css('marginTop','-'+diferenca+'px')
                });
            }
            if(dotNumero == true){
                var i = 1,
                    num = "";
                jQuery(elemento+" .owl-dots .owl-dot").each(function(){
                    num = "";
                    if((i < 10)){
                        num = "0";
                    }
                    jQuery(this).html(num+i);
                    i++;
                });
            }
        }
    },
    /*galeria:function(elemento, qtd, nav, dots){
        if(jQuery(elemento).html() != undefined) {
            jQuery(elemento).owlCarousel({
                loop: false,
                autoplay: false,
                nav: nav,
                dots: dots,
                responsiveClass: true,
                responsive: {
                    0: {
                        items: qtd.small
                    },
                    600: {
                        items: qtd.medium
                    },
                    1000: {
                        items: qtd.large
                    }
                }
            });
        }
    },*/
    navAdvogado:function(){
        jQuery('#advogadoNav a').on('click', function (e) {
            e.preventDefault()
            jQuery(this).tab('show')
        });
    },
    modalNews: function () {
        // if(jQuery('#modalNews').html() != undefined){
        //     jQuery('#modalNews').on('show.bs.modal', function (event) {
        //         console.log('ha');
        //         jQuery('#modalNews').addClass('show');
        //     });
        //     jQuery('#modalNews').modal('show');
        // }
    },
    changeExpertise: function(){

        if(jQuery('#expertise-select').html() != undefined){
            jQuery('#expertise-select').change(function(){
                window.location.href = jQuery(this).val();
            });
        }
    },
    resetForm:function(){
        if(jQuery('#reset-form').html() != undefined){
            jQuery('#reset-form').click(function(e){
                document.getElementById('formulario_pesquisa').reset();
                jQuery('#input-search-conteudo input').val('');
            });
        }
    },
    setStrongMovidos:function(){
        if(jQuery('section.movidos h2').html() != undefined){

            var text = jQuery('section.movidos h2').text().trim().split(" ");
            var last = text.pop();
            jQuery('section.movidos h2').html(text.join(" ") + (text.length > 0 ? " <strong class='fw-700'>" + last + "</strong>" : last));
        }
    },
    showHidePesquisa:function(){
        jQuery('.pesquisa-s-h').on('click',function(){
            var dPesquisa = jQuery('#div-pesquisa-form');
            if(jQuery(dPesquisa).find('form').hasClass('mostra')){
                jQuery(dPesquisa).find('form').removeClass('mostra');
                jQuery('.pesquisa-s-h i').addClass('fa-search').removeClass('fa-times');
            }else{
                jQuery(dPesquisa).find('form').addClass('mostra');
                jQuery('.pesquisa-s-h i').addClass('fa-times').removeClass('fa-search');
            }
        });
    },
    menuServico:function(){
        if(jQuery('body').hasClass('single-servicos')){
            jQuery('#menu-principal-pt .item-menu-servicos').addClass('active');
        }
        if(jQuery('body').hasClass('single-post')){
            jQuery('#menu-principal-pt .item-noticias').addClass('active');
        }
        jQuery('.select-servicos-mob').change(function(){
            var pag = jQuery(this).val();
            window.location.href = pag;
        });
        /*if(jQuery('section.home-reconhecimento')) {
            var div = jQuery('section.home-reconhecimento .carrossel-depoimentos .owl-stage-outer .owl-stage'),
                dots = jQuery('section.home-reconhecimento .carrossel-depoimentos .owl-dots'),
                height = 0,
                diferenca = 0;
            jQuery(div).find('.owl-item.active .item-depoimento').each(function () {
                if(jQuery(this).height() > height){
                    height = jQuery(this).outerHeight();
                }
            });
            diferenca = (div.outerHeight() - height)-40;
            jQuery(dots).css('marginTop','-'+diferenca+'px')
        }*/
    }
};

jQuery("document").ready(function ($) {
    app.init();
});