
var opensub = new Array();
var opensubg = new Array();
opensub[1] = 0;
opensub[2] = 0;
opensubg[1] = 0;
opensubg[2] = 0;
var timeout	= 500;
var closetimer	= 0;
var closetimer2	= 0;

function showSubmenu(parentNode,id,lvl) {
	
	
	if(document.getElementById('subnav'+lvl+'_' + id)){
		
		mcancelclosetime();
		mcancelclosetime2();

		if(opensub[lvl] && opensub[lvl] != document.getElementById('subnav'+lvl+'_' + id)) {
			opensub[lvl].style.display = 'none';
			opensubg[lvl].style.display = 'none';
			if(lvl == 1){
				if(opensub[2]){
			  opensub[2].style.display = 'none';
			  opensubg[2].style.display = 'none';
				}
			}
		}
		
		opensub[lvl] = document.getElementById('subnav'+lvl+'_' + id);
		opensubg[lvl] = document.getElementById('subnav'+lvl+'bg_' + id);
		
		if (lvl > 1)
		  var width = parentNode.offsetWidth+1;
	 else
		  var width = 0;
	 
		document.getElementById('subnav'+lvl+'_' + id).style.left = (parentNode.offsetLeft+width) + 'px';
    if (lvl > 1)
      document.getElementById('subnav'+lvl+'_' + id).style.top = (parentNode.firstChild.offsetTop-5) + 'px';
		document.getElementById('subnav'+lvl+'_' + id).style.display = 'block'; 
		document.getElementById('subnav'+lvl+'bg_' + id).style.left = (parentNode.offsetLeft+width) + 'px'; 
		if (lvl > 1)
      document.getElementById('subnav'+lvl+'bg_' + id).style.top = (parentNode.firstChild.offsetTop-5) + 'px';
		document.getElementById('subnav'+lvl+'bg_' + id).style.display = 'block'; 
		document.getElementById('subnav'+lvl+'bg_' + id).style.width = document.getElementById('subnav'+lvl+'_' + id).offsetWidth + "px";		
		document.getElementById('subnav'+lvl+'bg_' + id).style.height = document.getElementById('subnav'+lvl+'_' + id).offsetHeight + "px";	
		
		
	}
	return false;
}

// close showed layer
function mclose1()
{

	if(opensub[1]) {
		opensub[1].style.display = 'none';
		opensubg[1].style.display = 'none';

	}
	mclose2();
}
function mclose2()
{

	if(opensub[2]) {
		opensub[2].style.display = 'none';
		opensubg[2].style.display = 'none';

	}
}

// go close timer
function mclosetime1()
{
	closetimer = window.setTimeout(mclose1, timeout);
}
function mclosetime2()
{
	closetimer2 = window.setTimeout(mclose2, timeout);
}

// cancel close timer
function mcancelclosetime()
{
	if(closetimer)
	{
		window.clearTimeout(closetimer);
		closetimer = null;
	}
}

function mcancelclosetime2()
{
	if(closetimer2)
	{
		window.clearTimeout(closetimer2);
		closetimer2 = null;
	}
}
