
$(document).ready(function () {
       
    $('.linha a').click(function () {
        $(".linha-completa").overlay({
            top: 100,
            mask: {
                color: '#000000',
                loadSpeed: 200,
                opacity: 0.9
            },
            load: true
        }).load();
    });   
    
    if("home" == module){
        $("ul#ticker01").liScroll();
    
        // Carrossel vitrine home
        $("#carrossels").scrollable({
            circular: true,
            next: "#carrossels .nexts",
            prev: "#carrossels .prevs"
        }).navigator().autoscroll({ 
            autoplay: true,
            interval: 4000,
            autopause: true
        });
    
    }   
    
    if("produtos" == module){
        
        var init = $("#desc-menu").offset().top;
        var docked;
        
        $(window).scroll(function () {
            if (!docked && ($("#desc-menu").offset().top - $(window).scrollTop() < 0)) {
                $("#desc-menu").css("top", "0");
                $("#desc-menu").css("position", "fixed");
                docked = true;
            } else if (docked && $(window).scrollTop() <= init) {
                $("#desc-menu").css("position", "relative");
                docked = false;
            }
        });
        
        $(".descricao").click(function(){
            $('html,body').animate({
                scrollTop: $('#descricao').offset().top - 70
            }, 400);
        });
        $(".caracteristicas").click(function(){
            $('html,body').animate({
                scrollTop: $('#caracteristicas').offset().top - 70
            }, 400);
        });
        $(".principais").click(function(){
            $('html,body').animate({
                scrollTop: $('#principais').offset().top - 70
            }, 400);
        });
        $(".acessorios").click(function(){
            $('html,body').animate({
                scrollTop: $('#acessorios').offset().top - 70
            }, 400);
        });
        $(".especificacoes").click(function(){
            $('html,body').animate({
                scrollTop: $('#especificacoes').offset().top - 70
            }, 400);
        });
        
        $(".scroll").scrollable({
            circular: true
        }).click(function() {
            $(this).data("scrollable").next();		
        });
    }
    
    if("depoimentos" == module || "quemsomos" == module){
        $("#depoimentos").tabs(".pane", {
            tabs: 'h2', 
            effect: 'slide', 
            initialIndex: null
        });
        $("#quem-somos").tabs(".pane", {
            tabs: 'h2', 
            effect: 'slide', 
            initialIndex: null
        });
    }
    
    if("projetos" == module){
        $(".abre-projetos").click(function(){
            $(".abre-projetos").css("color","#3668c4");
            $(".abre-projetos").css("cursor","pointer");
            $(".lista-projetos li").animate({
                height: '20',
                width: '380',
                fontSize: '14'
            });
            $(".lista-projetos li").css("background","#244583");
            $(this).css("color","#fff");
            $(this).css("cursor","default");
            $(this).parent().animate({
                height: '175',
                width: '940',
                fontSize: '18'
            });
            $(this).parent().css("background","#333");
        });
    
        $("#carrossels-projetos-shows").scrollable({
            next: "#carrossels-projetos-shows .nexts",
            prev: "#carrossels-projetos-shows .prevs"
        });
    
        $("#carrossels-projetos-teatros").scrollable({
            next: "#carrossels-projetos-teatros .nexts",
            prev: "#carrossels-projetos-teatros .prevs"
        });
    
        $("#carrossels-projetos-igrejas").scrollable({
            next: "#carrossels-projetos-igrejas .nexts",
            prev: "#carrossels-projetos-igrejas .prevs"
        });      


        $("#open-academias").click(function(){
            window.location.hash ="#academias"
        });
        $("#open-cinemas").click(function(){
            window.location.hash ="#cinemas"
        });
        $("#open-casas").click(function(){
            window.location.hash ="#casas-noturnas"
        });
        $("#open-hoteis").click(function(){
            window.location.hash ="#hoteis"
        });
        $("#open-estadios").click(function(){
            window.location.hash ="#estadios"
        });
        $("#open-igrejas").click(function(){
            window.location.hash ="#igrejas"
        });
        $("#open-museus").click(function(){
            window.location.hash ="#museus"
        });
        $("#open-radio").click(function(){
            window.location.hash ="#radio"
        });
        $("#open-teatros").click(function(){
            window.location.hash ="#teatros"
        });
        $("#open-terminais").click(function(){
            window.location.hash ="#terminais"
        });
        $("#open-trios").click(function(){
            window.location.hash ="#trios"
        });
        $("#open-feelit").click(function(){
            window.location.hash ="#feelit"
        });
        
        switch (window.location.hash) {
            case '#academias':
                $("#open-academias").css("background","#244583");
                $("#open-academias").animate({
                    height: '175',
                    width: '940',
                    fontSize: '18'
                });
                $("#open-academias").css("background","#333");            
                break;
            case '#cinemas':
                $("#open-cinemas").css("background","#244583");
                $("#open-cinemas").animate({
                    height: '175',
                    width: '940',
                    fontSize: '18'
                });
                $("#open-cinemas").css("background","#333");            
                break;
            case '#casas-noturnas':
                $("#open-casas").css("background","#244583");
                $("#open-casas").animate({
                    height: '175',
                    width: '940',
                    fontSize: '18'
                });
                $("#open-casas").css("background","#333");            
                break;
            case '#hoteis':
                $("#open-hoteis").css("background","#244583");
                $("#open-hoteis").animate({
                    height: '175',
                    width: '940',
                    fontSize: '18'
                });
                $("#open-hoteis").css("background","#333");            
                break;
            case '#igrejas':
                $("#open-igrejas").css("background","#244583");
                $("#open-igrejas").animate({
                    height: '175',
                    width: '940',
                    fontSize: '18'
                });
                $("#open-igrejas").css("background","#333");            
                break;
            case '#estadios':
                $("#open-estadios").css("background","#244583");
                $("#open-estadios").animate({
                    height: '175',
                    width: '940',
                    fontSize: '18'
                });
                $("#open-estadios").css("background","#333");            
                break;
            case '#igrejas':
                $("#open-igrejas").css("background","#244583");
                $("#open-igrejas").animate({
                    height: '175',
                    width: '940',
                    fontSize: '18'
                });
                $("#open-igrejas").css("background","#333");            
                break;
            case '#museus':
                $("#open-museus").css("background","#244583");
                $("#open-museus").animate({
                    height: '175',
                    width: '940',
                    fontSize: '18'
                });
                $("#open-museus").css("background","#333");            
                break;
            case '#radio':
                $("#open-radio").css("background","#244583");
                $("#open-radio").animate({
                    height: '175',
                    width: '940',
                    fontSize: '18'
                });
                $("#open-radio").css("background","#333");            
                break;
            case '#teatros':
                $("#open-teatros").css("background","#244583");
                $("#open-teatros").animate({
                    height: '175',
                    width: '940',
                    fontSize: '18'
                });
                $("#open-teatros").css("background","#333");            
                break;
            case '#terminais':
                $("#open-terminais").css("background","#244583");
                $("#open-terminais").animate({
                    height: '175',
                    width: '940',
                    fontSize: '18'
                });
                $("#open-terminais").css("background","#333");            
                break;
            case '#trios':
                $("#open-trios").css("background","#244583");
                $("#open-trios").animate({
                    height: '175',
                    width: '940',
                    fontSize: '18'
                });
                $("#open-trios").css("background","#333");            
                break;
            case '#feelit':
                $("#open-feelit").css("background","#244583");
                $("#open-feelit").animate({
                    height: '175',
                    width: '940',
                    fontSize: '18'
                });
                $("#open-feelit").css("background","#333");            
                break;
        }
        
        
    }
    
    if("contato" == module){
    
        $("#contato_cep").change(function(){
            getEndereco();
        });
   
        $("#contato_cep").masked("99999-999");
        $("#contato_telefone").masked("(99)9999-9999");
    
    
        //Limpar Forms
        $("input:text, textarea").each(function () {
            var changed = false;
                
            if ("" == $(this).val()) {
                $(this).val($(this).attr("rel"));
                changed = false;
            }
                
            if ($(this).val() != $(this).attr("rel")) {
                changed = true;
                $(this).removeClass('changed');
            }
                
            $(this).focusin(function () {
                if (false == changed) {
                    $(this).val("");
                    $(this).addClass('changed');
                }
            });
                
            $(this).focusout(function () {
                if ("" == $(this).val()) {
                    $(this).val($(this).attr("rel"));
                    changed = false;
                    $(this).removeClass('changed');
                } else {
                    changed = true;
                    $(this).addClass('changed');
                }
            });
        });
    }
    
      
    $("#nav li").mouseover(function() {
        $(".submenu", this).fadeIn();
    });

    $("#nav li").mouseleave(function(){
        $(".submenu", this).fadeOut();
    });

    $(".submenu li").mouseover(function(){
        $("ul", this).fadeIn(); 
    });
    
    $(".submenu li").mouseleave(function(){
        $("ul", this).fadeOut(); 
    });
    
    $("img[rel]").overlay();
    
    
    //$.getJSON("http://twitter.com/statuses/user_timeline/fzaudiobr.json?callback=?", function(data) {
    //   $("#carrega_tweet").html(data[0].text);
    //});
    
    if("home" == module){
             
		
        function getTwitterMessage() {
            cappTwitterSearch("from:fzaudiobr", 1, function (twitter) {
                if (twitter.results[0]) {
                    $.ajax({
                        url: base_url + "home/format-twitter",
                        type: "POST",
                        data: {
                            "msg": twitter.results[0].text
                        },
                        dataType: "json",
                        success: function(response) {
                            $(".carrega_tweet").html('<p class="teste-twitter"><a target="_blank" href="http://twitter.com/#!/fzaudiobr">@fzaudiobr</a>: ' + response.text + '</p>');
                        }
                    });
                    return false;
                }
            });
            setTimeout('getTwitterMessage()', 50000);
        }
        
        
        function cappTwitterSearch(q, rpp, callback, result_type, dataType) {
            if (undefined == result_type) {
                result_type = "recent";
            }

            if (undefined == dataType) {
                dataType = "jsonp";
            }

            $.ajax({
                url: "https://search.twitter.com/search.json",
                data: {
                    "q": q,
                    "rpp": rpp,
                    "result_type": result_type
                },
                "dataType": dataType,
                success: function(response) {
                    callback(response);
                }
            });
        }
		
		getTwitterMessage();
    }
    
});
