var url = window.location.search;
var subMenuRegEx = /historia|spol/i;
var subMenuZRegEx = /pyt_s|pyt_w|pyt_r/i;
var activeMenu = '';
var currentMenu = '';

var msecs;
var timerID = null;
var timerRunning = false;
var delay = 100;

if (subMenuRegEx.exec(url))
	activeMenu = 'subMenu';
else if (subMenuZRegEx.exec(url))
	activeMenu = 'subMenuZ';

function show_subMenu() {
	stopTheClock();
	currentMenu = 'subMenu';
	subMenu.style.display = 'block';
	subMenuZ.style.display = 'none';
}

function hide_subMenu() {
	if (activeMenu != 'subMenu')
		subMenu.style.display = 'none';
	currentMenu = '';
	if (activeMenu == 'subMenuZ')
		show_subMenuZ();
}

function show_subMenuZ() {
	stopTheClock();
	currentMenu = 'subMenuZ';
	subMenuZ.style.display = 'block';
	subMenu.style.display = 'none';
}

function hide_subMenuZ() {
	if (activeMenu != 'subMenuZ')
		subMenuZ.style.display = 'none';
	currentMenu = '';
	if (activeMenu == 'subMenu')
		show_subMenu();
}

function initializeTimer() {
	msecs = 2;
	stopTheClock()
	startTheTimer()
}

function stopTheClock() {
	if(timerRunning)
	clearTimeout(timerID)
	timerRunning = false
}

function startTheTimer() {
	if (msecs == 0) {
		stopTheClock();
		if (currentMenu == 'subMenu')
			hide_subMenu();
		else if(currentMenu == 'subMenuZ')
			hide_subMenuZ();
	}
	else {
		msecs = msecs - 1;
		timerRunning = true;
		timerID = self.setTimeout("startTheTimer()", delay);
	}
}