//ABRE E FECHA DETALHES DO EVENTO
function abreDetalhe(codigo) {
  var nome = "#detalhe"+codigo;
  $(nome).show();
  var barra = "#mais-detalhes"+codigo;
  $(barra).hide();
}

function fechaDetalhe(codigo) {
  var nome = "#detalhe"+codigo;
  $(nome).hide();
  var barra = "#mais-detalhes"+codigo;
  $(barra).show();
}


$(function() {

  //LIGHTBOX 
  $('.f').lightBox();
  $('.re-imagem').lightBox();

  //TROCA BANNER-GRANDE
  $('#banner-grande').show();
  $('#banner-grande').cycle({
    fx:'fade',
    timeout:12000,
    speed:1000,
    pager:''
  });
  
  //TROCA BANNER-PEQUENO
  $('#banner-pequeno').show();
  $('#banner-pequeno').cycle({
    fx:'fade',
    timeout:10000,
    speed:1000,
    pager:''
  });
  
  //LISTA OCULTA1
  $(".lista-oculta1").hide();
  $(".select-em-lista1").click(function(){
    
    if ($(".lista-oculta1").css('display') == 'block'){
      $(".lista-oculta1").hide();
    }else{
      $(".lista-oculta1").show();
    }
  });
  
  $(".lista-oculta1 a").click(
    function () {
      $(".lista-oculta1").hide();
      $(".select-em-lista1").text($(this).text())
    }
  );
  
  $(".lista-oculta1").mouseleave(function(){
    $(this).hide();
  });
  
  //LISTA OCULTA2
  $(".lista-oculta2").hide();
  $(".select-em-lista2").click(function(){
    
    if ($(".lista-oculta2").css('display') == 'block'){
      $(".lista-oculta2").hide();
    }else{
      $(".lista-oculta2").show();
    }
  });
  
  $(".lista-oculta2 a").click(
    function () {
      $(".lista-oculta2").hide();
      $(".select-em-lista2").text($(this).text())
    }
  );
  
  $(".lista-oculta2").mouseleave(function(){
    $(this).hide();
  });

  //APAGA VALUE
  $("form input[type='text'], form textarea").focus( 
  function() {
    if ($(this).val()==$(this).attr("defaultValue")) {
     $(this).val('');
    }
  });
  
  $("form input[type='text'], form textarea").blur(
  function() {
    if ($(this).val()=='') {
     $(this).val($(this).attr("defaultValue"));
    }
  });
  
  //ABRE FORMULARIO PARA RECEBER EMAIL
  $("#principal #topo-formularios #tf-receber-email").click (
    function () {
      if ($("#principal #corpo-formularios form#cf-receber-email").css("display") == ("none")) {
        $("#principal #topo-formularios #tf-receber-email").css("text-decoration","underline"),
        $("#principal #corpo-formularios form#cf-receber-email").show(),
        $("#principal #topo-formularios #tf-cadastrar-evento").css("text-decoration","none"),
        $("#principal #corpo-formularios form#cf-cadastro-evento").hide()        
      }else{
        $("#principal #topo-formularios #tf-receber-email").css("text-decoration","none"),
        $("#principal #corpo-formularios form#cf-receber-email").hide()
      }
    }
  );
  
  //ABRE FORMULARIO PARA CADASTRAR EVENTO
  $("#principal #topo-formularios #tf-cadastrar-evento").click(
    function () {
      if ($("#principal #corpo-formularios form#cf-cadastro-evento").css("display") == ("none")) {
        $("#principal #topo-formularios #tf-cadastrar-evento").css("text-decoration","underline"),
        $("#principal #corpo-formularios form#cf-cadastro-evento").show(),
        $("#principal #topo-formularios #tf-receber-email").css("text-decoration","none"),
        $("#principal #corpo-formularios form#cf-receber-email").hide()
      }else{
        $("#principal #topo-formularios #tf-cadastrar-evento").css("text-decoration","none"),
        $("#principal #corpo-formularios form#cf-cadastro-evento").hide()
      }
    }
  ); 

  $("#corpo-dicas h3 a").toggle(
    function () {
        $(this).closest('#corpo-dicas h3').next("div.toda-dica").show();
    },
    function () {
        $(this).closest('#corpo-dicas h3').next("div.toda-dica").hide();
    }
  );

  $("#corpo-dicas h3:first").show();  
  $("#corpo-dicas h3 a:first").click();
    
  //ABRE DICAS
  $("#principal #topo-dicas h2 span b u").click(
    function() {
      $("#corpo-dicas h3").show();
    }
  );

  $("#principal #dicas .descricao p.des1 strong").click(
    function() {
      $(this).closest("p.des1").hide();
      $(this).closest(".descricao p").next("p.des2").show();
    }
  );
  
  $("#principal #dicas .descricao p.des2 strong").click(
    function() {
      $(this).closest("p.des2").hide();
      $(this).closest(".descricao p").prev("p.des1").show();
    }
  );  

  //VALIDACAO
  $('#cf-receber-email').validate({
  
      // define regras para os campos
      rules: {
          nome_receba: {
              required : true,
              minlength: 5
          },
          email_receba: {
              required: true,
              email   : true
          }     
      },
      // define messages para cada campo
      messages: {
          nome: null,
          email: null
      }
  });

  //VALIDACAO
  $('#cf-cadastro-evento').validate({
      // define regras para os campos
      rules: {
          TITULO: {
              required : true,
              minlength: 5
          },
          LOCAL: {
              required : true,
              minlength: 5
          },
          PROMOTOR: {
              required : true,
              minlength: 5
          },
          DESCRICAO: {
              required : true,
              minlength: 5
          },
          CONTATO: {
              required : true,
              minlength: 5
          },
          ivNome: {
              required : true,
              minlength: 5
          },
          ivContato: {
              required : true,
              minlength: 5
          },
          ivEmail: {
              required: true,
              email   : true
          }     
      },
      // define messages para cada campo
      messages: {
          nome: null,
          email: null
      }
  });
  
  //MASCARA PARA O FORMULARIO
  $("form .mascara-data").mask("99/99/9999");

});

/* EFEITO ROLAGEM -----------------------------------------*/
var rolagem;
function rolagemDireita() {
   var c = document.getElementById("rolagem");
   var maximo = c.scrollWidth;
   c.scrollLeft = c.scrollLeft + 10;
   if (c.scrollLeft >= maximo) {
     exit();
   }else{
     rolagem = setTimeout("rolagemDireita()",50);
   }  
}

function rolagemEsquerda() {
   var c = document.getElementById("rolagem");
   var maximo = c.scrollWidth;
   c.scrollLeft = c.scrollLeft - 10;
   if (c.scrollRight >= maximo) {
     exit();
   }else{
     rolagem = setTimeout("rolagemEsquerda()",50);
   }  
}  

function rolagemParar() {
 clearTimeout(rolagem);
}