jQuery.fn.delay = function(time, func) {
	return this.each(function() {
		setTimeout(func, time);
	});
}; 
  

$(document).ready(function() { 
	function validate(formData, jqForm, options) { 
	    var form = jqForm[0]; 
	    if ((!form.name.value) || (!form.comment.value) || (form.name.value == "Name") || (form.comment.value == "Well, what did you think?")) { 
	        $("#fail").fadeIn("normal");
	        return false; 
	    } 
	} 
	
	function after_form() {
		if($("#fail").css("display") != "none") {
			$("#fail").fadeOut("normal");
		}
		$("#success").fadeIn("normal");
		$('#success').delay(8000, function() { $('#success').fadeOut('normal'); });
	}
	
	$('#form').ajaxForm({ 
		beforeSubmit: validate,
		success: after_form 
	 });
	
	$("#form-name").focus(function(){
		$(this).css("background-color", "#FFF");
		if($(this).val() == "Name"){
			$(this).val(""); 
		}
	 }).blur(function(){
		$(this).css("background-color", "#b3b3b3"); 
	 	if($(this).val() == ""){
			$(this).val("Name");
		}
	 });
	
	$("#form-comment").focus(function(){
		$(this).css("background-color", "#FFF");
		if($(this).val() == "Well, what did you think?"){
			$(this).val("");
		}
	 }).blur(function(){  
		$(this).css("background-color", "#b3b3b3");
	 	if($(this).val() == ""){
			$(this).val("Well, what did you think?");
		}
	 });
	
	$(".subnav").click(function() { 
		var which = $(this).attr("rel");
		                                
    	if(which == "talk") {
			if($("#talk").css("display") == "none") {
			   if($("#credits").css("display") != "none") {
				$("#credits").fadeOut("normal", function() {
					$("#talk").fadeIn("normal");
				});
			   }
			   if($("#about").css("display") != "none") {
				$("#about").fadeOut("normal", function() {
					$("#talk").fadeIn("normal");
				});
			   }
			}
		} else if(which == "credits") {
			if($("#credits").css("display") == "none") {
			   if($("#talk").css("display") != "none") {
				$("#talk").fadeOut("normal", function() {
					$("#credits").fadeIn("normal");
				});
			   }
			   if($("#about").css("display") != "none") {
				$("#about").fadeOut("normal", function() {
					$("#credits").fadeIn("normal");
				});
			   }
			}
		} else if(which == "about") {
			if($("#about").css("display") == "none") {
			   if($("#talk").css("display") != "none") {
				$("#talk").fadeOut("normal", function() {
					$("#about").fadeIn("normal");
				});
			   }
			   if($("#credits").css("display") != "none") {
				$("#credits").fadeOut("normal", function() {
					$("#about").fadeIn("normal");
				});
			   } 
			}
		}
	});
});