

var menu_delay = 1000;
var top_links = new Array();

// an array that holds the <div> ids that have sub navs
var sub_nav_ids = Array('aboutSubMenu',
				'productsSubMenu',
				'featureSubMenu',
				'marketsSubMenu'
				);
var top_link;

//var test_form;



//----------------------------------------------------------------------------------------------------------------

function initHeaderSubNav() {
	//  if browser supports the code used. if not, stop code
	if (!DHTML) return;
	
	//test_form = document.getElementById('test_form');
	
	for(var x=0; x<sub_nav_ids.length; x++) {
		var parentDiv;
		//get the parent node
		parentDiv = document.getElementById(sub_nav_ids[x]);
		// loop the parent's kids
		for( var z=0; z<parentDiv.childNodes.length; z++) {
			// get the child node
			var child_node = parentDiv.childNodes[z];
			// check the child node's tag name
			switch (child_node.nodeName) {
				case 'A':
					top_links[x] = child_node;	// store the <a> node. this is the top level link
					//top_links[x].onmouseover = showSubMenu;
					top_links[x].onmouseover = activateMenu;
					top_links[x].onmouseout = setTimer;
					top_links[x].timer_id;		// holds the timer that controls this obj's submenu
					top_links[x].open_fly_out_menu; 	// stores a ref to the <ul> that is the open flyout menu
					top_links[x].fly_out_timer_id; 		// holds the timer that controls this open flyout menu
					break;	
				case 'UL':
					top_links[x].submenu = child_node;	// store the <ul> that is the submenu for this link submenu
					var links = new Array();;	// this will hold the links in this <ul>. the links get stored in the submenu obj at the end of this block
					var b=0;
					var ul_node = child_node;	// assignment done mainly for readability
					
					// loop through the children for this <ul>
					for (var i=0; i<ul_node.childNodes.length; i++) {
						// if the node is a <li>
						if( ul_node.childNodes[i].nodeName == "LI" ) {	
							// get the <li> node
							var li_node = ul_node.childNodes[i];
							//loop the <li> node kids
							for( var k=0; k<li_node.childNodes.length; k++) {
								var li_child = li_node.childNodes[k];
								switch(li_child.nodeName) {
									case 'A':
										// store the A node
										links[b] = li_child;
										links[b].onmouseover = clearTimer;	// these are the actions for <a>s that do not have a flyout menu
										links[b].onmouseout = setTimer;	// these are the actions for <a>s that do not have a flyout menu
										b++;
										break;
									case 'UL':
										var c = links.length - 1;	// get the last element in this array
										links[c].onmouseover = showFlyOutMenu;	// this <a> has a flyout menu and needs a different action than what was previously assigned
										links[c].onmouseout = setFlyOutTimer;	// this <a> has a flyout menu and needs a different action than what was previously assigned
										
										links[c].submenu = li_child;	// store the <ul>
										links[c].submenu.links = new Array(); 	// create an array to hold this submenu's links
										var flyout_link_index = 0;
										
										// loop the <ul>'s children
										var flyout_ul = li_child;
										for( var t=0; t<flyout_ul.childNodes.length; t++) {
											// if the node is a <li>
											if(flyout_ul.childNodes[i].nodeName == "LI" ) {	
												// get the <li> node
												var flyout_li = flyout_ul.childNodes[i];
												//loop the <li> node kids
												for( var s=0; s<flyout_li.childNodes.length; s++) {
													var flyout_node = flyout_li.childNodes[s];
													switch(flyout_node.nodeName) {
														case 'A':
															links[c].submenu.links[flyout_link_index] = flyout_node;
															links[c].submenu.links[flyout_link_index].onmouseover = clearAllTimers;
															links[c].submenu.links[flyout_link_index].onmouseout = setFlyOutTimer;
															flyout_link_index++;
															break;
													}
												}
											}
										}
										
										break;
								}
							}
						}
					}
					top_links[x].submenu.links = links;
					break;	
			}
		}
	}// end sub_nav_ids loop
	
	//last_menu_timer = num_menu_timers - 1;
	
}// end initHomePageSubNav

//----------------------------------------------------------------------------------------------------------------

function activateMenu() {
	// if there is already a top link and it is not the one we are over, hide it
	if(top_link && (top_link != this.top_link)) {
		clearAllTimers();
		//if (top_link.open_fly_out_menu) {
			hideFlyOutMenu();
		//}
		hideSubMenu();	
	}
	
	
	top_link = this;	
	showSubMenu();
}

function showSubMenu() {
	top_link.submenu.style.display = 'block';
	//this.submenu.style.display = 'block';
	clearTimer();
}

function showFlyOutMenu() {
	//this.submenu.style.display = 'block';

	top_link.open_fly_out_menu = this.submenu;
	top_link.open_fly_out_menu.style.display = 'block';


	clearTimer();
	//	top_link.fly_out_timer_id = this.timer_id;
	clearFlyOutTimer();
}

function hideSubMenu() {
	top_link.submenu.style.display = 'none';
	
}

function hideFlyOutMenu() {
	//test_form.trace.value = "\n hideFlyOutMenu" + test_form.trace.value;
	//test_form.trace.value = "\n     top_link.open_fly_out_menu " + top_link.open_fly_out_menu + test_form.trace.value;
	
	if (top_link.open_fly_out_menu) {
		top_link.open_fly_out_menu.style.display = 'none';
		top_link.open_fly_out_menu = null;
		top_link.fly_out_timer_id = -1;
	}
}

function setTimer() {
	top_link.timer_id = window.setTimeout( 'hideSubMenu()', menu_delay);
	
	
}

function setFlyOutTimer() {
	//test_form.trace.value = "\n setFlyOutTimer" + test_form.trace.value;
	//test_form.trace.value = "\n     " + this.submenu + test_form.trace.value;

	
	if (this.submenu) {
		top_link.open_fly_out_menu = this.submenu;
	} else {
		var li_node = this.parentNode;
		top_link.open_fly_out_menu = li_node.parentNode;
	}
	
	//test_form.trace.value = "\n     top_link.open_fly_out_menu " + top_link.open_fly_out_menu + test_form.trace.value;
	

	top_link.fly_out_timer_id = window.setTimeout( 'hideFlyOutMenu()', menu_delay);
	
	setTimer();
}

function clearAllTimers() {
	//alert('clearAllTimers');
	clearTimer();
	clearFlyOutTimer();
}

function clearTimer() {
	window.clearTimeout(top_link.timer_id);
	top_link.timer_id = -1;
	
	
}

function clearFlyOutTimer() {
	window.clearTimeout(top_link.fly_out_timer_id);
	top_link.fly_out_timer_id = -1;
	
	
}










