//<![CDATA[
	
	/*
	 * SCRIPT PRINCIPAL USADO NA MAIORIA DAS PÁGINAS
	 * -------------------------------------------------------
	 * 
	 * Autor: Gilmar Soares <professorgilmagro@gmail.com>
	 * Empresa: ENC Interativa
	 * 
	 * */
	
        var expand = true;
        var int_expand = true;
        var j = jQuery;
        var ie = (navigator.userAgent.toLowerCase().indexOf("msie")>0) ? true : false;
        var ie7 = (navigator.userAgent.toLowerCase().indexOf("msie 7")>0) ? true : false;
        var ipad = (navigator.userAgent.toLowerCase().indexOf("ipad") == -1) ? false : true;
                        
	jQuery(function(){
                
        
        j("#menu a").not(".active").not(".submenu a").hover(function(){
            j(this).stop().animate({backgroundColor:'#009EE0'},750);
        },function(){
            j(this).stop().animate({backgroundColor:'#000'},500);
        })
        
        if(ipad){
            j("#menu,header .box-integer").addClass("ipad");
        }
        
        /*
            VERIFICA QUAL E A URL ATUAL E APLICA O ESTILO AO MENU 
        */
       
        var url = window.location.pathname;
                
         if(url.indexOf('regulamento')>0){
            j("a.reg").addClass("active");
         }
        
        j("#menu nav a.active").click(function(e){
	    	if(j(this).attr('href') != ROOT_PATH+"trabalhos/portifolio"){
	            e.preventDefault();
	    	}
	    	if(j(this).attr('href') == ROOT_PATH+"trabalhos/cases"){
	            window.location.href = ROOT_PATH+"trabalhos/cases";
	    	}
	    	if(j(this).attr('href') == ROOT_PATH+"trabalhos/digital"){
	            window.location.href = ROOT_PATH+"trabalhos/digital";
	    	}
        });
        
        
        j("header button.cancelar").click(function(){
            j(this).parent().parent().parent().parent().fadeOut(500);
        });
        
        j("header a.imprensa").click(function(e){
            e.preventDefault();
            j("header .form-imprensa").fadeIn(500);
            j("header .form-contact").fadeOut(500);
            expand = true;
        })
        
        /**
         * ENVIA E-MAIL DE CONTATO E IMPRENSA
         **/
        
        j("header #frmContact").submit(function(){
                var data = "type=contact&" + j(this).serialize();
                j.post(ROOT_PATH + "view/pontodecriacao/mail.php",data,function(response){
                    if(response.success){
                        j("header .form-contact").fadeOut(500);
                    }
                    msgBox(response.message);
                },"json");
            
             return false;
             
        });
        
        j("header #frmImprensa").submit(function(){
            var data = "type=press&" + j(this).serialize();
                j.post(ROOT_PATH + "view/pontodecriacao/mail.php",data,function(response){
                    if(response.success){
                        j("header .form-imprensa").fadeOut(500);
                    }
                    msgBox(response.message);
                },"json");
            
             return false;
        })
        
        /**
         ***********************************************************************
         **/
        
        
        j("a#contact").click(function(e){
           if(expand){
               j("header .form-contact").fadeIn(500); 
               j("header .form-imprensa").fadeOut(500);
           }else{
               j("header .form-contact").fadeOut(500);
           }
           expand = !expand;
           e.preventDefault();
        });
        
        j("a.integer").click(function(e){
           e.preventDefault();
           j("header .twitter-box").fadeOut(500);
           
           if(int_expand)
                j(".box-integer").animate({marginTop:0},1500);
           else
             if(j(".box-integer").hasClass("expanded")){
                j(".box-integer").animate({width:380,height:275},1250).removeClass("expanded").animate({marginTop:-280},800);
            }else{
                j(".box-integer").animate({marginTop:-280},800);
            }
             int_expand = !int_expand;
        });
        
        j(".box-integer .back").click(function(){
            int_expand = true;
            j("div.resume").show();
            j("div.full").hide();
            if(j(".box-integer").hasClass("expanded")){
                j(".box-integer").animate({width:380,height:275},1250).removeClass("expanded").animate({marginTop:-280},800);
            }else{
                j(".box-integer").animate({marginTop:-280},800);
            }
        });
        j(".box-integer .more").click(function(){
            var w = window.innerwidth;
            var h = window.innerHeight;
            h = (h==null) ? document.documentElement.clientHeight : h;
            h -= 45;
            w = (w==null) ? document.documentElement.clientWidth : w;
            j(".box-integer").addClass("expanded").stop().animate({width:w,height:h},1500);
            j("div.resume").hide();
            j("div.full").show();
        });
        
        /*
         *BUSCA OS ULTIMOS TWEETS
         *
         **/
    
    j("header .twitter-box").css({left:j("header .social-network a.twitter").offset().left-147}).hover(null,function(){j(this).fadeOut(500)})
    j("header .social-network a.twitter").hover(function(){
        j("header div.twitter-box").fadeIn(500);
        j(".box-integer .back").trigger("click");
        retorna_tweets(1);
    })
    
    var usuario = 'pontodecriacao';
    var formato = 'json';
    var url = 'http://api.twitter.com/1/statuses/user_timeline.'+formato+"?callback=?";

    function retorna_tweets(pagina){

        j.getJSON(url, {screen_name:usuario, page:pagina}, function(tweets){

            var post = "";
            for(x=0;x<3;x++){
                 
                 var er = new RegExp(/(http:\/\/)[a-zA-Z0-9\-.\/]*/);

                 var texto = tweets[x].text;
                 var href = texto.match(er);
                 
                 if(href!=null){
                    var link = '<a href="' +  href[0] + '" >' + href[0] + '</a>';
                    texto = texto.replace(href[0], link);
                 }
                 
                  post += "<li>";
                  post += "<img src='" + tweets[x].user.profile_image_url + "' />";
                  post += "<p>\"" + texto + "\"</p>";
                  post += "</li>";

                  
              }
                var content = "<ul>" + post + "</ul>";
                    if(ipad)
                    content += "<span class='close'>Fechar</span>";
                j(".twitter-box").html(content);
        });
    }
    
    j("header .twitter-box span.close").live("click",function(){
        j("header .twitter-box").fadeOut(800);
    });
            
       /*
		ALERT PERSONALIZADO
        */
    var msg = "";
    jQuery("#msgBox").dialog({autoOpen: false});
    
    /*j(".scroll").jScrollPane();*/
           
    
    });
    
    function msgBox(message,titulo,fn){

            if(fn!=null){
                
                jQuery("#msgBox").dialog({
                    close:fn
                });
            }
            jQuery("#msgBox").html(message);
            jQuery("#msgBox").dialog({position: ['center','center'],title:titulo,minWidth:350,minHeight:160,modal:true,buttons: {"Fechar": function() {jQuery(this).dialog("close");}}});
            jQuery("#msgBox").dialog('open');
    }

    /*
    FUNÇÃO PARA VERIFICAR O E-MAIL
    */

function checkMail(mail){
    var er = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/);
    if(typeof(mail) == "string"){
            if(er.test(mail)){return true;}
    }else if(typeof(mail) == "object"){
            if(er.test(mail.value)){ 
                 return true; 
            }
    }else{
         return false;
    }
}

function verificaNumero(e) {
    if (e.which != 8 && e.which != 0 && (e.which < 48 || e.which > 57)) {
        return false;
    }
}


     
//]]>

