$(function(){
    var i =0,
    servicos_home_intervalo,fotos_home_intervalo,
    time_servicos_home = 20000,time_fotos_home=10000,
    liWidth,dataWidth;
    
    
    $(".menu ul li:first").addClass("menufirst");    
    $(".menu ul li:last").addClass("menulast");
    
    setTimeout(function(){
        $(".logo").fadeIn("slow",function(){
            $(".contatos").fadeIn("slow");
        });
    },100);
    
    
    $.each($(".menu li"),function(){
        if(!$(this).hasClass("sep")){
            $(this).slideDown(1000+i); 
            i = i+100;
        }else{
            $(this).fadeIn("slow");
        }
    });
    
    
    $.fn.initServico = function(){
        servicos_home_intervalo = setInterval(function(){
            $.fn.exibe_descricao_servico();
        },time_servicos_home);
    };
    
    $.fn.exibe_descricao_servico = function(){
        var el = $(".servicoshome li.active");
        if(el.length < 1){
            el = $(".servicoshome li:first");
            el.addClass("active");
        }else{
            el.removeClass("active");
            if(el.next().length < 1){
                el = $(".servicoshome li:first");    
                el.addClass("active");
            }else{
                el.next().addClass("active");
            }
        }
        
        $.each($(".servicoshome li"),function(){
            if($(this).hasClass("active")){
                $(this).removeClass("disabled");
                $(this).find(".descricaoservico").slideDown("slow");
            }else{
                $(this).find(".descricaoservico").slideUp("slow");
                $(this).addClass("disabled");
            }
        });
    }
    
    
    $(".servicoshome li a").click(function(){
        $.each($(".servicoshome li"),function(){
            if($(this).hasClass("active")){
                $(this).removeClass("active");
                $(this).find(".descricaoservico").slideUp("slow");
            }
        });

        $(this).parents("li").addClass("active");
        clearInterval(servicos_home_intervalo);
        $.each($(".servicoshome li"),function(){
            if($(this).hasClass("active")){
                $(this).removeClass("disabled");
                $(this).find(".descricaoservico").slideDown("slow");
            }else{
                $(this).find(".descricaoservico").slideUp("slow");
                $(this).addClass("disabled");
            }
        });
        setTimeout(function(){
            $.fn.initServico();
        },1000);
    })
    
    if($(".servicoshome").length > 0){ 
        $.fn.exibe_descricao_servico();
        setTimeout(function(){
            $.fn.initServico();
        },1000);
    }
   
   
    if($(".noticias").length > 0){
        $(".noticias li:last").css({
            'border':'0px'
        })
        $('.noticias li').hover(function(){
            $(this).css({
                'background':'#F8F8F8'
            })
        },function(){
            $(this).css({
                'background':'#FFFFFF'
            })
        })

        if($(".noticias li").length > 0){
            liWidth = $(".noticias li").width();
            dataWidth = $(".noticias li .data").width();
            $(".noticias li .resumo").css({
                'width':(liWidth-dataWidth-20)+"px"
            });
        }
        
    }
    
    if($(".legend").length >0){
        $(".legend").css({
            'opacity':'0.8'
        })
    }
    
    if($(".imagetransbox").length > 0){
        
        $.fn.atualiza_box_imagem = function(item_id){
            $.each($(".imagetransbox .itemimagem"),function(){
                $(this).css("display","none");
            });
            $(".imagetransbox").find(".itemimagem").eq(item_id).fadeIn("slow");
            $.each($(".imagetransbox ul li"),function(){
                $(this).removeClass("active");
            });
        }
        
        $(".itemimagem:first").fadeIn("fast");
        $(".imagetransbox").height($(".imagetransbox img").height());
        
        $(".imagetransbox ul li").click(function(){
            var el = $(this);
            var item_id = $.trim(el.text());
            item_id = parseInt(item_id);
            if(item_id){
                item_id = item_id-1;
                $.fn.atualiza_box_imagem(item_id);
                el.addClass("active");
            }
        });        
    }
    
    $(".contatos").css({
        'opacity':'0.9'
    });
    
    
    $(".masktelefone").mask("(99)9999-9999"); 
    
    /*$(".servicos_entr").find(".par").css("display","none");
    $.each($(".servicos_entr").find("h4"),function(){
        $(this).css({
            'cursor':'pointer',
            'display':'block'
        });
        $(this).click(function(){
            $(".servicos_entr").find(".par").css("display","none");
            $(".servicos_entr").find("h4").removeClass("servico_selecionado");
            $(this).next(".par").toggle('slow');
            $(this).addClass("servico_selecionado");
        });
    });*/



    var vitrine = $(".vitrine");
    var imagens = vitrine.find("li");
    var intervalo;

    $.fn.showNext = function(){
        imagens.css('display','none');
        var current = $(".current_img_display");
        var prox = current.next('li');
        if(prox.length < 1){
            prox = imagens.eq(0);
        }
        current.removeClass("current_img_display");
        prox.addClass("current_img_display");
        $.fn.anima(prox);
    }

    $.fn.anima = function(img){
        img.animate({
            'width':'toggle'
        },1000);
    }

    $.fn.initVitrine = function(){
        var primeira = imagens.eq(0);
        $.fn.anima(primeira);
        primeira.addClass("current_img_display");
        intervalo = setInterval(function(){
            $.fn.showNext();
        },10000);
    }

    $.fn.initVitrine();


})
