// Don't change these parameters
var menuElement_b  = new Array ();
var numOfMenus_b   = 0;
var usedWidth_b    = 0;

/// ----------------------------

// check browser version
var topID_b  = -1;

// constructor of menu elements
function menuConstructor_b (id, content)
{
	this.ID            = id;
	this.parentID      = content [0]*1;
	this.parentItemID  = content [1]*1;
	this.width         = content [2]*1+15;
	this.timerID       = -1;
	this.isOn          = false;
	this.item          = new Array ();
	this.currItemID    = -1;
	
	this.x = content [3]*1;
	
//	if (this.x < 0 && this.parentID == -1)
//	{
//		this.x = initX + usedWidth_b;
//		usedWidth_b = usedWidth_b + this.width;
//	}
//	else if (this.x < 0 && this.parentID > -1)
//	{
//		this.x =  menuElement_b [this.parentID].x + menuElement_b [this.parentID].width - xOverlap;
//	}
	
	this.y = content [4]*1;
//	if (this.y < 0 && this.parentID == -1)
//		this.y = initY;
//	else if (this.y < 0 && this.parentID > -1)
//		this.y =  menuElement_b [this.parentID].y + itemHeight*this.parentItemID + yOverlap;
	
	items = content [5];

	szulo = content [6]*1;

	layerBody = '<table width=' + this.width + ' cellpadding=0 cellspacing=' + borderSize + ' border=0>';
	
	cell_width=this.width-15;

	for (j = 0; j <= items.length - 3; j = j + 3)
	{
		controlBlock = ' onMouseOver = "';
		controlBlock += ' enterItem_b (' + this.ID + ', ' + ((j + 2)/2 - 1) + ');';
		if(szulo!=-1)
			controlBlock += ' enterTopItem (' + szulo + ');';
		controlBlock += '"';
		controlBlock += ' onMouseOut = "exitItem_b (' + this.ID + ', ' + ((j + 2)/2 - 1) + ');';
		if(szulo!=-1)
			controlBlock += ' exitTopItem (' + szulo + ');';
		controlBlock +='" ';


		if(j>0)
			{
			layerBody+='<tr><td width=5 background=images/al_menu_01.jpg></td><td width=10 background=images/lila_alap.jpg></td><td width=' + cell_width + ' height=1 background=images/lila_alap.jpg></td></tr>';
			}
		layerBody += '<tr><td width=5 background=images/al_menu_01.jpg></td><td width=10 background=images/al_menu_02.jpg></td><td height=' + itemHeight + ' width=' + cell_width + ' background=images/al_menu_02.jpg id=td_' + id + '_' + j + '><a href='+ items [j + 1] +' ' + controlBlock + ' class=al_menu_style>' + items [j] + '</a></td></tr>';
		layerBody = layerBody + '\n';
	}

	if (!isNC)
		layerHeader = '<div id=Menu_b' + this.ID + ' onMouseOver="enterMenu_b (' + this.ID + ');" onMouseOut = "exitMenu_b (' + this.ID + ');"' + ' style="z-index: 2; background: ; width: ' + this.width + '; visibility: hidden; position: absolute; left: ' + this.x + '; top: ' + this.y + ';">';
	else
		layerHeader = '<layer id=Menu_b' + this.ID + ' onMouseOver="enterMenu_b (' + this.ID + ');" onMouseOut = "exitMenu_b (' + this.ID + ');"' + ' visibility=hide left=' + this.x + ' top =' + this.y + '>';

	layerHeader += '<table width=' + this.width + ' cellpadding=0 cellspacing=0 border=0><tr><td>';

	layerFooter = '</table></td></tr></table>';

	if (!isNC)
		layerFooter = layerFooter + '</div>';
	else
		layerFooter = layerFooter + '</layer>';
	document.writeln (layerHeader + layerBody + layerFooter);

//	alert(layerHeader + layerBody + layerFooter);

	return this;
}

function enterTopItem_b (ID)
{
	if (topID_b != ID && topID_b != -1)
		hideTree_b (topID_b);
	releaseTree_b (ID);
	topID_b = ID;
	show_b (ID);
}

function exitTopItem_b (ID)
{
	menuElement_b [ID].timerID = setTimeout ('hide_b (' + ID + ')', delay);
}

function enterItem_b (menuID, itemID)
{
	var currItemID = menuElement_b [menuID].currItemID;

	if (currItemID != i & currItemID > -1)	
		hide_b (currItemID);
	

	for (var i = 0; i < numOfMenus_b; i++)
	{
		if (menuElement_b [i].parentID == menuID &&
		    menuElement_b [i].parentItemID == itemID)
		{
			clearTimeout (menuElement_b [i].timerID);
			menuElement_b [i].timerID = -1;
			show_b (i);
			return 0;
		}
	}

	return -1;
}
function exitItem_b (menuID, itemID)
{
	for (var i = 0; i < numOfMenus_b; i++)
	{
		if (menuElement_b [i].parentID == menuID && menuElement_b [i].parentItemID == itemID)
		{
			menuElement_b [i].timerID = setTimeout ('hide_b (' + i + ')', delay);
			return 0;
		}
	}
}
function enterMenu_b (ID)
{
	var parentID = menuElement_b [ID].parentID;
	if (parentID == -1)
	{
		clearTimeout (menuElement_b [ID].timerID);
		menuElement_b [ID].timerID = -1;
	}
	else
		releaseTree_b (ID);
}
function exitMenu_b (ID)
{
	timeoutTree_b (ID);
}
function hideTree_b (ID)
{
	hide_b (ID);
	for (var j = 0; j < numOfMenus_b; j++)
	{
		if (menuElement_b [j].parentID == ID &&
			menuElement_b [j].isOn)
		{
			hideTree_b (j);
			return 0;
		}
	}
}
function releaseTree_b (ID)
{
	clearTimeout (menuElement_b [ID].timerID);
	menuElement_b [ID].timerID = -1;

	var parentID = menuElement_b [ID].parentID;
	if (parentID > -1)
		releaseTree_b (parentID);
}

function timeoutTree_b (ID)
{
	menuElement_b [ID].timerID = setTimeout ('hide_b (' + ID + ')', delay);
	var parentID = menuElement_b [ID].parentID;
	if (parentID > -1)
		timeoutTree_b (parentID);
}

function show_b (ID)
{
	if (isDOM) 
		document.getElementById('Menu_b' + ID).style.visibility = "visible";
    	else if (isIE) 
		document.all['Menu_b' + ID].style.visibility = "visible";
      	else if (isNC) 
		document.layers[ID].visibility = "show";		
	menuElement_b [ID].isOn = true;

	if (menuElement_b [ID].parentID > -1)
		menuElement_b [menuElement_b [ID].parentID].currItemID = ID;
}

function hide_b (ID)
{
	if (isDOM) 
		document.getElementById('Menu_b' + ID).style.visibility = "hidden";
    	else if (isIE) 
		document.all['Menu_b' + ID].style.visibility = "hidden";
      	else if (isNC) 
		document.layers[ID].visibility = "hide";

	menuElement_b [ID].isOn = false;

	if (menuElement_b [ID].parentID > -1)
		menuElement_b [menuElement_b [ID].parentID].currItemID = -1;
}

function createMenuTree_b ()
{
	for (var i = 0; i < menuContent_b.length; i++)
	{
		menuElement_b [i] = new menuConstructor_b (i, menuContent_b [i]);
		numOfMenus_b++;
	}
}

