function getObj(name)
{
  if (document.getElementById)
  {
  	this.obj = document.getElementById(name);
	this.style = document.getElementById(name).style;
  }
  else if (document.all)
  {
	this.obj = document.all[name];
	this.style = document.all[name].style;
  }
  else if (document.layers)
  {
   	this.obj = document.layers[name];
   	this.style = document.layers[name];
  }
}

enableHoverMenusOld = function(){
  navRoot = new getObj('nav').obj;
  menuItems = navRoot.getElementsByTagName("LI");
  numMenuItems = menuItems.length;
  //cycle through all <li> nodes inside 'nav'
  for (i=0; i<numMenuItems; i++)
  {
	  if(menuItems[i].childNodes[2])
	  {
	    if(menuItems[i].firstChild.nodeName == "A" && menuItems[i].childNodes[2].nodeName == "UL")
		{
			menuItems[i].className = "collapsed";
			
			//add onmouseover event to menu entries that have submenus
			menuItems[i].firstChild.onmouseover = function() {
			  // Capture current class for the li
			  var currentClass = this.parentNode.className;
			  navRoot = new getObj('nav').obj;
			  
			  // Toggle display of submenu on/off
			  if (this.parentNode.className) 
			  {
				if(currentClass == 'collapsed')
				{
				  this.parentNode.className = 'expanded';
				  //this.parentNode.childNodes[2].style.display  = 'block';
				}
			  }
			}
			
			
			//add onmouseout event to menu entries that have submenus
			menuItems[i].firstChild.onmouseout = function() {
			  // Capture current class for the li
			  var currentClass = this.parentNode.className;
			  navRoot = new getObj('nav').obj;
			  
			  // Toggle display of submenu on/off
			  if (this.parentNode.className) 
			  {
				if(currentClass == 'expanded')
				{
				  this.parentNode.className = 'collapsed';
				  //this.parentNode.childNodes[2].style.display  = 'block';
				}
			  }
			}			
		}
	  }
  }
  
}




var to;
enableHoverMenus = function() {
//timer = hoverTime;
  navRoot = new getObj('nav').obj;
  menuItems = navRoot.getElementsByTagName("LI");
  numMenuItems = menuItems.length;
  
  //for (i=0; i<navRoot.childNodes.length; i++) {
  for (i=0; i<numMenuItems; i++) {
    //node = navRoot.childNodes[i];
	node = menuItems[i];  
    
    //if (node.nodeName=="LI") {
	if(node.childNodes[2])
	  {
	    if(node.firstChild.nodeName == "A" && node.childNodes[2].nodeName == "UL")
		{
	  node.className = "collapsed";
      node.onmouseover=function() {

		//make sure timeout doesn't hide menu unexpectedly
		if(to) clearTimeout(to);
		
		//hide all menus
		collapseAllMenus();
        /*
		node = this.parentNode.firstChild;
		if (node.nodeName=="LI") {
          node.className=node.className.replace(" expanded", " collapsed");
        }
		while (node.nextSibling)
		{
		  node = node.nextSibling;
          if (node.nodeName=="LI") {  
		    node.className=node.className.replace(" expanded", " collapsed");
		  }
        }
		*/
        
        //show this menu
        node.className=node.className.replace("collapsed", "expanded");
      }
      node.onmouseout= function() {
        theObj = this;
        if (!timer) var timer = 400;
        //to = setTimeout('theObj.className=theObj.className.replace(" expanded", " collapsed");', timer);
        to = setTimeout('collapseAllMenus();', timer);
	  }
      
    }
	}
  }
}

collapseAllMenus = function() {
//timer = hoverTime;
  navRoot = new getObj('nav').obj;
  menuItems = navRoot.getElementsByTagName("LI");
  numMenuItems = menuItems.length;
  
  for (i=0; i<numMenuItems; i++) {
	node = menuItems[i];    
	if(node.nodeName == "LI")
	{
		node.className=node.className.replace("expanded", "collapsed");
	  /*if(node.firstChild.nodeName == "A" && node.childNodes[2].nodeName == "UL")
	  {
		//hide all menus
        //node = this.parentNode.firstChild;
		if (node.nodeName=="LI") {
          node.className=node.className.replace(" expanded", " collapsed");
        }
		while (node.nextSibling)
		{
		  node = node.nextSibling;
          if (node.nodeName=="LI") {  
		    node.className=node.className.replace(" expanded", " collapsed");
		  }
        }      
      }*/
	}
  }
}


enableClickableLists = function() {
  listItems = document.getElementsByTagName("LI");
  numListItems = listItems.length;
  
  for (i=0; i<numListItems; i++) {
	node = listItems[i];    
	if(node.nodeName == "LI" && (node.className.indexOf("row0") != -1 || node.className.indexOf("row1") != -1 ))
	{
		node.style.display = "block";
		//node.style.width = node.parentNode.offsetWidth + "px";
		node.onmouseover = function() {
		  this.className = this.className + " RowOverSelected";	
		}
		
		node.onmouseout = function() {
		  this.className = this.className.replace(" RowOverSelected", "");	
		}
		node.onclick = function() {
			//get the link URL
			strURL = "";
			linkNode = this.firstChild;
			if (linkNode.nodeName=="A") {  
			  //strURL = linkNode.getAttribute("HREF");
			  strURL = linkNode.href;
			}
			while (linkNode.nextSibling && strURL != "")
			{
			  linkNode = linkNode.nextSibling;
			  if (linkNode.nodeName=="A") {  
			    strURL = linkNode.href;
			  }
			}
			window.location = strURL;
		}
	}
  }
}

function moveFooterToBottom()
{
/*
	var windowHeight;

	if (self.innerHeight) // all except Explorer
	{
	  windowHeight = self.innerHeight;
	  headerHeight = document.getElementById("header").offsetHeight;
	  bodyHeight = document.getElementById("bodycontent").offsetHeight;
	  footerHeight = document.getElementById("footer").offsetHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight)
	// Explorer 6 Strict Mode
	{
	  windowHeight = document.documentElement.clientHeight;
	  headerHeight = document.getElementById("header").clientHeight + 5;
	  bodyHeight = document.getElementById("bodycontent").clientHeight + 5;
	  footerHeight = document.getElementById("footer").clientHeight + 5;
	}
	else if (document.body) // other Explorers
	{
	  windowHeight = document.body.clientHeight;
	  headerHeight = document.getElementById("header").clientHeight;
	  bodyHeight = document.getElementById("bodycontent").clientHeight;
	  footerHeight = document.getElementById("footer").clientHeight;
	}


	newBodyHeight = windowHeight - (headerHeight + footerHeight + 22);
	
	if (newBodyHeight > bodyHeight)
	{
	  document.getElementById("bodycontent").style.height = newBodyHeight+"px";
	}
*/
}





/*****************/
/* Define events */
/*****************/


function addLoadEvent(func)
{
	var oldonload = window.onload;
	if (typeof window.onload != 'function') 
	{
		window.onload = func;
	} 
	else 
	{
		window.onload = function() 
		{
			oldonload();
			func();
		}
	}
}



//set onload events
addLoadEvent(moveFooterToBottom);
//addLoadEvent(enableHoverMenus);
addLoadEvent(enableClickableLists);
//addLoadEvent(expandCurrentMenu);

//set other events
window.onresize = moveFooterToBottom;