﻿/***********************************************
 * Menu script by Robin. This does two things. *
 *                                             *
 * 1) contrainmenu() stops the menu from going *
 *    off the side of the screen. Called using *
 *    the addEvent() function below.           *
 * 2) makes the menu work with IE5&6. This is  *
 *    done using the cryptic code at the start *
 *    which makes the code IE only by using MS *
 *    'conditional compilation' (see MSDN). To *
 *    get this working properly we need the    *
 *    defer="defer" attribute on the calling   *
 *    script element. This means that the code *
 *    only runs once the DOM is loaded.        *
 ***********************************************/

// Add menu support for IE using conditional compliation.
// also add in hiding for select elements.
/*@cc_on @*/
/*@if (@_jscript_version < 5.7) // IE6 and below

var sfEls = document.getElementById("rightmenu").childNodes;

for (var i=0; i<sfEls.length; i++) {
  if (sfEls[i].nodeName == 'LI') {
    sfEls[i].onmouseover=function() {
      this.className+=" over";
      iframe.style.display = "block";
      dropdown = this;
      dropdown_left = 0;
      dropdown_top = 0;
      if (dropdown.offsetParent) {
        var dropdown_parents = dropdown;
        while (dropdown_parents.offsetParent) {
          dropdown_left += dropdown_parents.offsetLeft;
          dropdown_top += dropdown_parents.offsetTop;
          dropdown_parents = dropdown_parents.offsetParent;
        }
      }
      if (this.getElementsByTagName("div")[0]) {
        iframe.style.left = (dropdown_left + marginLeftShift) + "px";
        iframe.style.top = (dropdown_top + marginTopShift) +"px";
        iframe.style.width = this.getElementsByTagName("div")[0].offsetWidth+"px";
        iframe.style.height = this.getElementsByTagName("div")[0].offsetHeight+"px";
      }
    }
    sfEls[i].onmouseout=function() {
      this.className=this.className.replace(new RegExp(" over\\b"), "");
      iframe.style.display = "none";
      iframe.style.width = "0";
      iframe.style.height = "0";
    }
  }
}
/*@end @*/

hideMenus = function() {
  this.className = this.className.replace(new RegExp("\\bfocussed\\b"), "");
  main_li = document.getElementById('rightmenu').childNodes;
  for (i=0; i<main_li.length; i++) {
    if (main_li[i].nodeName == 'LI') {
      main_li[i].className = main_li[i].className.replace(new RegExp("\\bover\\b"), "");
      main_li[i].className = main_li[i].className.replace(new RegExp("\\bopen\\b"), "");
    }
  }
}

addEvent(window, 'load', setupMenu);

function setupMenu() {
  main_li = document.getElementById('rightmenu').childNodes;
  for (i=0; i<main_li.length; i++) {
    if (main_li[i].nodeName == 'LI') {
      addEvent(main_li[i], 'mouseover', constrainMenu);
      addEvent(main_li[i], 'mouseover', addOver);
      addEvent(main_li[i], 'mouseout', removeOver);
      sub_li = main_li[i].getElementsByTagName("li");
      for (j=0; j<sub_li.length; j++) {
        addEvent(sub_li[j].getElementsByTagName("a")[0], 'focus', showMenu);
        addEvent(sub_li[j].getElementsByTagName("a")[0], 'blur', hideMenus);
      }
      addEvent(main_li[i].getElementsByTagName("a")[0], 'focus', hideMenus);
    }
  }
}