$(document).ready(function(){
	$("#form-email").submit(function(){
		var emailForm = $(this);
		emailForm.hide();
		$(".ajax-loader").show();
		
		$.getJSON('/ajax/emailSubscribe.php', {email: $("#email").val()}, function(json){
			//alert(json.success);
			$(".ajax-loader").hide();
			emailForm.show();
			// If there was an error, just alert it
			if(!json.success) {
				alert(json.message);
				$("#email").focus();
				return;
			}
			
			// It went OK show the gratitude message and remove the loader
			$("#form-email").replaceWith('<span style="color: #FFFFFF; font-weight: bold; id="thank-you">Thank you for your subscription</span>');
			// Uncomment the line below to fade the message out
			//$("#thank-you").closest("li.emailSubmit").fadeOut(15000);
			
		});
		
		return false;
	});
});
