$(document).ready(function() {
	
	// wait for form submission
	$("#nlform").submit(function() {

		// get the input element and text
		var input = $("#nlemail");
		var text = input.val();

		//post data to process.php and get json
		$.post('/php/newsletterSubscribe.php', { data: text }, function(data) {
			// create a new div element, add it to queue and animate
			var element = $('<span id="nlinfo" class="' + data.status + '">' + data.text + '</span>');
			
			if ($("#nlinfo").length) // if element already exists...
				$("#nlinfo").remove(); // ...remove
				
			element.appendTo("#nlform").fadeIn(5000);
		}, 'json');
		
		// prevent default form action
		return false;
	});
});
