var allMenuDivs = new Array();

var arSubmenuChecks = new Array(); // rika, zda je mys stale nad submenu ci ne

var strMenuIdSelected = '';

var pTimeout;
var cTimenout = 300;

function initAllMenuTags() // umistit pred tag </html>, aby se nacetly vsechny
							// menu tagy
{
	var i;
	allDivs = document.getElementsByTagName('div');

	for (i = 0; i < allDivs.length; i++) {
		if (allDivs[i].className == "submenu") {
			allMenuDivs[allDivs[i].id] = allDivs[i];
			arSubmenuChecks[allDivs[i].id] = false;
		}
	}

}

function showMenu(strMenuId) {
	clearTimeout(pTimeout);

	// skryti puv. menu a submenu
	if (strMenuIdSelected != '')
		hideMenu(strMenuIdSelected);

	// zobrazeni noveho
	allMenuDivs[strMenuId].style.display = 'block';
	strMenuIdSelected = strMenuId;

	// obarveni menu
	strMenuName = 'menu_' + strMenuId;
	pMenuAnchor = document.getElementById(strMenuName);
	pMenuAnchor.style.color = '#A3EE2C';
	pMenuAnchor.style.background = '#666666';
}

function hideMenu(strMenuId) {
	allMenuDivs[strMenuId].style.display = 'none';

	// odbarveni menu
	strMenuName = 'menu_' + strMenuId;
	pMenuAnchor = document.getElementById(strMenuName);

	pMenuAnchor.style.background = 0;
	pMenuAnchor.style.color = '#5A5A5A';
}

function menuMouseOver(strMenuId) {
	if (allMenuDivs[strMenuId] != null)
		showMenu(strMenuId);
	else {
		if (strMenuIdSelected != '') {
			hideMenu(strMenuIdSelected);
			strMenuIdSelected = '';
		}
	}
}

function menuMouseOut(strMenuId) {
	clearTimeout(pTimeout);
	pTimeout = setTimeout("checkSubmenuOnTimeout();", cTimenout);
}

function submenuMouseOver(strMenuId) {
	arSubmenuChecks[strMenuId] = true;
}

function submenuMouseOut(strMenuId) {
	arSubmenuChecks[strMenuId] = false;

	clearTimeout(pTimeout);
	pTimeout = setTimeout("checkSubmenuOnTimeout();", cTimenout);
}

function checkSubmenuOnTimeout() {
	if (arSubmenuChecks[strMenuIdSelected] == false) {
		// skryti submenu
		hideMenu(strMenuIdSelected);

		// zadne menu neni zvolene
		strMenuIdSelected = '';
	}
}

