//.....................................
//...tabbedMenuVars.js must be included before this module.
//...Non-configurable global variables and state variables
//.....................................
var timeBeforeAutoHide = 2000;			// Microseconds from mouse leaves menu to auto hide.
var currentZIndex = 1000;				// High z-index value to assure menuitems stay visible
var shimZIndex = 500;					// Middle z-index value to keep shims under menus but on top of page elements.
var tabbedMenuDiv;						// The main menu div
var visibleMenus = new Array();			// State: array holding the currently displayed menu
var visibleShims = new Array();			// State: array holding the shim for the currently displayed menu
var visibleTitles = new Array();		// State: array holding the shim for the currently displayed menu
var currentScroll = null;				// State: how many times the menu has been scrolled to the left
var needInit = true;					// State: flag for initialization. After init is set to false
var activeMenuItem = null;				// State: the active menu item
var activeSubMenuItem = null;			// State: the active submenu item
var currentTabId = null;				// State: the id of the currently selected main menu item (tab)
var currentSubMenuItemId = null;		// State: the id of the currently selected submenu item
var mainMenuItemClickToggle = "closed";	// State: allow opening and closing of menu onclick
var clickedMainMenuItemId = null;		// State: id of menuitem that was last clicked

var submenuMaxHeight = 10000; // st- Maximum height of submenus
var oldMax = 10000; // st- Maximum height of submenus before resize


//.............................................................................
//...Calc total submenu width from configurable values in tabbedMenuVars.js
//.............................................................................
var totalSubmenuWidth = 
	submenuItemWidth + submenuItemPaddingLeft + submenuItemPaddingRight + (submenuItemBorder*2) + (submenuBorder*2);

var innerSubmenuWidth = 
	submenuItemWidth + submenuItemPaddingLeft + submenuItemPaddingRight + (submenuItemBorder*2);
	
var outerSubmenuWidth = 	
	submenuItemWidth + (submenuBorder*2);

//...............................................
//...Minimal browser detections
//...............................................
var IE = (navigator.appName == 'Microsoft Internet Explorer') ? true : false;

//...............................................
//...Utility functions for submenu positioning
//...............................................
function getTopPos (inputObj) {
	var returnValue = inputObj.offsetTop + tabHeight;
	return returnValue;
}
function getLeftPos (inputObj) {
	// If menu won't go past available width, left justfify it on the tab's left edge.
	// Otherwise right justify it on the tab's right edge.
	if (inputObj.offsetLeft + totalSubmenuWidth < document.body.offsetWidth) {
		returnValue = 0;
	} else {
		if (!IE) {
			returnValue = tabWidth - totalSubmenuWidth;
		} else {
			returnValue = tabWidth - outerSubmenuWidth;
		}
	}
	return returnValue;
}


//...............................................
//...Event handler for main menu item clicks
//...Set via onclick in html. Is not passed an event parameter.
//...............................................
function mainMenuItemClick (id) {
	var mainMenuItem = document.getElementById(id);
	if (mainMenuItem) {
		if (mainMenuItem.id == clickedMainMenuItemId) {
			if (mainMenuItemClickToggle == "open") {		
				mainMenuItemClickToggle = "closed";
				clickedMainMenuItemId = null;
				menuActive = false;
				autohideMenuItems();
			} else {
				mainMenuItemClickToggle = "open";
				clickedMainMenuItemId = mainMenuItem.id;
				showSubMenu(mainMenuItem);
			}
		} else {
			mainMenuItemClickToggle = "open";
			clickedMainMenuItemId = mainMenuItem.id;
			showSubMenu(mainMenuItem);
		}
	}
	return false;
}
//...............................................
//...Event handler for main menu item rollovers
//...Set in js for li objects. Event object is passed.
//...............................................
function mainMenuItemOver (evt) {
	// Get the last element encountered before our element.
	// Filter events coming from submenu items (since they're our children)
	if (!evt) evt = window.event;
	var relTarg = evt.relatedTarget || evt.fromElement;		// W3C vs IE
	if (relTarg) {
		if (relTarg.id.search(/smli/) != -1 || relTarg.id.search(/sma/) != -1) {
			return;
		}
	}
	if (this) {
		showSubMenu(this);
	}
}
//...............................................
//...Show the submenu
//...............................................
function showSubMenu (mainMenuItem) {



	// If we're switching menus, change the css class and reset the global activeMenuItem
	if (activeMenuItem && activeMenuItem != mainMenuItem) {
		if (activeMenuItem.id == currentTabId) {
			// st activeMenuItem.className = activeMenuItem.className = 'tab_current';		
		} else {
			// st need a tag for flicker solution
	        var numericIdThis = activeMenuItem.id.replace(/[^0-9]/g,'');
	        var st_a_tag = document.getElementById('mma' + numericIdThis);
			// change this:
			//    activeMenuItem.className = activeMenuItem.className = 'tab';
			// to:
			st_a_tag.className = st_a_tag.className = 'tabtoplayer';
		}
	}
	activeMenuItem = mainMenuItem;

	// Hide any active submenu items by changing the css class
	if (activeSubMenuItem) {
            if (activeSubMenuItem.id == currentSubMenuItemId) {
			    //st this is the current item in the currently selected part
				activeSubMenuItem.className = activeSubMenuItem.className = 'submenuitem_current';		
			} else if (activeMenuItem.id == currentTabId) {
			    //st these are the unselected children of the currently selected part
			    activeSubMenuItem.className = activeSubMenuItem.className = 'MYPsubmenuitem';	
			} else {
			    //st these are the children of the other parts
				//   none of which can be selected, since we're not
				//   in their part parents
				activeSubMenuItem.className = activeSubMenuItem.className = 'submenuitem';		
			}
	}
	
	
	// Get just the number part of the id
	// st moved up for flicker issue
	var numericIdThis = activeMenuItem.id.replace(/[^0-9]/g,'');
	
	// Set our css class to rollover
	// st - if below added to avoid rollover for current item
	if (currentTabId != activeMenuItem.id) {
	     // st for flicker issue change:
		 //     activeMenuItem.className = 'tab_over';
		 // to:
		 var st_a_tag = document.getElementById('mma' + numericIdThis);
	     if (st_a_tag) {
		       st_a_tag.className = 'tab_over';
	     }
	}
	
	// Get just the number part of the id
	var numericIdThis = activeMenuItem.id.replace(/[^0-9]/g,'');

	// Show our submenu
	var exceptionArray = new Array();
	var sub = document.getElementById('subOf' + numericIdThis);
	if (sub) {
		visibleMenus.push(sub);
		// workaround for firefox which has not yet set this width based on its children
		if (sub.offsetWidth == activeMenuItem.offsetWidth) {
			sub.style.width = innerSubmenuWidth;
		}

		sub.style.display = 'block';
		

		
		// st - find out if we need to scroll and scroll:
		
		// need to detect lower window scroll bar to see how 
		// long the menu can be:
		if (document.body.clientWidth < document.body.scrollWidth) {
		     submenuMaxHeight = document.body.offsetHeight - 167; 
        // topnav + bottom horizontal scroll = 167
		} else {
		     submenuMaxHeight = document.body.offsetHeight - 150;
		}
		
		if (submenuMaxHeight > oldMax) {
	         //reset width and height that were
		     //set below with a smaller screen size
	         sub.style.width = 'auto';
		     sub.style.height = 'auto';
		     sub.style.overflow = 'visible';
		}
		
        if (sub.offsetHeight > submenuMaxHeight) {
             sub.style.height = submenuMaxHeight + 'px';
			 if (IE) {
                 sub.style.width = outerSubmenuWidth + 17 + 'px';
			 } else {
			     sub.style.width = totalSubmenuWidth + 23 + 'px';
			 }
             sub.style.overflow = 'auto';
			 
			 // move this into the style sheet
             sub.style.background = "#FFFFFF";
        }
		
		// st - end added scroll code

		
		exceptionArray[sub.id] = true;
	}	
	
	// Show the shim for the submenu
	var shimExceptionArray = new Array();
	var shim = document.getElementById('shimOf' + numericIdThis);
	if (shim) {
		visibleShims.push(shim);
		shim.style.width = sub.offsetWidth;
		shim.style.height = sub.offsetHeight;
		shim.style.display = 'block';
		shim.style.visibility = 'visible';
		shimExceptionArray[shim.id] = true;
	}
	
	// Show the part title in the banner
	var titleExceptionArray = new Array();
	var title = document.getElementById('title' + numericIdThis);
	if (title) {
		visibleTitles.push(title);
		title.style.display = 'block';
		title.style.visibility = 'visible';
		titleExceptionArray[title.id] = true;
	}
	
	// Hide other shims, but not ours
	hideShims(shimExceptionArray);

	// Hide other submenus, but not ours
	hideMenuItems(exceptionArray);

	// Hide other titles, but not ours
	hideTitles(titleExceptionArray);
}
//...............................................
//...Event handler for submenu item (LI) rollovers
//...............................................
function subMenuItemOver (evt) {
	if (this) {
		// Set global activeSubMenuItem variable
		if (activeSubMenuItem) {
			if (activeSubMenuItem != this) {
                if (activeSubMenuItem.id == currentSubMenuItemId) {
			    //st this is the current item in the currently selected part
				activeSubMenuItem.className = activeSubMenuItem.className = 'submenuitem_current';		
			    } else if (activeMenuItem.id == currentTabId) {
			    //st these are the unselected children of the currently selected part
			    activeSubMenuItem.className = activeSubMenuItem.className = 'MYPsubmenuitem';	
			    } else {
			    //st these are the children of the other parts
				//   none of which can be selected, since we're not
				//   in their part parents
				activeSubMenuItem.className = activeSubMenuItem.className = 'submenuitem';		
			    }
			}
		}
		
		activeSubMenuItem = this;

		// Set our css class to rollover
		
		if (activeMenuItem.id == currentTabId) {
		     activeSubMenuItem.className = 'MYPsubmenuitem_over';
		} else {
		     activeSubMenuItem.className = 'submenuitem_over';
		}
		
	}
}
//....................................................
//...Hide visible menu items, except those in input array
//....................................................
function hideMenuItems (exceptionArray) {
	var newVisibleMenuArray = new Array();
	for (var i=0; i<visibleMenus.length; i++){
		if (visibleMenus[i].className != 'menuBlock1' && visibleMenus[i].id) {
			if (!exceptionArray[visibleMenus[i].id]) {
				visibleMenus[i].style.display = 'none';
				var li = document.getElementById('mmli' + visibleMenus[i].id.replace(/[^0-9]/g,''));
				
				// st line below for flicker issue
				var li_a = document.getElementById('mma' + visibleMenus[i].id.replace(/[^0-9]/g,''));
				
				if (li.className.indexOf('over') > 0) {
					if (li.id == currentTabId) {
					    // st line below hides non-hightlight over image
						// actually let's avoid adding it at all instead
					    // li_a.className = li_a.className = 'tab_over';
						//li.className = li.className = 'tab_current';		
					} else {
					    // st line below adds a top layer non=hightlight image
					    li_a.className = li_a.className = 'tabtoplayer';
						// st tab class now holds highlight image
						// li.className = li.className = 'tab';
					}
				}
               if (activeSubMenuItem) {
			        if (activeSubMenuItem.id == currentSubMenuItemId) {
			            //st this is the current item in the currently selected part
				        activeSubMenuItem.className = activeSubMenuItem.className = 'submenuitem_current';		
			        } else if (activeMenuItem.id == currentTabId) {
			            //st these are the unselected children of the currently selected part
			            activeSubMenuItem.className = activeSubMenuItem.className = 'MYPsubmenuitem';	
			        } else {
			            //st these are the children of the other parts
				        //   none of which can be selected, since we're not
				        //   in their part parents
				        activeSubMenuItem.className = activeSubMenuItem.className = 'submenuitem';		
			       }
	           }
			} else {				
				newVisibleMenuArray.push(visibleMenus[i]);
			}
		}
	}		
	visibleMenus = newVisibleMenuArray;		
}
//....................................................
//...Hide shims, except those in input array
//....................................................
function hideShims (shimExceptionArray) {
	var newVisibleShimArray = new Array();
	for (var i=0; i<visibleShims.length; i++){
		if (visibleShims[i].id) {
			if (!shimExceptionArray[visibleShims[i].id]) {
				visibleShims[i].style.display = 'none';
			} else {				
				newVisibleShimArray.push(visibleShims[i]);
			}
		}
	}		
	visibleShims = newVisibleShimArray;		
}
//....................................................
//...Hide dynamic text strings, except those in input array
//....................................................
function hideTitles (titleExceptionArray) {
	var newVisibleTitleArray = new Array();
	for (var i=0; i<visibleTitles.length; i++){
		if (visibleTitles[i].id) {
			if (!titleExceptionArray[visibleTitles[i].id]) {
				visibleTitles[i].style.display = 'none';
			} else {				
				newVisibleTitleArray.push(visibleTitles[i]);
			}
		}
	}		
	visibleTitles = newVisibleTitleArray;		
}
//.....................................
//...Main menu mouse events
//...timer function for submenu display
//.....................................
var menuActive = true;
var hideTimer = 0;
function mouseOverMenu () {
	menuActive = true;		
}

function mouseOutMenu () {
	menuActive = false;
	timerAutoHide();	
}

// Workaround for Firefox
function iframeMouseOver () {
	mouseOutMenu();
}

function timerAutoHide () {
	if (menuActive){
		hideTimer = 0;
		return;
	}
	
	if (hideTimer < timeBeforeAutoHide) {
		hideTimer += 100;
	    setTimeout('timerAutoHide()', 99);
	} else {
		hideTimer = 0;
		autohideMenuItems();	
	}
}

function autohideMenuItems () {
	if (!menuActive){
		hideMenuItems(new Array());	
		hideShims(new Array());	
		hideTitles(new Array());	
		if (activeMenuItem) {
			if (activeMenuItem.id == currentTabId) {
				//activeMenuItem.className = activeMenuItem.className = 'tab_current';		
			} else {
				
				 var numericIdThis = activeMenuItem.id.replace(/[^0-9]/g,'');
	             var st_a_tag = document.getElementById('mma' + numericIdThis);
			     // change this:
			     //    activeMenuItem.className = activeMenuItem.className = 'tab';	
			     // to:
			     st_a_tag.className = st_a_tag.className = 'tabtoplayer';	
			}
		}
		if (activeSubMenuItem) {
			if (activeSubMenuItem.id == currentSubMenuItemId) {
			    //st this is the current item in the currently selected part
				activeSubMenuItem.className = activeSubMenuItem.className = 'submenuitem_current';		
			} else if (activeMenuItem.id == currentTabId) {
			    //st these are the unselected children of the currently selected part
			    activeSubMenuItem.className = activeSubMenuItem.className = 'MYPsubmenuitem';	
			} else {
			    //st these are the children of the other parts
				//   none of which can be selected, since we're not
				//   in their part parents
				activeSubMenuItem.className = activeSubMenuItem.className = 'submenuitem';		
			}
		}
	}
}
//....................................................
//...Submenu positioning for already existent submenus
//....................................................
function positionSubMenu (inputObj, initOffsetLeft) {	
	var numericId = inputObj.id.replace(/[^0-9]/g,'');
	var subUl = document.getElementById('subOf' + numericId);
	var topPos = getTopPos(inputObj);
	var leftPos = getLeftPos(inputObj)/1 + initOffsetLeft/1;			
	subUl.style.position = 'absolute';
	subUl.style.left = leftPos + 'px';
	subUl.style.top = topPos + 'px';

	var shim = document.getElementById('shimOf' + numericId);
	if (shim) {
		shim.style.top = subUl.style.top;
		shim.style.left = subUl.style.left;
		shim.style.zIndex = shimZIndex;
	}
}
//.....................................
//...Submenu initialization 
//.....................................
function initSubMenu (inputObj, initOffsetLeft) {	

	var numericId = inputObj.id.replace(/[^0-9]/g,'');

	// init submenu ul
	var subUl = document.getElementById('subOf' + numericId);
	if (subUl) {
	
	    // st separate classes for current part's pulldown
		if (inputObj.id == currentTabId) {
		    subUl.className = 'MYPmenuBlock2';
		} else {
		    subUl.className = 'menuBlock2';
		}
		subUl.onmouseover = mouseOverMenu;
		subUl.onmouseout = mouseOutMenu;
		currentZIndex += 1;
		subUl.style.zIndex = currentZIndex;
		var topPos = getTopPos(inputObj);
		var leftPos = getLeftPos(inputObj)/1 + initOffsetLeft/1;			
		subUl.style.position = 'absolute';
		subUl.style.left = leftPos + 'px';
		subUl.style.top = topPos + 'px';

		// init submenu items
		var li = subUl.getElementsByTagName('LI')[0];
		while (li){
			if (li.tagName == 'LI') {	
				li.className='submenuitem';
				if (inputObj.id == currentTabId) {
		            li.className = 'MYPsubmenuitem';
		        }
				if (li.id == currentSubMenuItemId) {
					li.className = 'submenuitem_current';
				}

				li.onmouseover = subMenuItemOver;
			}
			li = li.nextSibling;
		}
		subUl.style.display = 'none';	
	}
	// init shim
	var shim = document.getElementById('shimOf' + numericId);
	if (shim) {
		shim.style.top = subUl.style.top;
		shim.style.left = subUl.style.left;
		shim.style.zIndex = shimZIndex;
		shim.style.display = 'none';
	}
	
	// init dynamic text title
	var title = document.getElementById('title' + numericId);
	if (title) {
		title.style.display = 'none';
	}
}
//.........................................................
//...Entry point: called from onload or after scroll event
//.........................................................
function initTabbedMenu (tabId, subMenuItemId) {

	// Get main menu object
	tabbedMenuDiv = document.getElementById('tabbedMenu');
	if (!tabbedMenuDiv) return false;

	// div initially located off the page to avoid hidden elements overlapping iframe below
	tabbedMenuDiv.style.top = '0px';
	tabbedMenuDiv.style.left = '0px';
	tabbedMenuDiv.style.visibility = 'visible';

	if (needInit) {
		// Set global currently selected tab and subvolume ids
		if (tabId) { currentTabId = tabId; }
		if (subMenuItemId) { currentSubMenuItemId = subMenuItemId; }

		// If there is a current tab selected, set currentScroll from cookie
		if (tabId) {
			currentScroll = parseInt(getCurrentScroll(), 10);
		} else {
			currentScroll = 0;
			saveCurrentScroll(currentScroll);
		}
	}
	
	// Set up main menu
	var mainMenu = tabbedMenuDiv.getElementsByTagName('UL')[0];
	if (needInit) {
		mainMenu.className = 'menuBlock1';
		mainMenu.style.zIndex = currentZIndex;
		mainMenu.onmouseover = mouseOverMenu;
		mainMenu.onmouseout = mouseOutMenu;

		if (!IE) {
		    // Workaround for Firefox. Need to hide menu when 
			// slide from menu to iframe. Event propagation issue.
		    var contentIframe = document.getElementById('content');
		    if (contentIframe) 	contentIframe.onmouseover = iframeMouseOver;
		    var leftnavIframe = document.getElementById('navbar');
			if (leftnavIframe) leftnavIframe.onmouseover = iframeMouseOver;
		}
	}

	// Display main menu items
	var offLeft = initialTabOffset;	// pixel offset for positioning menu items
	var columnIdx = 0;				// considering each tab (or prev/next button) a column
	var mainMenuItemIdx = 0;		// index of main menu items
	
	// Get first main menu item
	var mainMenuItem = mainMenu.getElementsByTagName('LI')[0];

	// Display the menu
	while (mainMenuItem && (columnIdx < numColumns)) {
		// First column: either first item or previous button
		if (mainMenuItemIdx == 0) {
			if (currentScroll == 0) {
				initMainMenuItem(mainMenuItem, offLeft);		
				mainMenuItem = getNextMainMenuItem(mainMenuItem);
				mainMenuItemIdx++;
				offLeft += tabWidth;
				columnIdx++;
				continue;
			} else {
				initScrollButton('prev', offLeft);
				mainMenuItem = getNextMainMenuItem(mainMenuItem);
				mainMenuItemIdx++;
				offLeft += scrollButtonWidth;
				columnIdx++;
				continue;
			}
		}	
		// Last column: either last item or next button
		if (columnIdx == numColumns-1) {
			if (getNextMainMenuItem(mainMenuItem) == null) {
				// Last menu item
				initMainMenuItem(mainMenuItem, offLeft);		
				break;
			} else {
				initScrollButton('next', offLeft);
				break;
			}
		}
		// Middle columns
		if (mainMenuItemIdx > currentScroll) {
			initMainMenuItem(mainMenuItem, offLeft);		
			mainMenuItem = getNextMainMenuItem(mainMenuItem);
			mainMenuItemIdx++;
			offLeft += tabWidth;
			columnIdx++;
		} else {
			// Skip this one, it's been scrolled past
			mainMenuItem = getNextMainMenuItem(mainMenuItem);
			mainMenuItemIdx++;
		}
	}
	
	needInit = false;	
}
//.........................................................
//...Iterator to get next LI in list of siblings
//.........................................................
function getNextMainMenuItem (currentMainMenuItem) {
	
	var mainMenuItem = currentMainMenuItem.nextSibling;
	while (mainMenuItem) {
		if (mainMenuItem.tagName == 'LI') {
			return mainMenuItem;
		} else {
			return getNextMainMenuItem(mainMenuItem);
		}
	}
	return null;
}
//..........................................
//...Initialization for prev or next buttons
//..........................................
function initScrollButton (id, offLeft) {
	var buttonDiv = document.getElementById(id);
	if (buttonDiv) {
		buttonDiv.style.visibility = 'visible';
		var buttonObj = buttonDiv.getElementsByTagName('A')[0];
		if (buttonObj) {
			buttonObj.style.position = 'absolute';
			buttonObj.style.top = '0px';
			buttonObj.style.left = offLeft + 'px';
			buttonObj.style.visibility = 'visible';
		}
	}
}
//...............................................
//...Initialization for main menu item objects
//...............................................
function initMainMenuItem (mainMenuItem, offLeft) {
	// st this is now the rollover highlight
	mainMenuItem.className = 'tab';
	
	//st get a tag object as well for flicker issue
	var numericIdThis = mainMenuItem.id.replace(/[^0-9]/g,'');
	var st_a_tag = document.getElementById('mma' + numericIdThis);

	
	if (mainMenuItem.id == currentTabId) {
	    // this is instead of 'tab' it is the highlighted
		// current image
		// it never gets covered by tabtoplayer
		mainMenuItem.className = 'tab_current';
	} else {
	     if (st_a_tag) {
		      // st this is now the default, goes over 
			  // the rollover highlight
              st_a_tag.className = 'tabtoplayer';
	     }
	}
	mainMenuItem.onmouseover = mainMenuItemOver;
	mainMenuItem.style.position = 'absolute';
	mainMenuItem.style.top = '0px';
	mainMenuItem.style.left = offLeft + 'px';
	mainMenuItem.style.visibility = 'visible';
	mainMenuItem.style.display = 'block';
	if (!mainMenuItem.doneinit) {
		initSubMenu(mainMenuItem, 0);
		mainMenuItem.doneinit = 'true';
	} else {
		positionSubMenu(mainMenuItem, 0);
	}
}	
//.....................................
//...Hide prev or next buttons
//.....................................
function hideScrollButton (id) {
	var buttonDiv = document.getElementById(id);
	if (buttonDiv) {
		buttonDiv.style.visibility = 'hidden';
		var buttonObj = buttonDiv.getElementsByTagName('A')[0];
		if (buttonObj) {
			buttonObj.style.visibility = 'hidden';
		}
	}
}
//.....................................
//...Hide all tabs
//.....................................
function hideMainMenuItems () {
	var mainMenu = tabbedMenuDiv.getElementsByTagName('UL')[0];
	var mainMenuItem = mainMenu.getElementsByTagName('LI')[0];
	while (mainMenuItem) {
		mainMenuItem.style.visibility = 'hidden';
		//st used with prev and next, removing fully:
		mainMenuItem.style.display = 'none';
		
		mainMenuItem = getNextMainMenuItem(mainMenuItem);
	}
}
//.....................................
//...Event handler for prev button [<<]
//.....................................
function doPrev () {
	hideScrollButton('prev');
	hideScrollButton('next');
	hideMainMenuItems();
	currentScroll--;			// Decrement current scroll value
	saveCurrentScroll(currentScroll);
	initTabbedMenu();
}
//.....................................
//...Event handler for next button [>>]
//.....................................
function doNext () {
	hideScrollButton('prev');
	hideScrollButton('next');
	hideMainMenuItems();
	currentScroll++;			// Increment current scroll value
	saveCurrentScroll(currentScroll);
	initTabbedMenu();
}
//.............................................................................
//...Event handler for onResize; Reposition submenus for justfication logic
//.............................................................................
function repositionSubmenus () {
	var mainMenu = tabbedMenuDiv.getElementsByTagName('UL')[0];
	var mainMenuItem = mainMenu.getElementsByTagName('LI')[0];
	while (mainMenuItem) {
		if (mainMenuItem.tagName == 'LI') {
			if (mainMenuItem.doneinit) {
				positionSubMenu(mainMenuItem, 0, 2);
					
				// st test - must be here so that menus aren't
				// refreshed on move back from scroll bar
				var numericIdThis = activeMenuItem.id.replace(/[^0-9]/g,'');
	            var sub = document.getElementById('subOf' + numericIdThis);
				sub.style.display = 'block';
	            sub.style.width = 'auto';
		        sub.style.height = 'auto';;
				sub.style.overflow = 'visible';
	            // end st test
				
			}
		}
		mainMenuItem = getNextMainMenuItem(mainMenuItem);
	}
	oldMax = submenuMaxHeight; // st - record old max height
	

	
}

window.onresize = repositionSubmenus;

//.............................................................................
//...Persist current scroll position via cookie. Note path. May have to regex to be more specific 
//.............................................................................
function saveCurrentScroll (currentScroll) {
	document.cookie = "currentScroll=" + escape(currentScroll) + '; path=/';
}
//.............................................................................
//...Get currentScroll value from cookie
//.............................................................................
function getCurrentScroll () {
	var label = "currentScroll=";
	var labelLen = label.length;
	var cLen = document.cookie.length;
	var i = 0;
	while (i < cLen) {
		var j = i + labelLen;
		if (document.cookie.substring(i,j) == label) {
			var cEnd = document.cookie.indexOf(";",j);
			if (cEnd ==	-1) {
				cEnd = document.cookie.length;
			}
			return unescape(document.cookie.substring(j,cEnd));
		}
		i++;
	}
	return "0";
}
//.............................................................................
//...Debugging aid: log messages to textarea
//.............................................................................
function logIt(str) {
	window.content.document.forms['testform'].elements[0].value = str + '\n' + 
	window.content.document.forms['testform'].elements[0].value;
}
