/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 * go.js
 */

(function($) {
    var pages = {
        'anunciar-links-patrocinados':true,
        'blogs-corporativos-blog-empresa':true,
        'cadastro-site-diretorios-busca':true,
        'clientes':true,
        'consultoria':true,
        'contato':true,
        'criacao-de-sites-bahia':true,
        'criacao-de-sites-ceara':true,
        'criacao-de-sites-fortaleza':true,
        'criacao-de-sites-para-empresas':true,
        'criacao-de-sites-sao-paulo':true,
        'criacao-de-websites':true,
        'criar-e-desenvolver-sistemas':true,
        'desenvolvimento-de-sites':true,
        'desenvolvimento-de-websites':true,
        'empresa-de-seo':true,
        'empresa-de-webdesign':true,
        'hospedagem-de-sites':true,
        'loja-virtual-comercio-eletronico':true,
        'marketing-sites-de-busca':true,
        'moox':true,
        'newsletter-boletim-informativo':true,
        'o-que-e-otimizacao-de-site':true,
        'otimizacao-sites-busca':true,
        'otimizacao':true,
        'portfolio':true,
        'portifolio':true,
        'primeiro-lugar-google':true,
        'primeiro-lugar-sites-busca':true,
        'servicos-web':true,
        'sistema-de-busca-interno':true,
        'sistema-de-noticias':true,
        'sistema-gerenciamento-conteudo':true,
        'sistemas':true,
        'sobre':true,
        'trabalhos':true,
        'websites':true,
        '404':true,
        'blogs':true,
        'e-commerce':true,
        'google-adsense':true,
        'google-adwords':true,
        'hot-sites':true,
        'performace-de-sistemas':true,
        'portais-web':true,
        'seo':true,
        'sistemas-web':true,
        'intranet':true,
        'gestao':true,
        'compartilhamento':true,
        'automacao':true,
        'auditoria':true,
        'tecnologia-da-informacao':true,
        'web':true,
        'banco-de-dados':true,
        'sites-web':true
    };
    var app = $.sammy('#changer', function() {

        this.get('#!/:name', function() {
            var menu = this.params.name;
            
            this.swap = function(content) {

                this.$element().hide().html(content).fadeIn(1500);
				
                verifPage(menu);

            }
            
            if(pages[menu]) {
                this.partial("paginas/" + menu + ".html");
            
                menu_ativo(menu);
            }
            else {
                this.redirect("#!/404");
            }

        });
		
        this.get('#!/:action/:id', function(){
            var action = this.params.action;
            var id = this.params.id;
            this.swap = function(content) {
                this.$element().hide().html(content).fadeIn(1500);
                
                verifPage(action);
                
                acordion(id);
            }
            if(pages[action]){
                this.partial("paginas/" + action + ".html");
                
                menu_ativo('desenvolvimento');                
            }
        });

    });


    $(function() {
        app.run('#!/moox');
    });

})(jQuery);
function menu_ativo(menu) {
    var menu_ativo = {
        'moox'              : true,
        'sobre'             : true,
        'portfolio'         : true,
        'clientes'         : true,
        'contato'           : true,
        'desenvolvimento'   : true
    }
    if(!menu_ativo[menu]){
        menu = 'desenvolvimento'
    }
    $("#menu li[param="+menu+"]").addClass("ativo");
    $("#menu li[param!="+menu+"]").removeClass("ativo");
}
function acordion(id) {
    $(".accord .item[param='"+id+"']").css({
        display:'block'
    });
}
$(function(){
    $('#banner .slider').nivoSlider({

        effect:'sliceUp', //Specify sets like: 'fold,fade,sliceDown'
        slices:10,
        animSpeed:800, //Slide transition speed
        pauseTime:5000,
        startSlide:0, //Set starting Slide (0 index)
        directionNavHide:true, //Only show on hover
        controlNav: true, //1,2,3...
        controlNavThumbsFromRel:true, //Use image rel for thumbs
        controlNavThumbsSearch: '.jpg', //Replace this with...
        controlNavThumbsReplace: '_thumb.jpg', //...this in thumb Image src
        keyboardNav:true, //Use left & right arrows
        pauseOnHover:true, //Stop animation while hovering
        manualAdvance:false, //Force manual transitions
        captionOpacity:0.8 //Universal caption opacity

    });
});

$(function(){
    
    $("#menu li.subm").hover(function(){
        
        $(".submenu").fadeIn(300).animate({
            top: "30px"
        }, 800).fadeIn(800);
 
    }, function(){
        $(".submenu").stop(true, true).animate({
            top: "20px"
        }, 800).fadeOut(500);
    })

})


function tab(){

    var param = "";

    $("#tab li").live("click", function(){

        param = $(this).attr("param");

        $(".tab[param="+param+"]").fadeIn(1200);
        $(".tab[param!="+param+"]").fadeOut(500);

        $("#tab li[param="+param+"]").addClass("ativo");
        $("#tab li[param!="+param+"]").removeClass("ativo");

    });

}


function verifPage(page){

    if(page != "moox"){

        $("body").autoscroll(600, 2000);
    }

    if(page == "moox"){
        tab();

        setInterval("changerTec($('#tec img'),true,false,'img')", 8000);
    }

}

$(function(){

    $(".accord h3").live("click", function(){
	
        itm = $(this).attr("param");
		
        $(".accord .item[param="+itm+"]").slideDown("slow");
        $(".accord .item[param!="+itm+"]").slideUp("slow");

        $(".accord h3[param="+itm+"]").css({
            backgroundPosition: "top center"
        });
        $(".accord h3[param!="+itm+"]").css({
            backgroundPosition: "bottom center"
        });
                
        $(".accord h3[param="+itm+"] a").css({
            backgroundPosition: "right 17px"
        });
        $(".accord h3[param!="+itm+"] a").css({
            backgroundPosition: "right -15px"
        });
			
    });

});


function changerTec(imgch,sametime,backwards,type){
    
    imgch.each(function(index){
        if($(this).css('display') != 'none'){
            curimg = $(this);
        }
    });

    if(curimg != false){
        if(!sametime){
            curimg.fadeOut(350,function(){
                total = imgch.size();
                pos = $(type,$(this).parent()).index($(this));
                next = (!backwards) ? pos+1 : pos-1;
                if(backwards){
                    if(next < 0){
                        next = (total-1);
                    }
                } else {
                    if(next == total){
                        next = 0;
                    }
                }
                $(type, $(this).parent()).eq(next).fadeIn(350);
            });
        } else {
            total = imgch.size();
            pos = $(type,curimg.parent()).index(curimg);
            next = (!backwards) ? pos+1 : pos-1;
            if(backwards){
                if(next < 0){
                    next = (total-1);
                }
            } else {
                if(next == total){
                    next = 0;
                }
            }
            curimg.fadeOut(1500);
            $(type, curimg.parent()).eq(next).fadeIn(1500);
        }
    }
}

$(function(){
   
    $('ul#jcloud-tags').jcloud({
        radius:500,
        size:40,
        step:20,
        speed:50,
        flats:10,
        clock:10,
        areal:500,
        splitX:80,
        splitY:100,
        colors:['#FFFFFF','#DDDDDD','#EEEEEE','#DDDDDD','#EEEEEE','#DDDDDD']
    });
   
});


//plugin autoscroll barra de rolagem para subir ao top
(function($){
    $.fn.autoscroll = function(e, t) {
        jQuery('html,body').animate(
        {
            scrollTop: e
        },
        t
        );
        return this;
    };
})(jQuery);//Fim do plugn


itemAtual = "";

/* ABRE MODAL */
(function(){
    $.fn.openModal = function(mask,pTop) {

        modal = $(this);
        maskID = mask;
        mask = "#"+mask;

        $modal = {
            "z-index":"9999999",
            "display":"block",
            "position":"fixed"
        };

        $mask = {
            "background":"#000",
            "position":"absolute",
            "left":"0",
            "top":"0",
            "z-index":"999999",
            "display":"block",
            "opacity":"2.8",
            "filter":"alpha(opacity=8)",
            "-moz-opacity":"2.8"
        };

        $overflow = {
            "overflow":"hidden"
        };

        $("body div[id='"+maskID+"']").remove();
        $("body").append("<div id='"+maskID+"'></div>");

        $("body").css($overflow);
        $(modal).css($modal);
        $(mask).css($mask);

        $(modal).css("display","block");
        $(modal).hide();

        var maskHeight = $(document).height();
        var maskWidth = $(window).width();

        $(mask).css({
            'width':maskWidth,
            'height':maskHeight
        });

        $(mask).fadeIn("fast", function(){

            $(this).css({
                opacity: "0.3"
            });

            var winH = $(window).height();
            var winW = $(window).width();

            $(modal).css('top',  winH / 2-($(modal).height() / 2)+parseInt(pTop));
            $(modal).css('left', winW / 2-($(modal).width() / 2)+15);
            $(modal).slideDown("slow");
        });

    };
})(jQuery);

(function(){
    $.fn.closeModal = function(mask) {

        $overflow = {
            "overflow":""
        }

        $(this).hide();
        $("body div[id='"+mask+"']").remove();
        $("body").css($overflow);

    };
})(jQuery);
//fim do plugin modal

//Função modal recupera senha
$("#videos").live("click", function(){

    $("#modal-video").openModal("mask",0);
});

$("#close-vid").live("click", function(){

    $("#modal-video").closeModal("mask");

});


/* Função ajax que captura os dados do formulario */
$("#newslatter #enviar").live("click",function(){

    var nome = $("#newslatter #nome").val();

    var email = $("#newslatter #email").val();

    var data = "nome="+nome+"&email="+email
    var cont = 0;
    var txtHTML = '';


    if(nome.length < 1){
        txtHTML += "- Informe o campo Nome\n";
        ++cont;
    }

    if(email.length < 1){
        txtHTML += "- Informe o campo email\n";
        ++cont;
    }

    else if(email.indexOf("@") == -1){
        txtHTML += "- Email informado incorreto\n";
        ++cont;
    }

    if(cont > 0){

        alert (txtHTML);

        return false;
    }

    $.ajax({

        type: "POST",
        url: "newslatter.php",
        data: data,
        success: function(result){

            alert(result);

            return false;

        }

    });

    $("#inicio input[type='text']").each(function(){
        $(this).val("Digite seu e-mail aqui");
    });

    return false;

});// Fim da função newslatter

/* Função ajax que captura os dados do formulario */
$("#contato #enviar").live("click",function(){

    var nome 		= $("#contato #nome").val();
    var email 		= $("#contato #email").val();
    var mensagem	= $("#contato #msg").val();

    var data = "nome="+nome+"&email="+email+"&mensagem="+mensagem;
    var cont = 0;
    var txtHTML = '';

    if(nome.length < 1){
        txtHTML += "- Informe o campo nome\n";
        ++cont;
    }

    if(email.length < 1){
        txtHTML += "- Informe o campo email\n";
        ++cont;
    }

    else if(email.indexOf("@") == -1){
        txtHTML += "- Email informado incorreto\n";
        ++cont;
    }

    if(mensagem.length < 1){
        txtHTML += "- Informe o campo mensagem\n";
        ++cont;
    }

    if(cont > 0){

        alert (txtHTML);

        return false;
    }

    $.ajax({

        type: "POST",
        url: "email.php",
        data: data,
        success: function(result){

            alert(result);

            return false;

        }

    });

    $("#contato input[type='text'], .contato, textarea").each(function(){
        $(this).val("");
    });

    return false;

});//Fim da função email

