function hideStatus(){
  $("#sta").fadeOut("slow");
}
function auth(key){
  $("#sta").fadeIn("slow");
  $("#sta p").removeClass("warning").text("... verifying");
  $.getJSON("auth.php?a=" + key, function(data){
    if(!data["error"]){
      $("#sta p").text("key correct");
      for(var x in data){
        if(x == "preEval"){
          eval(data[x]);
        }else if(data[x] == "hide"){
          $("#" + x).slideUp(2000);
        }else{
          $("#" + x).html(data[x]).slideDown(2000);
        }
      }
    }else{
      $("#sta p").text(data["error"]);
    }
    $(".corner").corner("4px");
    setTimeout("eval('" + data["postEval"] + "')", 2000);
    setTimeout("hideStatus()", 3000);
  });
  $("form.login input").get(0).type = "text";
  $("form.login input").val("investor's secret");
}
function flashStatus(fadeIn){
  if(fadeIn){
    $("#sta").fadeIn(1500, function(){ flashStatus(false); });
  }else{
    $("#sta").fadeOut(1500, function(){ flashStatus(true); });
  }
}
$(function(){
  $("#matte").css('opacity', 0.3).corner();
  $("#team").corner("4px");
  $("#dsPoster").corner("4px");
  $("#gallery a").lightBox({fixedNavigation:true});
  $("#log").corner("bl tr");
  $("form.login button").corner("8px tr");
  $("form.login input").focus(function(){
    if(this.value == "investor's secret"){
      this.value = "";
      this.type = "password";
    }
  }).blur(function(){
    if(this.value == ""){
      this.value = "investor's secret";
      this.type = "text";
    }
  });
  $("form.login").submit(function(){
    return false;
  })
  $("#password").keydown(function(e){
    if(this.value == "investor's secret"){
      this.value = "";
    }
    if(this.type == "text"){
      this.type = "password";
    }
  });
  $("#password").keypress(function(e){
    if(e.which == 13){
      auth(this.value);
    }
  });
  $("form.login button").click(function(){
    auth($("#password").val());    $("#password").get(0).type = "text";
  });
  if($.browser.msie){
    $("#sta p").addClass("warning").html('M$ Internet Explorer detected!<br/>Please use a real browser for best results <img src="images/smiley.png" width="20" height="20" alt="*jokingly* ;)"/>');
    flashStatus(true);
  }
});
