$(function(){
  $("a.joinbutton").click(function(){
    $("#joinbutton").fadeOut("normal", function(){$("#form").fadeIn();});
    return false;
  });
  $(".read").click(function(){
    $.scrollTo("#shirt");
    setTimeout($("#shirt").effect("highlight",null, 5000), 1000);
    return false;
  }); 
  
  setTimeout(loadNextName, 1);
  
  $("#join-form").validate({
    rules: {
      name: { required: true },
      location: { required: true },
      email: { required: true, email: true }
    },
    messages: {
      name: "Be proud! Give me your name!",
      location: "Where are you? Given at least your country!",
      email: {
        required: "You won't get any spam, I promise.",
        email: "Format it like user@domain.tld."
      }
    },
    submitHandler: submitter,
    invalidHandler: function(form, validator){
      var errors = validator.numberOfInvalids();
      if (errors) {
        window.status = "Your pledge didn't go through because you forgot something.";
      }
    }
  });    
});

function loadNextName(){
  $("#othername").load("getone.php");
  setTimeout(loadNextName, 3000);
}
function submitter(){
  $.post(
    $("#form form").attr("action"), //url
    {
      name: $("#name").val(),
      location: $("#location").val(),
      email: $("#email").val(),
      referrer: document.referrer
    },
    function(data){
      if(data.value != false){
        $("#joinme").fadeOut("normal", function(){
                                       $("#thanks").fadeIn();
                                     }
        );
      }
    },
    "json"
  );
  return false;
}

