 //var version = jQuery.browser.version.substr();


 jQuery(document).ready(function(){
    
    browserDetect();
    
    /**** selects ***/
    if(jQuery('.rightselect span.selectvalue').text() == ''){
      jQuery('span.selectvalue').each(function(i){
        jQuery(this).text(jQuery('select option:selected', jQuery(this).parent()).text());
      });
    }
    jQuery('.rightselect select').change(function(){
      jQuery('span.selectvalue', this.parentNode).text(jQuery('option:selected', this).text());
    });
    /**** selects ***/
    
    if(jQuery(".lateralDireita").css("display") == "block") {
      jQuery(".rubricas").css("width", "487px");
      jQuery(".pesqRub").css("right", "-228px");
    }
    
    jQuery(".acessoBt").click(function(){
      if(jQuery(".popWorkout").css("display") == "none")
        jQuery(".popWorkout").show(300);
      else
        jQuery(".popWorkout").hide(300);
    });
    
    jQuery(".popWorkout .close").click(function(){
      jQuery(".popWorkout").hide(300);
    });
    
    jQuery(".serContactado").click(function(){
      
      if(jQuery(".formContactLateral").css("display") == "none") {
        jQuery(".formContactLateral").css("display", "block");
        jQuery(".formContactLateral").animate({"height" : "227"}, 300);
      } else {
        jQuery(".formContactLateral").animate({"height" : "0"}, 300, function(){
          jQuery(".formContactLateral").css("display", "none");
        });
      }
      
    });
    
    retornaClientes();
    
    dscserT = jQuery(".uni_servico");
    for(i=0; i<dscserT.length; i++) {
      alt = jQuery("h4", dscserT[i]).height();
      if(alt > 25) {
        jQuery("h4", dscserT[i]).addClass("h4twolines");
      }
    }
    
    
    dscserT = jQuery("..desenvolvimento a");
    for(i=0; i<dscserT.length; i++) {
      alt = jQuery("h4", dscserT[i]).height();
      if(alt > 25) {
        jQuery("h4", dscserT[i]).addClass("h4twolines2");
      }
    }
    
    bugsIE7();
    
    //if(jQuery(".paginacaoGeralSite").length > 0)
      jQuery(".Modulonoticias .fim").show();
    
    if(jQuery(".rightRubrica").length == 0 && jQuery(".moduloContactos").length == 0 && jQuery(".lateralDireita").length == 0 && jQuery(".moduloFilosofia").length == 0)
      jQuery(".blocoRub").width(715);
    
    jQuery(".galeriaNewsletter").height(jQuery(".newsel").height());
    
 });
 
 
 function browserDetect() {
  /*
    if($.browser.ff) {
      jQuery(".linguas *").css({"font-family" : "Tahoma", "font-size" : "10px"});
    }
  */
  
  if($.browser.ie) {
    var totalFiles = jQuery("input[type=file]");
    
    for(i=0; i<totalFiles.length; i++) {
      jQuery(totalFiles[i]).attr("size", "27");
    }
  }
  
  if($.browser.chrome) {
    jQuery(".caixa input[type=text]").css("padding-top", "10px");
    jQuery(".formContactLateral .caixa input").css({"margin-top" : "3px", "padding-top" : "6px"})
  }
  
 }
 
 
 function animaFilosofia() {
    
    /* inicio */
    
    jQuery(".pontoA").attr("class", "pontoA_sel");
    var tbs = jQuery(".tbs_sel").children();
    jQuery(tbs[0]).addClass("sel");
    jQuery(".cnt", tbs[0]).show(300);
    
    /* click */
    
    jQuery(".pontoA").live("click", function (event){
    
      //alert(tbs[0]);
      
      event.stopImmediatePropagation(); 
      jQuery(".uniTab").attr("class", "uniTab");
      jQuery(tbs[0]).addClass("sel");
      jQuery(".pontoA").attr("class", "pontoA_sel");
      jQuery(".pontoB_sel").attr("class", "pontoB");
      jQuery(".pontoC_sel").attr("class", "pontoC");
      jQuery(".uniTab .cnt:visible").hide(300, function(){
        jQuery(".cnt", tbs[0]).show(300);
      });
    
    });
    
    
    jQuery("#ponto1 h3").live("click", function (event){
      event.stopImmediatePropagation(); 
      if(jQuery(this).parent().attr("class") != "uniTab sel" && jQuery(this).parent().attr("class") != "sel uniTab"){
        jQuery(".uniTab").attr("class", "uniTab");
        jQuery(tbs[0]).addClass("sel");
        jQuery(".pontoA").attr("class", "pontoA_sel");
        jQuery(".pontoB_sel").attr("class", "pontoB");
        jQuery(".pontoC_sel").attr("class", "pontoC");
        jQuery(".uniTab .cnt:visible").hide(300, function(){
          jQuery(".cnt", tbs[0]).show(300);
        });
      }
    
    });
    
    jQuery(".pontoB").live("click", function (event){
      event.stopImmediatePropagation(); 
      jQuery(".uniTab").attr("class", "uniTab");
      jQuery(tbs[1]).addClass("sel");
      jQuery(".pontoA_sel").attr("class", "pontoA");
      jQuery(".pontoC_sel").attr("class", "pontoC");
      jQuery(".pontoB").attr("class", "pontoB_sel");
      jQuery(".uniTab .cnt:visible").hide(300, function(){
        jQuery(".cnt", tbs[1]).show(300);
      });
    });
    
     jQuery("#ponto2 h3").live("click", function (event){
      event.stopImmediatePropagation(); 
      if(jQuery(this).parent().attr("class") != "uniTab sel" && jQuery(this).parent().attr("class") != "sel uniTab"){
        jQuery(".uniTab").attr("class", "uniTab");
        jQuery(tbs[1]).addClass("sel");
        jQuery(".pontoA_sel").attr("class", "pontoA");
        jQuery(".pontoC_sel").attr("class", "pontoC");
        jQuery(".pontoB").attr("class", "pontoB_sel");
        jQuery(".uniTab .cnt:visible").hide(300, function(){
          jQuery(".cnt", tbs[1]).show(300);
        });
      }
    });
    jQuery(".pontoC").live("click", function (event){
      event.stopImmediatePropagation(); 
      jQuery(".uniTab").attr("class", "uniTab");
      jQuery(tbs[2]).addClass("sel");
      jQuery(".pontoA_sel").attr("class", "pontoA");
      jQuery(".pontoB_sel").attr("class", "pontoB");
      jQuery(".pontoC").attr("class", "pontoC_sel");
      jQuery(".uniTab .cnt:visible").hide(300, function(){
        jQuery(".cnt", tbs[2]).show(300);
      });
    });
    
    jQuery(".roda_pt .total").live("click", function (event){
      event.stopImmediatePropagation(); 
      if(jQuery(tbs).length > 3) {
        jQuery(".uniTab").attr("class", "uniTab");
        jQuery(tbs[3]).addClass("sel");
        jQuery(".pontoA_sel").attr("class", "pontoA");
        jQuery(".pontoB_sel").attr("class", "pontoB");
        jQuery(".pontoC").attr("class", "pontoC");
        jQuery(".uniTab .cnt:visible").hide(300, function(){
          jQuery(".cnt", tbs[3]).show(300);
        });
      }
    });
    
     jQuery("#ponto3 h3").live("click", function (event){
      event.stopImmediatePropagation(); 
      if(jQuery(this).parent().attr("class") != "uniTab sel" && jQuery(this).parent().attr("class") != "sel uniTab"){
        jQuery(".uniTab").attr("class", "uniTab");
        jQuery(tbs[2]).addClass("sel");
        jQuery(".pontoA_sel").attr("class", "pontoA");
        jQuery(".pontoB_sel").attr("class", "pontoB");
        jQuery(".pontoC").attr("class", "pontoC_sel");
        jQuery(".uniTab .cnt:visible").hide(300, function(){
          jQuery(".cnt", tbs[2]).show(300);
        });
      }
    });
    
     
    
      jQuery("#ponto4 h3").live("click", function (event){
      event.stopImmediatePropagation(); 
      if(jQuery(this).parent().attr("class") != "uniTab sel" && jQuery(this).parent().attr("class") != "sel uniTab"){
        jQuery(".uniTab").attr("class", "uniTab");
        jQuery(tbs[3]).addClass("sel");
        jQuery(".pontoA_sel").attr("class", "pontoA");
        jQuery(".pontoB_sel").attr("class", "pontoB");
        jQuery(".pontoC").attr("class", "pontoC");
        jQuery(".uniTab .cnt:visible").hide(300, function(){
          jQuery(".cnt", tbs[3]).show(300);
        });
      }
    });
    
    var menusFilosofia = jQuery(".menuFilosofia").children();
    var cntLeft = jQuery(".leftFilosofia").children("div");
    var titulos = jQuery(".titFilosofia");
        
    jQuery(".menuFilosofia div").live("click", function(){
      
      classDiv = jQuery(this).attr("class");
      relDiv = jQuery(this).attr("rel");
      
      if(classDiv == "") {
        
        jQuery(".uniTab .cnt:visible").hide(300);
        jQuery(".uniTab").attr("class", "uniTab");
        jQuery(".tbs_sel").attr("class", "tbs");
        jQuery(menusFilosofia).attr("class", "");
        jQuery(cntLeft).css("display", "none");
        jQuery(titulos).css("display", "none");
        
        jQuery(menusFilosofia[relDiv]).attr("class", "sel");
        jQuery(cntLeft[relDiv]).css("display", "block");
        jQuery(titulos[relDiv]).css("display", "block");
        
        jQuery(".pontoA_sel").attr("class", "pontoA");
        jQuery(".pontoC_sel").attr("class", "pontoC");
        jQuery(".pontoB_sel").attr("class", "pontoB");
        jQuery(".pontoA").attr("class", "pontoA_sel");
        
        jQuery(".tbs", cntLeft[relDiv]).attr("class", "tbs_sel");
        tbs = jQuery(".tbs_sel").children();
        jQuery(tbs[0]).addClass("sel");
        jQuery(".cnt", tbs[0]).show(300);
        
      }
      
      
      
    });
    
 }
 
 var conta = 0;
 function jqGalery() {
    
    var titulos = jQuery(".subtitulo");
    var imagens = jQuery(".galeriaNewsletter").children();
    var titulo = jQuery(".paginacaoGaleria p");
    
    var limit = jQuery(".subtitulo").length;
    
    
    jQuery(".next").click(function(){
      if(conta < limit - 1) {
        conta++;
       
        
       
        
        jQuery(imagens[conta]).fadeIn(300, function(){
        
         mes = jQuery("span", titulos[conta]).text();
        jQuery(titulo).html(mes);
        
        jQuery(titulos).css("display", "none");
        jQuery(titulos[conta]).css("display", "block");
        
        jQuery(imagens).css("z-index", "0", function(){
          jQuery(imagens[conta]).css("z-index", "10");
        });
        
          jQuery(imagens).css("display", "none");
          jQuery(imagens[conta]).css("display", "block");
          jQuery(imagens).removeClass("newsel");
          jQuery(imagens[conta]).addClass("newsel");
          jQuery(".galeriaNewsletter").height(jQuery(".newsel").height());
        });
        
         //alert(conta);
      
        if(conta == (limit-1))
          jQuery(".next").css('visibility','hidden');
         if(conta <= (limit-1))
          jQuery(".prev").css('visibility','visible');     
      }
    });
    
    
    jQuery(".prev").click(function(){
      if(conta > 0) {
        conta--;
        
       
        jQuery(imagens[conta]).fadeIn(300, function(){
          
        
          mes = jQuery("span", titulos[conta]).text();
          jQuery(titulo).html(mes);
          
          jQuery(titulos).css("display", "none");
          jQuery(titulos[conta]).css("display", "block");
          
          jQuery(imagens).css("z-index", "0");
          jQuery(imagens[conta]).css("z-index", "10");
        
          jQuery(imagens).css("display", "none");
          jQuery(imagens[conta]).css("display", "block");
          jQuery(imagens).removeClass("newsel");
          jQuery(imagens[conta]).addClass("newsel");
          jQuery(".galeriaNewsletter").height(jQuery(".newsel").height());
        });
      }
      
       if(conta < (limit-1))
          jQuery(".next").css('visibility','visible');
       if(conta == 0)
          jQuery(".prev").css('visibility','hidden');   
      
    });
    
   
    
 }
 
 var interval = 0;
 var contaSlider = 0;
 var imagens = 0;
 
 function retornaClientes() {
    
    imagens = jQuery(".img center").children("img");
    jQuery(imagens[0]).css("display", "block");
    
    interval = setInterval(funcInterval, 3500);
    
 }
 
 function funcInterval() {
    contaSlider++;
    if(contaSlider == imagens.length) {
      contaSlider = 0;
    }
    
    jQuery(imagens).css("display", "none");
    jQuery(imagens[contaSlider]).css("display", "block");
  
 }
 
function verifica_pesq(formID){

  var form = document.getElementById(formID);
  var txt = form.pesq;
  var texto = txt.value;
  var error;
  
  
  
  if((txt.value=="") ){
      alert(unescape(json[15]));
      error=1;
  }else if(txt.value!="" &&  texto.length<3){
      alert(unescape(json[16]));
      error=2;
      //return false;
  }

  if((txt.value!="") && (texto.length>=3)){
     error=0;
     //document.getElementById(form).submit();
  }
  
  if(error>0){
    return false;
  }else {
    return document.getElementById(formID).submit();
  }
}
 
function enviaContacto(teste){
 
 var nome = $('#nome').val();
 var tipocontacto = $('#tipocontacto').val();
 var contacto = $('#contacto').val();
 var telefone = $('#tels').attr('checked');
 var email = $('#emails').attr('checked');
 
 
 if(nome == ""){
    alert(unescape(json[50]));
    return false;
 }else if( (contacto == "" || verify_number (parseInt(contacto)) == false ) && telefone == true ){
    alert(unescape(json[51]));
    return false;   
 }else if((contacto == "" || verify_email(contacto) == false ) && email == true ){
    alert(unescape(json[52]));
    return false;   
 }

 
 
 $('.bt_pedido input').attr('disabled',true);
  
  $.ajax({
      url: 'ajax_contacto.php',
      type: 'POST',
      data:$('#form_contacto').serializeArray(),
      success: function(data) {
        
          $('.formContactLateral').html("<div style='margin-top:5px;'><p>" + unescape(json[54]) + "</p></div>");
          //$('.bloqueado').hide();
           
      }
  });
  
  $('.bt_pedido input').attr('disabled',false);
  
  return false;
 
}




function verify_number(value){
  if (isNaN(value)) 
  {
    return false;
  }else {
    return true;
  }
}

function verify_email(_mail){
		
	var status = false;     
	var emailRegEx = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;
	
	if (_mail.search(emailRegEx) == -1) {
		status = false;
	} else {
		status = true;
	}
	     
	return status;

}
function addFav(){
    var url      = slocation;
    var title    = "QIS";
    if (window.sidebar) window.sidebar.addPanel(title, url,"");
    else if(window.opera && window.print){
        var mbm = document.createElement('a');
        mbm.setAttribute('rel','sidebar');
        mbm.setAttribute('href',url);
        mbm.setAttribute('title',title);
        mbm.click();
    }
    else if(document.all){window.external.AddFavorite(url, title);}
}

function bugsIE7() {
  
  jQuery(".uni_servico").mouseenter(function(){
    jQuery(this).css({
      "text-decoration" : "none",
      "border" : "1px solid #96B6BE",
      "width" : "168px",
      "background-position" : "-174px -1px"
    });
    jQuery("h4", this).css({"margin" : "23px 0 0 6px"});
    jQuery(".img", this).css({
      "top" : "19px",
      "right" : "7px"
    });
    jQuery(".imagem", this).css("padding", "7px 0 13px 7px");
    jQuery("p", this).css({
       "color" : "#0479A5",
       "line-height" : "18px",
       "margin-left" : "8px"
    });
  }).mouseleave(function(){
    jQuery(this).css({
      "text-decoration" : "none",
      "border" : "0px solid",
      "width" : "170px",
      "background-position" : "left top"
    });
    jQuery("h4", this).css({"margin" : "24px 0 0 7px"});
    jQuery(".img", this).css({
      "top" : "20px",
      "right" : "8px"
    });
    jQuery(".imagem", this).css("padding", "7px 0 13px 8px");
    jQuery("p", this).css({
       "color" : "#0479A5",
       "line-height" : "18px",
       "margin-left" : "9px"
    });
  });
  
}



function voltar(){
  
  alert(history.length);
   history.back(-1);
  if(history.length==0){
    window.location = slocation + "/index.php?id=64";
    
  }else {
    history.back(-1);
  }
  
  //return false;
   
}











