// function to find horizontal position of an element
function findPosX(obj) {
	var curleft = 0;
	if (obj.offsetParent) {
  		while (obj.offsetParent) {
   			curleft += obj.offsetLeft
  			obj = obj.offsetParent;
  		}
 	}
 	else if (obj.x)
 		curleft += obj.x;
 	return curleft;
} 

function centerMenu() {
	var activeA, theWidth, actWidth, actPlace, windowWidth;
	mainMenuAct = document.getElementById('mainMenu');
	if (mainMenuAct != null)
	{
		activator = mainMenuAct.getElementsByTagName('a');
		// find active link in main menu
		for(var i = 0; i < activator.length; i++) {
			if (activator[i].className == 'tab_hi') {
				activeA = activator[i];
			}
		}
		// get the width of the submenu
		submenuDiv = document.getElementById('placer');
		if (submenuDiv!=null) {
			if(navigator.appName.indexOf("Netscape")>(-1)){
				theWidth = 1;
				submenus = submenuDiv.getElementsByTagName('a');
				for(var i = 0; i < submenus.length; i++) {
					theWidth += submenus[i].offsetWidth;
				}
				windowWidth = document.body.offsetWidth + 1;
			} else {
				theWidth = submenuDiv.offsetWidth;
				windowWidth = document.body.offsetWidth - 20; 
			}
			if (activeA!=null && activeA!="") {
				actWidth = activeA.offsetWidth;
				actPlace = findPosX(activeA) + 0.5*actWidth; 
				// check if submenuplacement exceeds left of screen
				if (parseInt(actPlace - 0.5*theWidth)<0) {
					document.getElementById('dummy').style.display = 'none';
				// check if submenuplacement exceeds right of screen
				} else if (parseInt(actPlace + 0.5*theWidth)>windowWidth) {
					submenuDiv.style.paddingLeft = parseInt(windowWidth - theWidth) -1 + 'px';
				} else {
					submenuDiv.style.paddingLeft = (parseInt(actPlace - 0.5*theWidth)<0) ? -1 + 'px' : parseInt(actPlace - 0.5*theWidth) + 'px';
				}
			} else {
				actWidth = 0;
			}
		}
	}
}
