﻿String.prototype.trim = function() { return this.replace(/^\s+|\s+$/, ''); };
		
var disp = "";
var disp1 = "";

function getMousePos(e)
{
	if (!e)
	var e = window.event||window.Event;
			
	var node;
	if (e.target == null)
	{
		node = e.srcElement;
	}
	else
	{
		node = e.target;
	}
				
	//reset
	disp = "";
	disp1 = "";
	
	while (node.parentNode != null)
	{
	    //show the classNames
        disp1 += " - " + node.nodeName;
	    
	    if (node.className.length > 0)
	    {
	        //show the classNames
	        disp += " - " + node.className;
	    }
	    
	    //loop up
	    node = node.parentNode;
	}
	
	//get ref to node
	if (e.target == null)
	{
		node = e.srcElement;
	}
	else
	{
		node = e.target;
	}
	
	disp = disp.trim();
	disp1 = disp1.trim();
	
	//alert(disp1);
			
	//check to see if we are on the primary navigation link
	if ((disp1 == "- A - LI - UL - DIV - DIV - DIV - DIV - DIV - DIV - BODY - HTML")&&
	    (disp.indexOf("- navigation") > -1))
	{
	    //get ref to child navigation
	    var child_node = document.getElementById(node.title.toLowerCase().replace(/ /ig, "_"));
	    
	    if (child_node != null)
	    {
	        if (arr_nodes.length > 0)
	        {
	            //hide the prev navigation
	            hide(arr_nodes[(arr_nodes.length -1)]); 
	        }
	        
	        //add the child_node
	        arr_nodes.push(child_node);
	            			    
	        //show the child navigation
	        show(child_node);
	    }
	}
	
	if (disp.indexOf("- navigation") == -1)
	{
	    if (arr_nodes.length > 0)
        {
            //hide the prev navigation
            hide(arr_nodes[(arr_nodes.length -1)]);
            
            //reset the array
            arr_nodes = new Array();
        }
	}
}

var arr_nodes = new Array();

function hide(node)
{
	if (node != null)
	{			
		node.style.visibility = "hidden";
		node.style.display = "none";
	}
}

function show(node)
{
	node.style.visibility = "visible";
	node.style.display = "inline";
}

//add event handlers
if(window.Event && document.captureEvents)
document.captureEvents(Event.MOUSEMOVE);
document.onmousemove = getMousePos;
