
var animSpeed = 500;

function showMenuHover(lnk, id) {
  hideMenu();
  // display popup
  var lnk = $(lnk);
  var menu = $("#" + id);
  var ul = menu.children("ul");
  var nav = $("#primaryNav");
  var offset = lnk.offset().left - nav.offset().left - 15;
  var overhang = offset + menu.width() - nav.width();
  if(overhang > 0) {
    offset -= (overhang + 10);
  }
  menu.css("visibility", "hidden");
  menu.css("display", "block");
  menu.css("left", offset);
  menu.css("top", lnk.offset().top - 100);
  menu.css("height", ul.height() + 10);
  menu.children(".popupNavL,.popupNavR,.popupNavC").css("height", ul.height());
  menu.children(".popupNavTab").css("width", lnk.width() + 50);
  menu.css("visibility", "visible");
  menu.bind("mouseleave", null, hideMenu);
  $("#header").bind("mouseover", null, hideMenu);
  // add active highlight
  lnk.addClass("black");
  // display curtain
}

function hideMenu(e) {
  // remove active highlight
  $(".black").removeClass("black");
  // hide all menus
  var e = $(".popupNav");
  e.stop();
  e.hide();
}

function toggleSubNav(id) {
  $("#" + id).toggle(animSpeed);
}

function randomParam() {
  return "&rand=" + Math.random() * 1000000;
}

function randomQS() {
  return "?rand=" + Math.random() * 1000000;
}

$(document).ready(function() {
  // hack to remove pointer cursor from non-links 
  $("a[href='']").removeAttr("href").addClass("notLink");
});
