// Compile the static menu headings:

menutxt += '<div id="LinkBar">\n';
for(i=1;i<=totalmenus;i++){
		// Increment the tabindex counter for every link
		tabcount++;
		menutxt += '\t<div id="Link' + i + '">';

		if(menu[i].MenuURL==''){
			menutxt += '<a ';
		}
		else{
			menutxt += '<a href="' + menu[i].MenuURL + '"';
		}


		// Add an explicit tab sequence
		menutxt += ' tabindex="' + tabcount + '"';

		// Only compile the event handlers if able to handle them
		if(document.getElementById){// DOM1 compliant
			menutxt += ' onmouseover="menuOver(\'Menu' + i + '\'); return true;"';
			// To activate via tab navigation
			menutxt += ' onfocus="menuOver(\'Menu' + i + '\'); return true;"';
			menutxt += ' onmouseout="menuOut(\'Menu' + i + '\'); return true;"';
			// To de-activate when tab focus is lost
			menutxt += ' onblur="menuOut(\'Menu' + i + '\'); return true;"';

			// Increment the tabindex to allow for the bullets
			tabcount += menu[i].Bullet.size;
		}

		menutxt += '>' + menu[i].MenuTitle + '</a>';
		menutxt += '<\/div>\n';
	}
menutxt += '<\/div>\n';

// If DOM1 compliant, add the
// drop-down menus:

if(document.getElementById){// DOM1 compliant
	// Reset the tab counter
	tabcount = 0;
	menutxt += '<div id="MenuBar">\n';
	for(i=1;i<=totalmenus;i++){
		// Increment the tab counter
		tabcount++;
		menutxt += '<div id="Menu' + i + '">';
		// Build the bullet list
		menutxt += '<ul type="square">\n\t';
		for(j=1;j<=menu[i].size;j++){
			// Increment the tab couter
			tabcount++
			menutxt += '<li><a href="' + menu[i].Bullet[j].BulletURL + '"';
			menutxt += ' onmouseover="stayOpen(\'Menu' + i + '\'); return true;"';
			menutxt += ' onfocus="stayOpen(\'Menu' + i + '\'); return true;"';
			menutxt += ' onmouseout="menuOut(\'Menu' + i + '\'); return true;"';
			menutxt += ' onblur="menuOut(\'Menu' + i + '\'); return true;"';
			// Add an explicit tab sequence
			menutxt += ' tabindex="' + tabcount + '"';
			menutxt += '>' + menu[i].Bullet[j].BulletTitle;
			menutxt += '<\/a><\/li>\n\t';
		}
		menutxt += '<\/ul>\n<\/div>\n';
	}
	menutxt += '<\/div>\n';
}

// Global menu element handle:

var LiveMenu = null;

// Global menu timeout handle:

var Timeout_ID = null;

// Opens or keeps open a given menu
// and shuts any previous menu:

function menuOver(MenuID){
	// If DOM1 supported and element exists ...
	if((document.getElementById)&&(document.getElementById(MenuID)!=null)){
		// If this menu is already open ...
		if(LiveMenu==document.getElementById(MenuID)){
			// Do not close it
			clearTimeout(Timeout_ID);
		}
		// Another menu might still be open ...
		else{
			// If another menu is open ...
			if(LiveMenu!=null){
				// Do not wait, shut it down now
				clearTimeout(Timeout_ID);
				hideNow();
			}
		}
		// This is the new 'live' menu, make it visible
		LiveMenu = document.getElementById(MenuID);
		// LiveMenu.style.visibility is
		// initially empty in IE5 until
		// it is assigned by these
		// functions, so must check that
		// it's not null before proceeding...
		if((LiveMenu.style)&&(LiveMenu.style.visibility!=null)){
			LiveMenu.style.visibility = 'visible';
		}
	}
}

// Stops menu links from opening menu
// onmouseover when shut to
// workaround mouse events which are
// not hidden by z-index in Opera 4!

function stayOpen(MenuID){
	// If menuOver has not been called or the menu is hidden, do nothing
	if((LiveMenu==null)||((LiveMenu.style)&&(LiveMenu.style.visibility)&&(LiveMenu.style.visibility=='hidden')))return;
	else menuOver(MenuID);
}

// Shuts a given menu in 250
// milliseconds, unless timeout is
// cleared by menuOver()

function menuOut(MenuID){
	// If DOM1 supported and a menu is open ...
	if((document.getElementById)&&(document.getElementById(MenuID)!=null)){
		// Get the current live menu
		LiveMenu = document.getElementById(MenuID);
		// Prepare to shut it in 250 milliseconds
		Timeout_ID = window.setTimeout('hideNow();',250);
	}
}

// Called by menu handlers to shut
// previous menu immediately

function hideNow(){
	if((LiveMenu.style)&&(LiveMenu.style.visibility)){
		LiveMenu.style.visibility = 'hidden';
	}
}