/* Site menu using jQuery. */
$(document).ready(function() {

  var menuId;
  var isRtl;
  var eoffset;

  if (document.getElementById("tcMainMenuRtl")) {
    menuId = "#tcMainMenuRtl";
    isRtl = true;
  }
  else {
    menuId = "#tcMainMenu";
    isRtl = false;
  }

  //v2. $(menuId + " ul").hide();
  $(menuId + " div.sm").hide();

  //v2. $(menuId + " ul a").addClass("mainSubMenuLink");
  $(menuId + " table a").addClass("mainSubMenuLink");

  // First level items.
  $(menuId + " tr:first>td").hover(

      function() {
        $(this).addClass("mainMenuHover");

        /* Set top for IE6, IE7. */
        eoffset = $(this).offset().top + $(this).height() - 2;
        $(this).children("div.sm").css("top", eoffset); //v2. ul >>> table

        if (isRtl) {
          /* Align submenu blocks to the right for Chrome etc. */
          /* 210 = 225 - 15 and page scrolling offset. */
          eoffset = $(this).position().left + $(this).width() - 210 - $("html").offset().left;
          $(this).children("div.sm").css("left", eoffset); //v2. ul >>> table
        }
        else {
          /* Align submenu blocks to the left for IE6, IE7. */
          eoffset = $(this).offset().left - 1;
          $(this).children("div.sm").css("left", eoffset); //v2. ul >>> table
        }

        $(this).children("div.sm").show(); //v2. ul >>> table
      },
      function() {
        $(this).children("div.sm").hide(); //v2. ul >>> table
        $(this).removeClass("mainMenuHover");
      }
  ); //hover

  // Initialize site search form.
  var sf = new siteSearch();

  $("#frmSrch").focus(
    function() {
      if (!sf.searchEntered) {
        $(this).val("");
      }
      $(this).attr("class", "sfActive");
    }
  ); // search box focus.

  $("#frmSrch").keyup(
    function() {
      sf.searchEntered = true;
      if ($(this).val().length == 0) { sf.searchEntered = false; }
    }
  ); // search box keyup.

  $("#frmSrch").blur(
    function() {
      if (!sf.searchEntered) {
        if ($(this).val() == "") {
          $(this).val(sf.searchDefault);
          $(this).attr("class", "sfInactive");
        }
      }
    }
  ); // search box blur.

});   // document ready

function siteSearch() {

  this.searchEntered = false;
  this.searchDefault = "";

  if (this.searchField == null) {
    this.searchField = document.getElementById("frmSrch");
  }

  if (this.searchField) {
    this.searchDefault = this.searchField.value;
  }

}

function hideUIMenu() {
  var uimenu;

  if (document.getElementById) { uimenu = document.getElementById("uilSelector"); }
  else if (document.all) { uimenu = document.all("uilSelector"); }
  else if (document.layers) { uimenu = document.layers["uilSelector"]; }
  if (uimenu) {
    uimenu.style.display = "none";
  }
}

