
/*
  Navigation JavaScript Component
  
  Files:  Navigation.js
  Version: 1.0
  Objects: Navigation
  Dependencies: none
  Last updated: Matthew Smith (matthew.r.smith@erac.com) 3/14/2007
  
  Code provided as-is.  Modification could result in compatability issues with future versions of the component.
*/
function Navigation(container){

  if(container)this.container = container;
  
  var lis = this.container.getElementsByTagName('li');
  
  var context=this;
  
  for(var i=0; i<lis.length; i++){
       
    lis[i].onmouseover = function(){
    
      var uls = this.getElementsByTagName('ul');
      
      if(uls.length==0)return;
      if(uls[0].getElementsByTagName('li').length==0)return;
      
      this.className += ' hover';
      
      // get item index
      var current = this.previousSibling;
      var index = 0;
      var width = 0;
      while(current != null){
        index++;
        current = current.previousSibling;
      }
      
      for(var j=0; j<uls.length; j++){
        uls[j].style.display = 'block'; // show & position submenu
        uls[j].style.position = 'absolute';
        uls[j].style.top = this.offsetTop + this.offsetHeight + 'px';
        if(index >= (this.parentNode.childNodes.length/2))
            uls[j].style.right = (context.container.offsetWidth-this.offsetLeft-this.offsetWidth) + 'px'; // position to the right
        else
          uls[j].style.left = this.offsetLeft + 'px'; // position to the left
      }
      
      navigationHelper.blurFormElements(); // blur all form elements
    }
    
    lis[i].onmouseout = function(){
    
      this.className = this.className.replace('hover', '');
    
      var uls = this.getElementsByTagName('ul');
      
      for(var j=0; j<uls.length; j++){
        uls[j].style.display = 'none'; // hide submenu
      }
    }
  }
/*  
  // add iframe fix
  var uls = this.container.getElementsByTagName('ul');
  
  for(var i=0; i<uls.length; i++){
    var iframeFix = document.createElement('iframe');
      iframeFix.frameBorder = '1';
      iframeFix.style.width = '150px';
      iframeFix.style.position = 'absolute';
      iframeFix.style.top = '0';
      iframeFix.style.left = '0';
      iframeFix.style.zIndex = '-1';
      
      if(document.all)iframeFix.style.filter = 'alpha(opacity=0)';
        else iframeFix.style.opacity = '0';
        
      var height = 10;
      for(var j = 0; j < uls[i].childNodes.length; j++){height += 20;}   
      
      iframeFix.style.height = height + 'px';
      
      uls[i].appendChild(iframeFix);
  }
*/

}


/*
  Header
*/
var navigationHelper = {
 
  /*
    Blurs all form elements on the page
  */
  blurFormElements:function(){
    if(document.all && document.getElementsByTagName) {
      var theForms = document.getElementsByTagName('form');
      
      for(var i=0; i<theForms.length; i++) 
      {
        var theElements = theForms[i].elements;
        for(var j=0; j<theElements.length; j++) { theElements[j].blur(); }
      }
    }
  }
  
}