window.onload = function() {
	if (!cssQuery) return;
	if (navigator.platform == 'MacPPC' && navigator.appName == 'Microsoft Internet Explorer') return;
	
	var menus = cssQuery('#topnav > ul > li, #mininav > ul > li');
	for (var i = 0; i < menus.length; i++) {

		// for mouseover-activated menus in IE (others covered by CSS)
		if (navigator.appName == 'Microsoft Internet Explorer' && navigator.userAgent.indexOf('Opera') == -1) {
			menus[i].onmouseover = function() { this.className = 'scriptfocus'; };
			menus[i].onmouseout = function() { this.className = ''; };
			}
		
		// for keyboard-activated menus in all browsers
		// var focusHandler = makeFocusHandler(menus[i]);
		// var blurHandler = makeBlurHandler(menus[i]);
		// var anchors = cssQuery('a', menus[i]);
		// for(var j = 0; j < anchors.length; j++) {
		// 	anchors[j].onfocus = focusHandler;
		// 	anchors[j].onblur = blurHandler;
		//	}

		}
	
	// adjust right edge of mininav menus
	var bodyRight = document.getElementById('body').offsetWidth + absoluteLeft(document.getElementById('body'));
	var menu_uls = cssQuery('#mininav > ul > li > ul');
	for (var i = 0; i < menu_uls.length; i++) {
		var menuRight = menu_uls[i].offsetWidth + absoluteLeft(menu_uls[i]);
		if (menuRight > bodyRight) menu_uls[i].style.left = -(menuRight-bodyRight)+"px";
		}

	};

function makeFocusHandler(e) {
	return function() {
		if (e.menuTimer != null) {
			window.clearTimeout(e.menuTimer);
			e.menuTimer = null;
			}
		e.className = 'scriptfocus';
		};
	}

function makeBlurHandler(e) {
	return function() {
		// defer closing the menu, otherwise the links in the menus will be skipped
		e.menuTimer = window.setTimeout(function () { e.className = '' }, 0);
		}
	}

function absoluteLeft(e) {
	return e.offsetLeft + (e.offsetParent ?  absoluteLeft(e.offsetParent) : 0);
	}
