$(document).bind("ready", function (e) {

  $("A").bind("click", function (e) {
    $(this).blur();
  });

  $("A.Nav").bind("click", function (e) {
    var $this = $(this);
    var $subs = $this.siblings("#parent"+$this.attr("id"));
    if ($subs.length > 0) {
     if ($subs.eq(0).css("display") == "none") {
       $subs.css("display", "block");
      }
      else {
       $subs.css("display", "none");
      }
    }
    else {
      if ($this.attr("href") == "#") {
        location.href = "category.php?cat="+$this.attr("id");
      }
      else {
        location.href = $this.attr("href");
      }
    }
    e.preventDefault();
  });

  //  Find the selected menu item and if it's a sub category, show its sibling subcategories.
  var $sel = $("td.LeftColumn a.Selected");
  if ($sel.length > 0) {

    var $elem = $sel.parent(); //  will be the active element
    var par_id = $sel.parent().attr("id");

    var c = true; // will be set to false when there are no more parents
    while (c) {
      if ($elem.attr("id").substring(0, 6) == "parent") {
        $elem.css("display", "block"); //.siblings("."+par_id.substring(7)).css("display", "block");
        $elem = $elem.parent();
      }
      else {
        c = false;
      }
    }

  }

});
