$(document).ready(function() {
    $("#header #i").blur();
    queryBoxBlur($("#header #i"));

    $("#header #i").blur(function() {
            queryBoxBlur($(this));
        }).focus(function() {
          $(this).css("color", "#555");
        });

    $("#header #i").keypress(function (e) {
        if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
            if ($.trim($(this).val()) != "")
                window.location.href = "http://www.wolframalpha.com/input/?i=" + encodeURIComponent($(this).val());
        }
    });

    $("#header #submitQuery, #header #eq").each(function(){
      $(this).click(function(e){
        e.preventDefault();
        ctrl = $("#header #i");
        if (!($.trim(ctrl.val()) == "" || $.trim(ctrl.val()) == "What would you like to know about?"))
          window.location.href = "http://www.wolframalpha.com/input/?i=" + encodeURIComponent(ctrl.val());
      });
    });

});

function queryBoxBlur(ctrl) {
    if(!ctrl) { ctrl = $("#header #i"); }
    if ($.trim(ctrl.val()) == "" || $.trim(ctrl.val()) == "What would you like to know about?") {
        ctrl.val("What would you like to know about?").css("color", "#999").one("click", function() {
               $(this).val("");
           });
    } else {
        ctrl.css("color", "#555");
    }
    if(ctrl==document.activeElement) {ctrl.blur();}
}

