// when the page has loaded
Event.observe(window, 'load', function() {

	// the page is, by default, reset to show the relevant second-level navigation
	var nav_reset = true;

	// for each of the top level navigation
	$$('#nav ul li').each( function(nav) {
		
		// include the current page alternative ones as well
		var nav2 = 'nav2_' + nav.id.replace(/_onpage/,'');
		
		// when we rollover the top-level then show the second nav
		Event.observe(nav, 'mouseover', function(e) {
			var elem = Event.element(e);
			var nav = elem.up('li');
			var nav2 = 'nav2_' + nav.id.replace(/_onpage/,'');

			// if this top-level nav has a second-level nav
			if ($(nav2) != null) {
				// show the second-level nav
				$(nav2).show();
			}
			
			// hide all the other second-levels
			$$('#nav2 ul').each( function(ul) {
				if (ul.id != nav2) {
					ul.hide();
				}
			});

			// the page is now not in its normal state
			nav_reset = false;
			
		});
			
	});
	
	// when we rollover the body, if we haven't already, hide all second-levels
	// and show the default second-level
	Event.observe('body', 'mouseover', function(e) {
		if (!nav_reset) {
			$$('#nav2 ul').each( function(ul) {
				if (ul.id != nav_default) {
					ul.hide();
				}
			});
			if ($(nav_default)) $(nav_default).show();
			nav_reset = true;
		}
	});
	
});
