$(document).ready(function() {
	$("#your_name").blur(function(){
		var qs = new Array();
		qs["action"] = "name";
		qs["name"] = $(this).val();
		qs["rand"] = Math.floor(Math.random()*100001)
		booyantAJAX("/ajax/contact",qs,talkToMeBob);
		return true;
	});
	
	$("#email").blur(function(){
		var qs = new Array();
		qs["action"] = "email";
		qs["email"] = $(this).val();
		qs["rand"] = Math.floor(Math.random()*100001)
		booyantAJAX("/ajax/contact",qs,talkToMeBob);
		return true;
	});
	
	$("#message").blur(function(){
		var qs = new Array();
		qs["action"] = "message";
		qs["message"] = $(this).val();
		qs["rand"] = Math.floor(Math.random()*100001)
		booyantAJAX("/ajax/contact",qs,talkToMeBob);
		return true;
	});
	
	$("#form_submit").click(function(){
		var qs = new Array();
		qs["action"] = "send";
		qs["email"] = $("#email").val();
		qs["name"] = $("#your_name").val();
		qs["message"] = $("#message").val();
		qs["rand"] = Math.floor(Math.random()*100001)
		$("#contactForm").hide();
		$("#loader").show();
		booyantAJAX("/ajax/contact",qs,submitForm);
		return true;
		
		/*
		$.ajax({
			type: "GET",
			url: "/ajax/contact",
			data: qs,
			success: function(msg){
				//alert( "Data Saved: " + msg );
				submitForm(msg);
			
			}
		});
		
		*/
		
	});
	
});

function talkToMeBob(x){

		$("#bob-talk > blockquote > p").html(x);
		$("#bob-talk > blockquote").show(500);

}

function submitForm(x){

	if (x > 0){
		text = "That wooshing sound you hear is your note being split up into millions of tiny pieces, and then going whizzing through the air down to our laptops where they're all put together again in the right order.";
		$("#loader").hide();
	} else {
		text = "Weird. Something went wrong. Can you make sure you filled out all the fields below?";
		$("#contactForm").show();
	}

	$("#bob-talk > blockquote > p").html(text);
	$("#bob-talk > blockquote").show(500);

}