$(function()
	{
		$("#subscribe").click(function() {	
			// First, disable the form from submitting
			$('.newsletter form').submit(function() { return false; });
			
			// Grab form action
			formAction = $(".newsletter form").attr("action");
			
			// Hack together id for email field
			emailId = formAction.replace("http://ebull.dusteddesign.com/t/r/s/", "");
			emailId = emailId.replace("/", "");
			emailId = emailId + "-" + emailId;

			
			emailChk = true;
			
			// Validate email address with regex
			if (!checkEmail(emailId)) 
			{
				$("#confirmation").slideDown("slow");  // Shows "Thanks for subscribing" div
				$("#confirmation").html("Please enter a valid email address");
				return;
			}

			// Serialize form values to be submitted with POST
			var str = $(".newsletter form").serialize();

			// Add form action to end of serialized data
			final = str + "&action=" + formAction;
			
			// Submit the form via ajax
			$.ajax({
				url: "http://aekt3.com/proxy.php",
				type: "POST",
				data: final,
				success: function(html){
					$("#confirmation").slideDown("slow");  // Shows "Thanks for subscribing" div
					$("#confirmation").html("Thanks for subscribing");
				}
			});
		});
	});
	function checkEmail(email)
	{	
		var pattern = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		var emailVal = $("#" + email).val();
		return pattern.test(emailVal);
	}
