

jQuery(window).load(function(){
  
  
  jQuery("#mn_loja").live("mouseover",function(){
       jQuery(".popuploja").show();
  });
  
  jQuery("#mn_loja").live("mouseout",function(){
       jQuery(".popuploja").hide();
  });
  
  jQuery('._black').click(function(){
    jQuery('._black').css("display","none");
    jQuery('._popDetalhe').css("display","none");
  });
  
  
  jQuery(".wraper_label label").click(function(){
      
      var lbl = jQuery(this).attr('id');
      
      lbl.split("lbl_");
      
      jQuery("#" + lbl[1]).focus();
      
      if(jQuery("#" + lbl[1]).attr('value') == ""){
        jQuery(this).hide(0);
      }
  });
  
  
  jQuery(".wraper_label input").blur(function(){
      var id = jQuery(this).attr('id');      
  
      if(jQuery(this).attr('value') == "")
        jQuery("#lbl_" + id).show(0);
  })
  
  jQuery(".wraper_label input").focus(function(){
      var id = jQuery(this).attr('id');      
      
      
      jQuery("#lbl_" + id).hide(0);
      
      
  })
  

  jQuery(".span5",  jQuery('.menu_lateral2 a.sel').prev()).css('display','none')


  jQuery(".span5",  jQuery('.menu_lateral a.sel').next()).css('display','none')


  jQuery(".span5",  jQuery('.menu_lateral3 a.sel').prev()).css('display','none')
   jQuery(".menu_principal",  jQuery('a.sel').prev()).css('display','none')

jQuery('.newsletter input[type="text"]').focusin(function(){
	console.log('teste');
    if(jQuery(this).val() != ""){
      jQuery(this).val('')
    }
  }).focusout(function(){
    if(jQuery(this).val() == ""){
      jQuery(this).val('Insira aqui o seu e-mail')
    }
  });
  jQuery('.pesq input[type="text"]').focusin(function(){
	console.log('teste');
    if(jQuery(this).val() != ""){
      jQuery(this).val('')
    }
  }).focusout(function(){
    if(jQuery(this).val() == ""){
      jQuery(this).val('Pesquisa')
    }
  });
  jQuery('.menu_log input[type="text"]').focusin(function(){
	console.log('teste');
    if(jQuery(this).val() != ""){
      jQuery(this).val('')
    }
  }).focusout(function(){
    if(jQuery(this).val() == ""){
      jQuery(this).val('')
    }
  });
    slideShowHome();

  fakeselect();

  });


function fakeselect()
{
jQuery('.fakeSelect span.selectValue').each(function(){
jQuery(this).text(jQuery('option:selected', jQuery(this).parent()).text());
});

jQuery('.fakeSelect select').change(function(){
jQuery('span.selectValue', jQuery(this).parents('.fakeSelect')).text(jQuery('option:selected', this).text());
});
 } 
  /*** SLIDER HOME ****/


var tmpInterval = 55;
var intervalo = 0;
var intervalo2 = 0;
var widthTotal = 0;
var imgSel = 0;
var imagens = 0;
var imgNow = 0;

function slideShowHome() {
   imagens = jQuery(".imagens_home").children();
   intervalo = setInterval(progressBar, tmpInterval);
   
   
   jQuery(".bt1").click(function(){
    clearInterval(intervalo);
    clearTimeout(intervalo2);
    widthTotal = 22;
    jQuery(".barra_cinza").animate({ width: widthTotal + 1}, 300);
    trocaImagemClick(0);
    imgSel = 0;
    intervalo2 = setTimeout(tempoEspera, 7000);
   });
   
   
   jQuery(".bt2").click(function(){
    clearInterval(intervalo);
    clearTimeout(intervalo2);
    widthTotal = 48;
    jQuery(".barra_cinza").animate({ width: widthTotal + 1}, 300);
    trocaImagemClick(1);
    imgSel = 1;
    intervalo2 = setTimeout(tempoEspera, 7000);
   });
   
   jQuery(".bt3").click(function(){
    clearInterval(intervalo);
    clearTimeout(intervalo2);
    widthTotal = 73;
    jQuery(".barra_cinza").animate({ width: widthTotal + 1}, 300);
    trocaImagemClick(2);
    imgSel = 2;
    intervalo2 = setTimeout(tempoEspera, 7000);
   });

   
}

function tempoEspera() {
  clearTimeout(intervalo2);
  intervalo = setInterval(progressBar, tmpInterval);
}


function trocaImagem(imgSel) {

  clearInterval(intervalo);
  
  /*
  if(imgSel == 3) {
    imgSel = 0;
	imgNow = 2;
  } else {
    imgNow = (imgSel - 1);
  }
  */
  if(widthTotal == 73) {
	widthTotal = 0;
  } 

  jQuery(imagens).css("z-index", "0");
  jQuery(imagens[imgSel]).css("z-index", "10");
  
 // alert("imgSel :: " + imgSel + " imgNow :: " + imgNow);
  
  jQuery(imagens[imgSel]).stop().fadeIn(800, function(){
   jQuery(imagens[imgNow]).css("display", "none");
   intervalo2 = setTimeout(tempoEspera, 7000);
  });
  
}


function trocaImagemClick(imgSel) {
    if(widthTotal == 73) {
	widthTotal = 0;
  } 
  jQuery(imagens).css("z-index", "0");
  jQuery(imagens[imgSel]).css("z-index", "10");
  
  jQuery(imagens[imgSel]).stop().fadeIn(800, function(){
    jQuery(imagens).css("display", "none");
    jQuery(imagens[imgSel]).css("display", "block");
  });
  
}

function progressBar() {
  widthTotal++;
  
  jQuery(".barra_cinza").css("width", widthTotal);

  if(widthTotal == 22) {
    imgSel = 0;
	imgNow = 2;
    trocaImagem(imgSel);
  }
  
  else if(widthTotal == 48) {
    imgSel = 1;
	imgNow = 0;
    trocaImagem(imgSel);
  }
  
  else if(widthTotal == 73) {
    imgSel = 2;
	imgNow = 1;
    trocaImagem(imgSel);
  }
  

  
}

/*** SLIDER HOME ****/
function updateBox(comando,box,price,cls){
  var _box = document.getElementById(box);
  
  
  if(comando == "")
  {
    if(_box.value>0){
      document.getElementById(cls).innerHTML = parseFloat(price)*_box.value + ",00 €";
    } else {
      alert("Quantidade não permitida.");
    }
  }
  if(comando == "plus")
  {
    if(price!="")
    {
      _box.value = (_box.value*1) + (1)*1;
       if(document.getElementById(cls)){
          var total =  price * _box.value;
          document.getElementById(cls).innerHTML = parseFloat(price)*_box.value + ",00 €";
       }
    }
    
  }
  
  if(comando == "less")
  {
    if(_box.value>1){
      _box.value = _box.value - 1;
        if(document.getElementById(cls)){
          document.getElementById(cls).innerHTML = parseFloat(price)*_box.value + ",00 €";
        }
    } else {
      alert("Quantidade não permitida.");
    }
  }
}
function addCart(){
  var _black = document.getElementById("black_screen");
  var _carrinho = document.getElementById("cart_adic");
  var altura = jQuery(document).height();
  var janela = jQuery(window).height();
  
  var conta = (janela /2) - 130;
  _black.style.height = altura + "px";
  _black.style.display = "block";
  _carrinho.style.marginTop = conta + "px";
  _carrinho.style.display = "block";
}
function closePopCart(){
  var _black = document.getElementById("black_screen");
  var _carrinho = document.getElementById("cart_adic");
  
  _carrinho.style.display = "none";
  _black.style.display = "none";
}
function openTabsForm(id_tr){
  
  var display = jQuery('#tr_'+id_tr+'').css('display');
  
  jQuery('.hidden_tr').css("display","none");  
  
  
  if(display == "none")
    jQuery('#tr_'+id_tr+'').show(300);
  else  
    jQuery('#tr_'+id_tr+'').css("display","none");
  
  
}
function showPopUp(este){
  var id_j = jQuery(este).attr('idpage');
  
  var altura = jQuery(document).height();
  var largura = jQuery(window).width();
  
  var janela = jQuery(window).height();
  var janela_larg = jQuery(window).width();
  
  //var conta = (janela /2) - 130;
  jQuery('._black').css("width",largura);
  jQuery('._black').css("height",altura);
  
  
  jQuery('._popDetalhe').css("top",(janela/2)-130);
  jQuery('._popDetalhe').css("left",(janela_larg/2)-220);
  
  
  
  var params = {id:id_j};
  var str = jQuery.param(params);
  
  jQuery.ajax({
    type: "GET",
    url: "ajax_detalhe.php",
    data:str,
    success: function(data) {
      jQuery('._popDetalhe').html(data);
      jQuery('._black').css("display","block");
      jQuery('._popDetalhe').css("display","block");
          
    }
  });
  
  return false;
}


