(function(B){var A={};A.text=function(D,E){D=B(D);function F(){if(D.val()===""||D.val()===E){D.val(E).addClass("hint")}}function C(){if(D.val()===E){D.val("").removeClass("hint")}}D.blur(F).focus(C).each(F)};A.password=function(E,F){var H=B(E),D=B("<input type='text' />").insertBefore(H).val(F).addClass("hint");function G(){if(H.val()===""){H.hide();D.show()}}function C(){D.hide();H.show().focus()}H.data("hinted-password-field",true);H.blur(G);D.focus(C);G()};B.fn.hide_password_field=function(){this.hide().prev().hide()};B.fn.show_password_field=function(){var D=this,C=D.prev();if(D.val()===""){C.show()}else{D.show()}};B.fn.add_hint=function(C){this.filter("input").each(function(){A[this.type](this,C)})}})(jQuery);(function(F){function J(){F("#welcome form").attr("action","login.php");F("#welcome h3").text("login");F("#welcome #password2").hide_password_field();F("#welcome #toggle_register_login").text("new here?").blur();F("#welcome #username").focus().select()}function C(){F("#welcome form").attr("action","register.php");F("#welcome h3").text("register");F("#welcome #password2").show_password_field();F("#welcome #toggle_register_login").text("already registered?").blur()}function H(){var M=F("#welcome form").attr("action");if(M==="register.php"){J()}else{C()}F("#welcome form").find(".validation_error, .double_error").remove();return false}function E(){return F("#welcome #username").val()}function L(){location.href=location.href.replace("?session=expired","")}F.fn.show_validation_error=function(M){if(F(this).next().is(".validation_error")){F(this).next().text(M);return this}F("<div class='validation_error'>"+M+"</div>").insertAfter(this).hide().fadeIn(500);F(this).one("keydown",function(){F(this).next().filter(".validation_error").fadeOut(1000,function(){F(this).remove()})});return this};function A(){var M=F("<div class='double_error'>these aren't equal (they should be)</div>").insertAfter("#password").hide().fadeIn(500);if(F.browser.opera){M.css("margin-top","5px")}F("#password, #password2").keyup(function(){var O=F("#password").val(),N=F("#password2").val();if(O===N){M.fadeOut(500,function(){M.remove()});F("#password, #password2").unbind("keyup")}})}function G(){return F("#welcome h3").text()}function B(M){switch(M.result){case"unavailable_username":F("#username").show_validation_error("sorry, that username is unavailable").focus().select();return true;case"unknown_username":F("#username").show_validation_error("sorry, this username is new to me").focus().select();return true;case"missing_username":F("#username").show_validation_error("you need a username to "+G()).focus();return true;case"wrong_password":F("#password").show_validation_error("sorry, that's not the right password").focus().select();return true;case"missing_password":F("#password").show_validation_error("you need a password to "+G()).prev().trigger("focus").next().focus();return true;case"mismatched_passwords":A();return true;default:return false}}function K(N){var M=F(this);N.preventDefault();F.postJSON("actions/"+M.attr("action"),M.serializeArray(),L,B);return false}function I(){return F("#session_expired").exists()||E()!=="username"}function D(){F("#username").add_hint("username");F("#password").add_hint("password");F("#password2").add_hint("password again");F("#toggle_register_login").click(H);F("#welcome form").submit(K);if(I()){J()}F("#submit").val("let's start").attr("disabled","")}D()})(jQuery)
