// JavaScript Document
function bartenderTimed() {
  $activeb = $('#divimgsbartender img.active').next();
  if ( $activeb.length == 0 ) $activeb = $('#divimgsbartender img:first');
  $activeb.trigger("rodabartender");
}
function rodaNovidades() {
	var id = $(".news0 li").siblings(':visible');
	var pag = $(".paginacao a").siblings('.ativo');
	$(pag).removeAttr('class').next().addClass('ativo');
	$(id).fadeOut(300).next().fadeIn(800);
	if(id.index()+1 == $(".news0 li").length){$(".news0 li:first").fadeIn(800);$(".paginacao a:first").addClass('ativo');}
}
(function($){ 
  $(function(){ 
     $('input:text').setMask(); 
  } 
); 
})(jQuery); 
$(document).ready(function() {
	var regmail = /^[\w!#$%&amp;'*+\/=?^`{|}~-]+(\.[\w!#$%&amp;'*+\/=?^`{|}~-]+)*@(([\w-]+\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;

	//EVENTOS
    $('.btnProx').click( function() {
       $fotoativa = $('#fotoseventos ul li.active').next();
       if ( $fotoativa.length == 0 ) $fotoativa = $('#fotoseventos ul li:first');
       $('#fotoseventos ul li').removeClass('active');
       $('#fotoseventos ul li').hide();
       $fotoativa.addClass('active');
       $fotoativa.fadeIn();
	});

    $('.btnAnt').click( function() {
       $fotoativa = $('#fotoseventos ul li.active').prev();
       if ( $fotoativa.length == 0 ) $fotoativa = $('#fotoseventos ul li:last-child');
       $('#fotoseventos ul li').removeClass('active');
       $('#fotoseventos ul li').hide();
       $fotoativa.addClass('active');
       $fotoativa.fadeIn();
	});	
	
	//NOVIDADES
	var time = 8000;
	$(".news0 li:not(:first)").hide();
	
	$("a[tarja='clique']").click( function() {
		var id = $(".news0 li").siblings(':visible');
		var pag = $(".paginacao a").siblings('.ativo');
		$(pag).removeAttr('class');
		$(this).addClass('ativo');
		$(id).fadeOut(300);
		$("li#"+$(this).attr("chama")).fadeIn(800);
		clearInterval(playNovidades);
	});
	
	playNovidades = setInterval( "rodaNovidades()", 8000 );
	
	// Bartenders
	$('#divimgsbartender img').bind("rodabartender", function(){ 
      $('#nomebartender').empty().html($(this).attr("nome"));  
      $('#fotobartender').hide().attr("src", $(this).attr("src")).fadeIn();  
      $("#divimgsbartender img").removeClass('active');
      $(this).addClass('active');
    });
	playBartender = setInterval( "bartenderTimed()", 3000 );
	
    if ($.browser.msie) {
  	   $('#eventoselect').change(function(){
		    $('#fotoseventos').empty().html('<div align=center><br><br><b>Aguarde...<br>Carregando...</b></div>');
			$.post('fotosgaleria.php',
			{ grupo : $("#eventoselect option:selected").attr("value")},
				function(resposta){	 
					$('#fotoseventos').empty().html(resposta);
					$(".evento li:not(:first)").hide();
				}
			);			
  	   });    
  	   $('#selectbartender').change(function(){
  	      $('#nomebartender').empty().html($("#selectbartender option:selected").attr("value"));  
  	      $('#fotobartender').hide().attr("src", $("#selectbartender option:selected").attr("foto")).fadeIn();  
  	      clearInterval(playBartender);
  	   });
  	   $('#videoselectf').change(function(){
		    $('#ondemostravideo').empty().html('<div align=center><br><br><b>Aguarde...<br>Carregando...</b></div>');
			$.ajax({
				type: "POST",
				url: "videosgaleria.php",
				cache: false,
				async: false,
				dataType: 'html',
				data: "video="+$("#videoselectf option:selected").attr("value"),
				success: function(msg){
				    dividemsg = msg.split("|");
					$('#ondemostravideo').empty().html(dividemsg[0]);
					$('#descricaovideo').empty().html(dividemsg[1]);
				}
			});
  	   });
	}

    if ($.browser.mozilla) {
		$('#eventoselect option').click(function(){
		    $('#fotoseventos').empty().html('<div align=center><br><br><b>Aguarde...<br>Carregando...</b></div>');
			$.post('fotosgaleria.php',
			{ grupo : $(this).attr("value")},
				function(resposta){	 
					$('#fotoseventos').empty().html(resposta);
					$(".evento li:not(:first)").hide();					
				}
			);			
  	    });    
  	   $('#selectbartender option').click(function(){
  	      $('#nomebartender').empty().html($(this).attr("value"));  
  	      $('#fotobartender').hide().attr("src", $(this).attr("foto")).fadeIn();  
  	      clearInterval(playBartender);
  	   });
  	   $('#videoselectf option').click(function(){
		    $('#ondemostravideo').empty().html('<div align=center><br><br><b>Aguarde...<br>Carregando...</b></div>');
			$.ajax({
				type: "POST",
				url: "videosgaleria.php",
				cache: false,
				async: false,
				dataType: 'html',
				data: "video="+$(this).attr("value"),
				success: function(msg){
				    dividemsg = msg.split("|");
					$('#ondemostravideo').empty().html(dividemsg[0]);
					$('#descricaovideo').empty().html(dividemsg[1]);
				}
			});
  	   });
	}
  $("form#formorca").submit(function() {
      $('#erroorca').empty().hide().html("<font color='#A80004'><b>AGUARDE... ENVIANDO...</b><br></font>").show("fast");
      if( regmail.test($(':input[name="orcaemail"]').val()) && $(':input[name="orcanome"]').val() != "" && $(':input[name="orcadataevento"]').val() != "" && $(':input[name="orcatelefone"]').val() != "" && $(':input[name="orcacidadeuf"]').val() != "" && $(':input[name="orcabairro"]').val() != "" && $(':input[name="orcatotalconvidados"]').val() != "" && $(':input[name="orcacomentarios"]').val() != "") {
 		$.ajax({
			type: "POST",
			url: "enviamailorca.php",
			cache: false,
			async: false,
			dataType: 'html',
			data: $('form#formorca').serialize(), 
			success: function(msg){
			    $('#erroorca').empty();
				$('.orcamento').empty().html("<h2>Fa&ccedil;a um Or&ccedil;amento</h2><br><div id='erroorca' style='display:block;margin:35px 0px 0px 20px;'></div>" + msg);
			}
		});
	  } else {
	     $('#erroorca').empty().hide().html("<br><font color='#FFCECE'><b>Por favor, preencha todos os campos marcados com * ...</b><br></font>").show("medium");
	  }
	return false;
  });


  $("form#formdepoimento").submit(function() {
      $('#errodepo').empty().hide().html("<font color='#A80004'><b>AGUARDE... ENVIANDO...</b><br></font>").show("fast");
      if( regmail.test($(':input[name="depoemail"]').val()) && $(':input[name="deponome"]').val() != "" && $(':input[name="depoevento"]').val() != "" && $(':input[name="depocomentario"]').val() != "") {
 		$.ajax({
			type: "POST",
			url: "enviadepoimento.php",
			cache: false,
			async: false,
			dataType: 'html',
			data: $('form#formdepoimento').serialize(), 
			success: function(msg){
			    $('#errodepo').empty();
				$('#divdepo').empty().html("<h2>Fa&ccedil;a um Depoimento</h2><br><div id='errodepo' style='display:block;margin:15px 0px 0px 20px;'></div>" + msg);
			}
		});
	  } else {
	     $('#errodepo').empty().hide().html("<br><font color='#FFCECE'><b>Por favor, preencha todos os campos marcados com * ...</b><br></font>").show("medium");
	  }
	return false;
  });

});

