// JavaScript Document
  function validar(){
	  // validate signup form on keyup and submit
	  $("#form_contato").validate({
		  rules:{
			  nome:{required: true, minlength: 2},
			  email:{required: true, email: true},
			  mensagem:{required: true, minlength: 10}
		  },
		  
		  messages:{
			  nome:{
				  required: "Digite o seu nome",
				  minlength: "O seu nome deve conter, no mínimo, 2 caracteres"
			  },
			  email:{
				  required: "Digite o seu e-mail para contato",
				  email: "Digite um e-mail válido"
			  },
			  mensagem:{
				  required: "Digite a sua mensagem",
				  minlength: "A sua mensagem deve conter, no mínimo, 10 caracteres"
			  }
		  }
	  });
  };
$(function() {
	
	$('.close').live('click',function(){		
		$('#overlay').slideUp('slow');		
		$($(this).parent()).slideUp();
		
	});
	$('.contato').click(function(){
		$('#overlay').slideDown('slow');
		$('#contato').slideDown();
		validar();
		// Crio uma variável chamada $forms que pega o valor da tag form
		$('#contato_form').bind('submit', function(){
			validar();
			var $button = $('button',this).attr('disabled',true);
			var params = $(this.elements).serialize();
			var self = this;
			$.ajax({
				// Usando metodo Post
				type: 'POST',
				// this.action pega o script para onde vai ser enviado os dados
				url: this.action,
				// os dados que pegamos com a função serialize()
				data: params,
				// Antes de enviar
				beforeSend: function(){
					// mostro a div loading
					$('#loading').show();
					$('#contato_form').hide();
					$('#loading').html('Enviando...');
				},
				success: function(txt){
					// Ativo o botão usando a função attr()
					$button.attr('disabled',false);
				   // Escrevo a mensagem
					$('#loading').show();
					$('#loading').html(txt);
					$('#contato_form').hide();
					// Limpo o formulário
					self.reset();
				},
	
				// Se acontecer algum erro é executada essa função
				error: function(txt){
					$('#loading').html(txt);
				}
			})
			return false;
		});
	});
	$('.youtube').live('click',function() {
		$('#overlay').slideDown('slow');
		$('#youtube').slideDown();
		
		var youtube = "<div class='close'>Fechar</div><h3>" + $(this).attr('title') + "</h3>";
		youtube +="<object width='640' height='505'><param name='movie' value='";
		youtube += $(this).attr('href') + "'></param><param name='allowFullScreen' value='true'></param><param name='allowscriptaccess' value='always'></param><embed src='";
		youtube += $(this).attr('href') + "' type='application/x-shockwave-flash' width='640' height='505'></embed></object>";
		
		$('#youtube').html(youtube);
	//
	});
	$('.txt').click(function(){
		$('#overlay').slideDown('slow');
		$('#dialog_box').slideDown();
		
		$('#dialog_box h3.title').text($(this).attr('title'));
		$('#dialog_box .content').html("carregando...");
		$('#dialog_box .content').load('liv/inc/text.php','p='+$(this).attr('href').split('#')[1],function() {});
	
	});
  });	
  $(document).ready(function () {
  	
	$("#loading").click(function(){
		$('#contato_form').show();
		$('#loading').hide();
	});
	
    
  });