$(document).ready(function()
{  
	var form = $("form#mailing-list");
	
	$('#email').focus(function() { $(this).attr('value', ($(this).attr('value') == 'enter your email address' ? '' : $(this).attr('value'))) });
	
	$(form).submit(function() 
	{  
		var email = $('#email').attr('value'); 
		$.ajax(
		{  
			type: "POST",  
			url: document.location.href, 
			data: "email="+ email +"&ajax=true",  
			dataType: "json",
			beforeSend: function()
			{
				$('.error').each(function(index)
				{
					$(this).remove();
				});
				$("#loading").addClass('visible');
				form.children("#submit").addClass('disabled');				
			},
			complete: function()
			{
				$("#loading").removeClass('visible');
				form.children("#submit").removeClass('disabled');
			},
			success: function(json)
			{  
				if(json.errors)
				{
					$(json.errors).each(function(index)
					{
						$("#submit").after(this.message).next().effect("bounce", { times: 3, mode: "show"}, 200).animate({ backgroundColor: "white" }, 1500).slideUp(1000);
					});					
				}
				else if(json.success)
				{
					form.hide().after(json.success.message).next().effect("bounce", { times:3, mode: "show"}, 200);
				}
			},
			error: function()
			{
				form.children("#loading").after('<p class="spaceyroom error">There was a problem processing your request, please <a href="./contact">contact me</a></p>');
			}
		});  
		return false;  
	});  
}); 
