/*

Lucas Paluzga, © 2003
lucas@daimon.cz

CTSL and CTST - permission given by Petr Maj

*/

var mnu_maxlevel = 5;

function CTSL (element)
{
    var y=element.offsetLeft;
    while (element.tagName!="BODY")
    {
      y+=element.offsetParent.offsetLeft;
      element=element.offsetParent;
    }
    return y;
}

function CTST(element)
{
    var y=element.offsetTop;
    while (element.tagName!="BODY")
    {
      y+=element.offsetParent.offsetTop;
      element=element.offsetParent;
    }
    return y;
}

function TMenu (source)
{
	this.m = new Array();
	this.yOffset = 0;
	this.negyOffset = 0;
	this.source = source;
	this.classname = source;
	this.AM = mmenuaddsubmenu;
	this.AL = mmenuaddsublink;
	this.Show = showmainmenu;
	this.clearupperlevels = clearupperlevels;
	this.boxid = 0;
	this.setclean = setclean;
	this.clearclean = clearclean;
	this.timeout = 0;
}

function TSubMenu (name, source, width, boxid, classname, url)
{
	this.type = 'submenu';
	this.url = url;
	this.name = name;
	this.source = source;
	this.width = width;
	this.boxid = boxid;
	this.m = new Array();
	this.AM = smenuaddsubmenu;
	this.AL = mmenuaddsublink;
	this.Show = showsubmenu;
	this.classname = classname;
	this.clearuuperlevels = clearupperlevels;
	this.setclean = setclean;
	this.clearclean = clearclean;
}

function TSubLink (name, url)
{
	this.type = 'link';
	this.name = name;
	this.url = url;
}
	

function mmenuaddsubmenu (name, width, url)
{
	this.m[name] = new TSubMenu (name, this.source + '.m[\'' + name + '\']', width, 1, this.classname, url);
}

function mmenuaddsublink (name, url)
{
	this.m[name] = new TSubLink (name, url);
}
	
function smenuaddsubmenu (name, width, url)
{
	this.m[name] = new TSubMenu (name, this.source + '.m[\'' + name + '\']', width, this.boxid + 1, this.classname, url);
}

function showmainmenu()
{
	document.write ('<div id="layer_control" style="z-index:3"><table class="y_menu_topbox"><tr>');
	for (i in this.m)
	{
		switch (this.m[i].type)
		{
			case 'link':
				document.write ('<td onmouseover="' + this.classname + '.clearupperlevels(1)"><a href="' + this.m[i].url + '" class="y_menu_topitem">' + i + '</a></td>');
				break;
			case 'submenu':
				document.write ('<td onmouseover="' + this.classname + '.m[\'' + i + '\'].Show(CTSL(this) + ' + this.xOffset + ', CTST(this) + ' + this.yOffset + ')"><a href="' + this.m[i].url + '" class="y_menu_topitem">' + i + '</a></td>');
				break;
		}
	}
	document.write ('</tr></table><img src="images/common/sub_line.gif" width="654" height="1" border="0" align="bottom" vspace="4"><img src="images/common/dot_black.gif" width="12" height="1" border="0" align="bottom"><img src="images/common/jfp.gif" width="294" height="20" alt="" border="0"><br><br><br>');
	for (i = 1; i <= mnu_maxlevel; i++)
	{
		document.write ('<table class="y_menu_subbox" id="mnu_' + this.classname + '_box' + i + '" style="position:absolute; visibility: hidden; left: 0px; top: 0px"><tr><td id="mnu_' + this.classname + '_content' + i + '" onmouseover="' + this.classname + '.clearclean()" onmouseout="' + this.classname + '.setclean(1)"></td></tr></table></div>');
	}		
}	
	
function showsubmenu (left, top)
{
	this.clearuuperlevels(this.boxid);
	this.clearclean();
	var s = '';
	for (i in this.m)
	{
		switch (this.m[i].type)
		{
			case 'link':
				s += '<a class="y_menu_sublink" href = "' + this.m[i].url + '" onmouseover="' + this.classname + '.clearupperlevels(' + (this.boxid + 1) + ')">' + this.m[i].name + '</a><br>';
				break;
			case 'submenu':
				s += '<a href="' + this.m[i].url + '" class="y_menu_submenucapt" onmouseover = "' + this.source + '.m[\'' + i + '\'].Show(CTSL(this) + ' + this.width + ', CTST(this))">' + this.m[i].name + '</a><br>';
				break;
		}
	}
	var box = document.getElementById ('mnu_' + this.classname + '_box' + this.boxid);
	var content = document.getElementById ('mnu_' + this.classname + '_content' + this.boxid);
	content.innerHTML = s;
	box.style.left = left;
	eval ('box.style.top = top - ' + this.classname + '.negyOffset');
	box.style.width = this.width;
	box.style.visibility = "visible";
}

function clearupperlevels(lvl)
{
	var box, content;
	for (i = lvl; i <= mnu_maxlevel; i++)
	{
		box = document.getElementById ('mnu_' + this.classname + '_box' + i);
		content = document.getElementById ('mnu_' + this.classname + '_content' + i);
		box.style.visibility = "hidden";
		content.innerHTML = "";
	}
}

function setclean (lvl)
{
	eval (this.classname + '.timeout = setTimeout ("' + this.classname + '.clearupperlevels (' + lvl + ')", 1000)');
}	

function clearclean ()
{
	eval ('clearTimeout (' + this.classname + '.timeout)');
}	
