function verificaBrowser(){
  var versao = window.navigator.userAgent;
  // CHECA O NAVEGADOR
  if(versao.indexOf("MSIE")!= -1){
//    window.alert("Internet Explorer");
    var browser = "MSIE";
  }else if(versao.indexOf("Firefox")!= -1){
//    window.alert("Mozzila Firefox");
    var browser = "Firefox";
  }else if(versao.indexOf("Chrome")!= -1){
//    window.alert("Google Chrome");
    var browser = "Chrome";
  }else if(versao.indexOf("Safari")!= -1){
    if(versao.indexOf("Chrome")!= -1){
    }else{
//      window.alert("Apple Safari");
      var browser = "Safari";
    }
  }
  return browser;
}

function larguraBrowser(){
     return window.innerWidth ? window.innerWidth : /* For non-IE */
            document.documentElement ? document.documentElement.clientWidth : /* IE 6+ (Standards Compilant Mode) */
            document.body ? document.body.clientWidth : /* IE 4 Compatible */
            window.screen.width; /* Others (It is not browser window size, but screen size) */
}

function alturaBrowser(){
     return window.innerHeight ? window.innerHeight : /* For non-IE */
            document.documentElement ? document.documentElement.clientHeight : /* IE 6+ (Standards Compilant Mode) */
            document.body ? document.body.clientHeight : /* IE 4 Compatible */
            window.screen.height; /* Others (It is not browser window size, but screen size) */
}

function verificaTamanhoJanela(){
  largura = larguraBrowser().toString();
  altura = alturaBrowser().toString();

  var tamanho = new Array(2);
  tamanho[0] = largura;
  tamanho[1] = altura;
  
  return tamanho;
}

function ajustaCamada(camada,posx,posy,sinal_top,top,sinal_left,left){
  var obj = document.getElementById(camada);

  if(sinal_top == '+'){
    obj.style.top   = posy + top + 'px';
  }else if(sinal_top == '-'){
    obj.style.top   = posy - top + 'px';
  }
  if(sinal_left == '+'){
    obj.style.left  = posx + left + 'px';
  }else if(sinal_left == '-'){
    obj.style.left  = posx - left + 'px';
  }
}

function pegarPosicaoX(objeto){
  var atual_left = 0;
  if (objeto.offsetParent) {
    while (objeto.offsetParent) {
      atual_left += objeto.offsetLeft
      objeto = objeto.offsetParent;
    }
  }
  return atual_left;
}

function pegarPosicaoY(objeto){
  var atual_top = 0;
  if (objeto.offsetParent) {
    while (objeto.offsetParent) {
      atual_top += objeto.offsetTop
      objeto = objeto.offsetParent;
    }
  }
  return atual_top;
}

function visibilidade(camada,acao){
  document.getElementById(camada).style.visibility = acao;
}

/*Verifica se o email é um email válido*/
function verificaEmail(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{
      return false;
    }
  }else if(typeof(mail) == "object"){
    if(er.test(mail.value)){
      return true;
    }
  }else{
    return false;
  }
}

function iniciaGaleriaInicial(total_fotos,foto_proxima,atual_foto){
  var _global = this;
  if(foto_proxima && atual_foto){
    var foto_atual = 'destaque_galeria_' + atual_foto;
    var proxima_foto = 'destaque_galeria_' + foto_proxima;
    document.getElementById(foto_atual).style.visibility = 'hidden';
    document.getElementById(foto_atual).style.zIndex = 1;
    document.getElementById(proxima_foto).style.visibility = 'visible';
    document.getElementById(proxima_foto).style.zIndex = 10;
    clearInterval(_global.atualizaGaleria);
    _global.atualizaGaleria = setInterval(function(){
      loopingGaleriaInicial(total_fotos,foto_proxima,1);
    }, 8000);
  }else{
    document.getElementById('destaque_galeria_1').style.zIndex = 10;
    for(i=2;i<=total_fotos;i++){
      var camada_galeria_inicial = 'destaque_galeria_' + i;
      document.getElementById(camada_galeria_inicial).style.visibility = 'hidden';
    }
    document.getElementById('destaque_visivel').value = 1;
    _global.atualizaGaleria = setInterval(function(){
      loopingGaleriaInicial(total_fotos);
    }, 8000);
  }
}

function loopingGaleriaInicial(total_fotos,foto,ativo){
  var _global = this;

  if(ativo == 1){
    clearInterval(_global.atualizaGaleria);
    _global.atualizaGaleria = setInterval(function(){
      loopingGaleriaInicial(total_fotos);
    }, 8000);
  }

  if(foto){
    var foto_visivel = foto;
  }else{
    var foto_visivel = document.getElementById('destaque_visivel').value;
  }
  var foto_atual = 'destaque_galeria_' + foto_visivel;
  if(foto_visivel == total_fotos){
    var foto_seguinte = 1;
  }else{
    var foto_seguinte = parseInt(parseInt(foto_visivel)+1);
  }
  var proxima_foto = 'destaque_galeria_' + foto_seguinte;

  document.getElementById(foto_atual).style.visibility = 'hidden';
  document.getElementById(foto_atual).style.zIndex = 1;
  document.getElementById(proxima_foto).style.visibility = 'visible';
  document.getElementById(proxima_foto).style.zIndex = 10;
  if(foto_seguinte > total_fotos){
    document.getElementById('destaque_visivel').value = 1;
  }else{
    document.getElementById('destaque_visivel').value = foto_seguinte;
  }
}

function exibePopUp(largura,altura,timer){
  margem_superior = (-1) * parseInt(altura/2) + 'px';
  margem_esquerda = (-1) * parseInt(largura/2) + 'px';

  document.getElementById('popup').style.marginTop = margem_superior;
  document.getElementById('popup').style.marginLeft = margem_esquerda;
  
  mostraPopup();
  
  var timer_popup = parseInt(timer) * 1000;
  var esconde = setInterval(function(){
    escondePopup();
  }, timer_popup);
}

function mostraPopup(){
  document.getElementById('popup').style.visibility = 'visible';
}

function escondePopup(){
  document.getElementById('popup').style.visibility = 'hidden';
}

