// JavaScript Document
$(document).ready(function(){
	var t = $("#mail-popup-wrapper").height();
	//$("#mail-popup-wrapper").height(1);
	//Open mail popup
	$("#display-mail-popup").css({cursor:"pointer"});
	$("#display-mail-popup").click(function(event){
		$("#greyer").css({display: "block"});
		$("#greyer").css({opacity: 0});
		$("#greyer").animate({opacity: 0.5}, 500, function(){});
		
		$("#mail-popup-wrapper").slideDown("slow");
		
		restore_form = $("#mail-form");

	});
   
   // Close mail popup
	$(".close").click(function(event){
		//event.preventDefault();
		//$("#greyer").hide("slow");
		$("#greyer").css({opacity: 0.5});//To fix IE bug that resets opacity to 100% before animating
		$("#greyer").animate({opacity: 0}, 1500, function(){$(this).css({display:"none"});} );
		
		$("#mail-popup-wrapper").slideUp("slow", function(){
				
				// Check if a message sent element is present
				if ($(".sent-message").length > 0 ) {
					$(".sent-message").remove();
				}										  
			
			}
														  
		);
		
	});
	
	// Send mail
	$("#mail-form").submit(function(){
  		return false;
	 });
	$("#send-mail").click(function(event){
		
		var emailToVal = "ep.ferreira@gmail.com"
		var nome_val = $("#nome").val();
		var correio_resposta_val = $("#correio_resposta").val();
		var subjectVal = "Mail enviado a partir do site";
		var corpo_val = $("#corpo").val();
		//alert(nome_val);
		$.ajax({
			type: "POST",
			url: "PHP/mail_ajax.php",
			data: {nome:nome_val,corpo:corpo_val,correio_resposta:correio_resposta_val},
			success: function(msg){
				//alert( "Data Saved: " + msg );
				//$("#mail-form").replaceWith(msg);
				//$("#mail-form").css({display:"none"});
				$("#mail-popup").append(msg);
				
			}
		});
		
		return false;
			
	});

});
