var defaultQuery = "information retrieval";
$(document).ready(function() {
  $(window).load(function() {
    search_tag = $("#search-submit");
    if (search_tag) search_tag.attr("disabled", false);
  });
  $("#search_form").bind("submit", function() {
    $("#search-submit").attr("disabled", true);
    Loading.showIt(this);
  });
  sq_id = $("#search_query");
  if (sq_id.length != 0) {
    if (sq_id.attr("value").length == 0 || sq_id.attr("value") == defaultQuery) {
      sq_id.attr("value", defaultQuery);
      sq_id.css("color", "#CCC");
      sq_id.bind("focus", function() {
        if (sq_id.attr("value") == defaultQuery && sq_id.css("color") == "rgb(204, 204, 204)") {
          sq_id.attr("value", "");
          sq_id.css("color", "#000");
        }
      });
    }
  }
  $("#hide_categories").bind("click", function() {
    toggleCategoryPanel();
  });
});
var Message = {
  notify: function(text, hide_after) { this.message(text, 'notice', hide_after); },
  error: function(text, hide_after) { this.message(text, 'error', hide_after); },
  message: function(text, class_, hide_after) {
    id = 'flash_' + class_ + '_content';
    $('#flash_' + class_).html('<h2 id="' + id + '" class="' + class_ + '">' + text + '</h2>');
    if (typeof(hide_after) == 'number' && hide_after > 0) {
      setTimeout(function() {
        $('#' + id).fadeOut(1000);
      }, hide_after);
    }
  },
  delayedHide: function(time) { setTimeout(function() { $('#flash_notice_content').fadeOut(time/3); }, time); }
};
var Loading = {
  popupId: '#loading-popup',
  showIt: function(e) {
    $(Loading.popupId).show();
  },
  hideIt: function() { $(Loading.popupId).hide(); }
};
function toggleCategoryPanel() {
    cat_id = $("#categories");
    if (cat_id.css("display") == "none") {
      cat_id.show();
    } else {
      cat_id.hide();
      $(".results .category").each(function(el) {
        $(this).css("width", "860px");
      });
    }
}