var executer;
var startHandlersLoaded = 0;

function displayMenu(menuId, position) {
		hideMenus();
		var menu = $(menuId);
		if (menu) {
				menu.style.display	= 'block';
				menu.style.left		= position * 114.5 + 'px';
		}
}

function hideMenus() {
		var menus = $$('.submenu');
		menus.each(function(menu){
						menu.style.display = 'none';
						});
		highlightCurrent();
}

function currentPage() {
		return location.href.substring(location.href.lastIndexOf('/')+1);
}

function highlightCurrent() {
		var menus = $$('.menuItem');
		menus.each(function(menu) {
				if (menu.id + '.shtml' == currentPage()) {
						var imgname = 'sub_nav_' + menu.id + '_off';
						var imgfile = '/en/images/sub_nav_' + menu.id + '-on.' + menu.type;
						changeImages(imgname, imgfile);
				}
		});
}

function startMonitoring() {
		executer = new PeriodicalExecuter(hideMenus, .1);
}

function stopMonitoring() {
		if (executer)
				executer.stop();
}

function attachListenersToSubmenu() {
		var submenus	 = $$('.menuItem a');

		submenus.each(function(submenu) {
				Event.observe(submenu, 'mouseover', stopMonitoring);
				Event.observe(submenu, 'mouseout', startMonitoring);
		});
}

function startHandlers() {
	if (! startHandlersLoaded)
	{
		startHandlersLoaded = 1;
		highlightCurrent();
		attachListenersToSubmenu();
	}
}

Event.observe(window, 'load', startHandlers);
