var currentMenu = null;
var menuEnabled = !($.browser.msie && $.browser.version < 8);

function setMenu(id) {
	closeMenu();
	if (currentMenu == id) {
		return;
	}
	if (id != null) {
		$('#topmenu #button-' + id).attr('src', '/images/menu/menu_' + id + '_on.png');
		var pos = $('#topmenu #button-' + id).position();
		$('#topmenu #submenu-' + id).css('top', (pos.top+63)+'px').css('left', (pos.left+220)+'px').show();
		currentMenu = id;
	}
}

function closeMenu() {
	$('#topmenu').stopTime('close');
	if (currentMenu != null) {
		$('#topmenu #button-' + currentMenu).attr('src', '/images/menu/menu_' + currentMenu + '.png');
		$('#topmenu #submenu-' + currentMenu).hide();
		currentMenu = null;
	}
}

if (menuEnabled) {
	$('#topmenu').ready(function() {
		$('#topmenu .menu-item').hover(function() {
			var id = $(this).attr('id').substr(7);
			setMenu(id);
		}, function() {
			$('#topmenu').oneTime(300, 'close', closeMenu);
		});
		$('#topmenu .submenu').hover(function() {
			$('#topmenu').stopTime('close');
		}, function() {
			$('#topmenu').oneTime(300, 'close', closeMenu);
		});
	});
}
