var lastShown = "";
var closeOK = true;
var gender;
$(document).ready(function(){
	$(".dim_window").prepend('<a class="close" href="#"></a>');
	$(".close").click(function(){
		if(closeOK) dimTL(lastShown, false);
	});
});
$("#noscript").ready(function(){
	$("#noscript").css("display", "none");
});
$("#giant_overlay").ready(function(){
	$("#giant_overlay").css({"height": $("html").height()+"px", "display": "none"});
});
var dimTL = function(element, show){
	if(show == null) show = true;
	if(show){
		$("#giant_overlay").css("display", "block");
		$(element).css("display", "block");
	} else {
		$("#giant_overlay").css("display", "none");
		$(element).css("display", "none");
	}
	lastShown = element;
};
var getCostume = function(){
	if(closeOK){
		$(".form").attr("readonly", true);
		$("input[type=button]").val("Please wait...");
		closeOK = false;
		prevHTML = $("#window2").html();
		$.post("changeCostume.php?gender="+gender, { login: $("#username").val(), pswd: $("#password").val() },
			function(data){
				closeOK = true;
				dimTL(lastShown, false);
				$("#window2").html(prevHTML);
				$(".form").attr("readonly", false);
				$("input[type=button]").val("Submit");
				if(data == "result=success"){
					msg = "Congrats! Your selected outfit has been applied to your account.";
				} else if(data == "result=invalid-gender"){
					msg = "Sorry, this costume is not available for your Poptropican's gender.";
				} else {
					msg = "Whoops! Looks like something went wrong. Try again later.";
				}
				alert(msg);
			}
		);
	}
};