// For each menu you create, you must create a matching "FSMenu" JavaScript object to represent
// it and manage its behaviour. You don't have to edit this script at all if you don't want to;
// these comments are just here for completeness. Also, feel free to paste this script into the
// external .JS file to make including it in your pages easier!

// Here's a menu object to control the above list of menu data:
var listMenu = new FSMenu('listMenu', true, 'display', 'block', 'none');

// The parameters of the FSMenu object are:
//  1) Its own name in quotes.
//  2) Whether this is a nested list menu or not (in this case, true means yes).
//  3) The CSS property name to change when menus are shown and hidden.
//  4) The visible value of that CSS property.
//  5) The hidden value of that CSS property.
//
// Next, here's some optional settings for delays and highlighting:
//  * showDelay is the time (in milliseconds) to display a new child menu.
//    Remember that 1000 milliseconds = 1 second.
//  * switchDelay is the time to switch from one child menu to another child menu.
//    Set this higher and point at 2 neighbouring items to see what it does.
//  * hideDelay is the time it takes for a menu to hide after mouseout.
//    Set this to a negative number to disable hiding entirely.
//  * cssLitClass is the CSS classname applied to parent items of active menus.
//  * showOnClick will, suprisingly, set the menus to show on click. Pick one of 3 values:
//    0 = all mouseover, 1 = first level click, sublevels mouseover, 2 = all click.
//  * hideOnClick hides all visible menus when one is clicked (defaults to true).
//  * animInSpeed and animOutSpeed set the animation speed. Set to a number
//    between 0 and 1 where higher = faster. Setting both to 1 disables animation.

//listMenu.showDelay = 0;
//listMenu.switchDelay = 125;
//listMenu.hideDelay = 500;
//listMenu.cssLitClass = 'highlighted';
//listMenu.showOnClick = 0;
//listMenu.hideOnClick = true;
//listMenu.animInSpeed = 0.2;
//listMenu.animOutSpeed = 0.2;


// Animations
listMenu.animations[listMenu.animations.length] = FSMenu.animFade;
listMenu.animations[listMenu.animations.length] = FSMenu.animSwipeDown;
//listMenu.animations[listMenu.animations.length] = FSMenu.animClipDown;

// assign an arrow for submenu flyouts
var arrow = null;
if (document.createElement && document.documentElement) {
 arrow = document.createElement('span');
 arrow.appendChild(document.createTextNode('>'));
 // Feel free to replace the above two lines with these for a small arrow image...
 //arrow = document.createElement('img');
 //arrow.src = 'arrow.gif';
 //arrow.style.borderWidth = '0';
 arrow.className = 'subind';
}
addEvent(window, 'load', new Function('listMenu.activateMenu("main_navigation", arrow)'));

// MENU REPOSITIONING: This will stop menus showing outside visible screen boundaries.

      page.winW=function()
       { with (this) return Math.max(minW, MS?win.document[db].clientWidth:win.innerWidth) };
      page.winH=function()
       { with (this) return Math.max(minH, MS?win.document[db].clientHeight:win.innerHeight) };
      page.scrollX=function()
       { with (this) return MS?win.document[db].scrollLeft:win.pageXOffset };
      page.scrollY=function()
       { with (this) return MS?win.document[db].scrollTop:win.pageYOffset };

      function repositionMenus(mN) { with (this)
      {
       var menu = this.menus[mN].lyr;

       // Showing before measuring corrects MSIE bug.
       menu.sty.display = 'block';
       // Reset to and/or store original margins.
       if (!menu._fsm_origML) menu._fsm_origML = menu.ref.currentStyle ?
        menu.ref.currentStyle.marginLeft : (menu.sty.marginLeft || 'auto');
       if (!menu._fsm_origMT) menu._fsm_origMT = menu.ref.currentStyle ?
        menu.ref.currentStyle.marginTop : (menu.sty.marginTop || 'auto');
       menu.sty.marginLeft = menu._fsm_origML;
       menu.sty.marginTop = menu._fsm_origMT;

       // Calculate absolute position within document.
       var menuX = 0, menuY = 0,
        menuW = menu.ref.offsetWidth, menuH = menu.ref.offsetHeight,
        vpL = page.scrollX(), vpR = vpL + page.winW() - 16,
        vpT = page.scrollY(), vpB = vpT + page.winH() - 16;
       var tmp = menu.ref;
       while (tmp)
       {
        menuX += tmp.offsetLeft;
        menuY += tmp.offsetTop;
        tmp = tmp.offsetParent;
       }

       // Compare position to viewport, reposition accordingly.
       var mgL = 0, mgT = 0;
       if (menuX + menuW > vpR) mgL = vpR - menuX - menuW;
       if (menuX + mgL < vpL) mgL = vpL - menuX;
       if (menuY + menuH > vpB) mgT = vpB - menuY - menuH;
       if (menuY + mgT < vpT) mgT = vpT - menuY;

       if (mgL) menu.sty.marginLeft = mgL + 'px';
       if (mgT) menu.sty.marginTop = mgT + 'px';
      }};

      // Set this to process menu show events for a given object.
      addEvent(listMenu, 'show', repositionMenus, true);


// this will display the title for each href in a div on the page
function titleDisplaySetup() {
	titleDisplay('main_navigation', 'menuhint');
};
addEvent(window, 'load', titleDisplaySetup);

function titleDisplay(menuID, target) {
 var nav = getRef(menuID);
 addEvent(nav, 'mouseover', new Function('e',
  'e=e||window.event; var lt=getRef("' + target + '"); if (lt) {' +
  'while (lt.firstChild) lt.removeChild(lt.firstChild);' +
   'e=e.target||e.srcElement; while(e && (!e.title&&!e.title_orig)) e=e.parentNode;' +
   'if (e && e.getAttribute) {' +
    'var t = e.getAttribute("title");' +
    'if (t) { e.title_orig = t; e.setAttribute("title", "") }' +
    'lt.appendChild(document.createTextNode(e.title_orig));' +
  '}}'));
 addEvent(nav, 'mouseout', new Function('e',
  'var lt=getRef("' + target + '"); if (lt) while (lt.firstChild) lt.removeChild(lt.firstChild);'));
}

