 function showError(data) {
	$("#checking").hide("slow");
	$("#registering").html("<p>There was a problem logging in. (" + data.code + ") Try again.</p>")
					 .show("slow");
	$("#sign-in-form").show("slow");
 }
 
 $(document).ready(function(){
   $("#form").append("<input type='hidden' name='m' value='ajax' />");							
   $("#sign-in").bind("click", function(e) {
		e.preventDefault();	
		$("#registering").hide("slow");
		$("#sign-in-form").hide("slow");
		$("#checking").show("slow");		
		$.ajax({
			type: "POST",
			url: "http://www.88stories.com/api/token.php",
			data: $("#form").serialize(),
			dataType: "json",
			success: function(data) {
					if(data.code == "ok") {
						$("#checking").hide("slow");
						$("#registering").html("Registering " + data.fname 
											    + " and redirecting...").show("slow");
						setTimeout("location='http://www.88stories.com/c/'", 2000);
					} else { showError(data); }
				},
			error: function(data) { showError(data); }
			});				
   });
 });