  /**
  * D2 Hierarchical Menu System
  * Version 1.4.3
  */
  
  /**
  * Modify these variables to control menu position and feel.
  */
  
  rootMenuOffsetX       = 0;
  rootMenuOffsetY       = 28;
  subMenuOffsetX        = 135;
  subMenuOffsetY        = 4;
  
  subMenuDelay          = 500;

  /**
  * Main control code. Do not modify any code below this line.
  */
  
  menuActive = false;
  
  function Is() {
    var agent   = navigator.userAgent.toLowerCase();
    this.major  = parseInt(navigator.appVersion);
    this.minor  = parseFloat(navigator.appVersion);
    this.ns     = ((agent.indexOf('mozilla')   != -1) &&
                  (agent.indexOf('spoofer')    == -1) &&
                  (agent.indexOf('compatible') == -1) &&
                  (agent.indexOf('opera')      == -1) &&
                  (agent.indexOf('webtv')      == -1));
    this.ns4    = (this.ns && (this.major      ==  4));
    this.ns6    = (this.ns && (this.major      >=  5));
    this.ie     = (agent.indexOf("msie")       != -1);
    this.ie3    = (this.ie && (this.major      <   4));
    this.ie4  	= (this.ie && (this.major >= 4));
    this.ie5    = (this.ie && (this.major      ==  4) &&
                  (agent.indexOf("msie 5.0")   != -1));
    this.ie6    = (this.ie && (this.major      ==  4) &&
                  (agent.indexOf("msie 6.0")   != -1));
    this.ieX    = (this.ie && !this.ie3 && !this.ie4 && !this.ie5 && !this.ie6);
  }

	function getY(obj){
	  var y = 0;
	  if(obj) {
  		if (document.getElementById || document.all) {
  		  while (obj.offsetParent) {
  			y += obj.offsetTop;
  			obj = obj.offsetParent;
  		  }
  		} else if(document.layers) {
  		  y += obj.y;
  		}
	  }
	  return y;
	}
	
	function getX(obj){
	  var x = 0;
	  if(obj) {
  		if(document.getElementById || document.all) {
  		  while (obj.offsetParent) {
  			x += obj.offsetLeft;
  			obj = obj.offsetParent;
  		  }
  		} else if(document.layers) {
  		  x += obj.x;
  		}
	  }
	  return x;
	}

  function getMenuX(id) {
    var obj = getObj(id);
    var x = obj.offsetLeft;
    x = parseInt(x);
    
    if(document.body.offsetWidth && !obj.root) {
      var bodyWidth = document.body.offsetWidth;
      if(x + (obj.offsetWidth + subMenuOffsetX) > bodyWidth) {
        x -= (obj.offsetWidth + subMenuOffsetX - 10);
      }   
    }
    
    if(isNaN(x)) x = 0;
    if(x == 0 && obj.parent == null) {
      x = getX(obj);
    }
    return x;
  }
  
  function getMenuY(id) {
    var obj = getObj(id);
    var y = obj.offsetTop;
    y = parseInt(y);    
    if(isNaN(y)) y = 0;
    if(y == 0 && obj.parent == null) {
      y = getY(obj);
    }
    return y;
  }
  
  
  function getObj(id) {
    var obj;
    obj = document.getElementById(id);
    return obj;
  }
    
  function setDisplay(id, display) {
    var obj = getObj(id);
    if(display) {
      obj.style.display = 'block';
    } else {
      obj.style.display = 'none';
    }
  }
  
  function showChildren(id) {
    menuActive = true;
    
    var obj = getObj(id);
    
    if(!obj.level) obj.level = 1;
    if(!obj.number) obj.number = 1;
    if(!obj.root) obj.root = obj;
    if(!obj.container) obj.container = obj;
    
    if(obj.delay) {
      clearTimeout(obj.delay);
    }
    
    if(obj.parent) {
      if(obj.parent.parent != null) {
        obj.parent.className = "menuItem_On";
      }
      if(obj.parent.selected) {
        if(obj.parent.selected != obj) {
          obj.parent.selected.className = "menuItem_Off";
          hideChildren(obj.parent.selected.id, 0);
        }
      }
      obj.parent.selected = obj;
    }
    
    if(obj.root) {
      if(obj.root.delay) {
        clearTimeout(obj.root.delay);
      }
    }
    
    subMenu = getObj(obj.id + "_subMenus");
 
    if(subMenu != null) {
      
      obj.subMenus = subMenu.childNodes.length;
      
      var is = new Is();
      
      if(obj.root==obj) {
        subMenu.style.top = getMenuY(obj.id) + rootMenuOffsetY;
        subMenu.style.left = getMenuX(obj.container.id) + rootMenuOffsetX;        
      } else {
        subMenu.style.top = getMenuY(obj.container.id) + getMenuY(obj.id) + subMenuOffsetY;
        subMenu.style.left = getMenuX(obj.container.id) + subMenuOffsetX;
      }
      
      setDisplay(subMenu.id, true);

      for(i = 0; i <= obj.subMenus - 1; i++) {
        tmpObj = getObj(obj.id + "_" + i);
				if(tmpObj) {
					tmpObj.parent = obj;
					tmpObj.level = obj.level + 1;
					tmpObj.number = i;
					tmpObj.root = obj.root;
					tmpObj.container = subMenu;
					tmpObj.style.top = 16 * (i - 1);
					
					tmpObj.onmouseover = function() {
					  this.className = "menuItem_On";
						showChildren(this.id);
					}
					
					tmpObj.onmouseout = function() {
					  this.className = "menuItem_Off";
						hideChildren(this.root.id, subMenuDelay * 2);
					}
					
					tmpObj.onclick = function() {
					  this.className = "menuItem_Off";
					  hideChildren(this.root.id, 0);
					}
				}
      }
      
      if(document.body.clientHeight) {
        var bodyHeight = document.body.clientHeight;
        if(document.body.scrollTop) {
          bodyHeight += document.body.scrollTop;
        }
        
        if(parseInt(subMenu.style.top) + subMenu.offsetHeight > bodyHeight) {
          subMenu.style.top = parseInt(subMenu.style.top) - ((parseInt(subMenu.style.top) + subMenu.offsetHeight) - bodyHeight) < 0 ? 0 : parseInt(subMenu.style.top) - ((parseInt(subMenu.style.top) + subMenu.offsetHeight) - bodyHeight);
        }
      }
    }
  }
  
  function hideChildren(id, delay) {
    if(delay == 0) {
      menuActive = false;
    }
    
    var obj = getObj(id);

    if(obj) {
      if(delay) {
        obj.delay = setTimeout("hideChildren(\'" + id + "\', 0)", delay);
      } else {
        if(obj.subMenus) {
          subMenu = getObj(obj.id + "_subMenus");
          if(obj.selected) {
            obj.selected.className = "menuItem_Off";
          }
          setDisplay(subMenu.id, false);
        }
        if(obj.selected) {
          hideChildren(obj.selected.id, 0);
        }
      }
    }
  }
  
  var tierSelected;
