// check browser version
NS4 = (document.layers) ? 1 : 0;

var topIDLateral  = -1;

// constructor of menu elements


function hideElementLateral()
	{
	for (i = 0; i < document.all.tags('SELECT').length; i++)
		{
		obj = document.all.tags('SELECT')[i];
		if (! obj || ! obj.offsetParent)
			continue;		
			obj.style.visibility = "hidden";
		}	

	}
	
	
function showElementLateral() 
	{
	for (i = 0; i < document.all.tags('SELECT').length; i++)
		{
		obj = document.all.tags('SELECT')[i];
		if (! obj || ! obj.offsetParent)
			continue;		
		obj.style.visibility = "";
		}

	}	
	
	
function menuConstructorLateral (id, content)
{
	this.ID            = id;
	this.parentID      = content [0]*1;
	this.parentItemID  = content [1]*1;
	this.width         = content [2]*1;
	this.timerID       = -1;
	this.isOn          = false;
	this.item          = new Array ();
	this.currItemID    = -1;

	if (this.parentID == -1)
	{
		this.x = content [4]*1;
		if (this.x == -1) {
			this.x = initXLateral + usedWidthLateral;
			usedWidthLateral = usedWidthLateral + this.width;
			}
		//this.y = initYLateral;
		this.y = initYLateral + content [3]*1;
	}
	else
	{
		this.y = content [3]*1;
		if (this.y < 0)
			this.y =  menuElementLateral [this.parentID].y
		 		      + itemHeightLateral*this.parentItemID
				      + yOverlapLateral;
		this.x = content [4]*1;

		if (this.x < 0)
			this.x =  menuElementLateral [this.parentID].x
				      + menuElementLateral [this.parentID].width
				      - xOverlapLateral;
	}
	items = content [5];

	layerBody = '<table width=' + this.width + ' cellpadding=1 cellspacing=' + borderSizeLateral + ' border=0>';
	
	for (j = 0; j <= items.length - 2; j = j + 2)
	{
		controlBlock = ' onMouseOver = "enterItemLateral (' + this.ID + ', ' + ((j + 2)/2 - 1) + ');this.style.cursor=\'hand\';" onMouseOut = "exitItemLateral (' + this.ID + ', ' + ((j + 2)/2 - 1) + ');" ';
		//layerBody += '<td class="DropDownMenuAlpha" height=' + itemHeightLateral + ' width=' + this.width + ' bgcolor=' + backColorLateral + ' ' + controlBlock + '>';
		
		if (items [j + 1] != "") {
			layerBody += '<a  href='+ items [j + 1] + '><td colspan=2 class="DropDownMenuAlpha" height=' + itemHeightLateral + ' width=' + this.width + ' bgcolor=' + backColorLateral + ' ' + controlBlock + '>' + items [j] + '</td></a>';
			}
		else
			{
			layerBody += '<td class="DropDownMenuAlpha" height=' + itemHeightLateral + ' width=' + this.width + ' bgcolor=' + backColorLateral + ' ' + controlBlock + '>' + items [j] + '</td><td><img src="./images/bot_seta.gif" width="5" height="6"></td>';
			}
		//layerBody += '</td>';
		if (j < items.length - 2)
			layerBody = layerBody +  '<tr>\n';
		else
			layerBody = layerBody + '\n';
	}

	if (!NS4)
		layerHeader = '<div id=MenuLateral' + this.ID +
				   	   ' onMouseOver="enterMenuLateral (' + this.ID + ');" onMouseOut = "exitMenuLateral (' + this.ID + ');"' +
		    	       ' style="width: ' + this.width + '; visibility: hidden; z-index: -1; position: absolute; left: ' + this.x +
		        	   '; top: ' + this.y + ';">';
	else
		layerHeader = '<layer id=MenuLateral' + this.ID +
					   ' onMouseOver="enterMenuLateral (' + this.ID + ');" onMouseOut = "exitMenuLateral (' + this.ID + ');"' +
					   ' visibility=hide left=' + this.x +
					   ' top =' + this.y + '>';
	//alert(layerHeader);

	layerHeader += '<table bgColor= '+ borderColorLateral + ' width=' + this.width + ' cellpadding=1 cellspacing=1 border=0>' +
				    '<td bgcolor=' + backColorLateral + ' >';

	layerFooter = '</table></td></table>';

	if (!NS4)
		layerFooter = layerFooter + '</div>';
	else
		layerFooter = layerFooter + '</layer>';


	document.writeln (layerHeader + layerBody + layerFooter);

	return this;
}
function enterTopItemLateral (ID)
{
	if (topIDLateral != ID && topIDLateral != -1)
		hideTreeLateral (topIDLateral);
	releaseTreeLateral (ID);
	topIDLateral = ID;
	showLateral (ID);
}
function exitTopItemLateral (ID)
{
	menuElementLateral [ID].timerID = setTimeout ('hideLateral (' + ID + ')', delayLateral);
}
function enterItemLateral (menuID, itemID)
{
	var currItemID = menuElementLateral [menuID].currItemID;

	if (currItemID != i & currItemID > -1)
		hideLateral (currItemID);

	for (var i = 0; i < numOfMenusLateral; i++)
	{
		if (menuElementLateral [i].parentID == menuID &&
		    menuElementLateral [i].parentItemID == itemID)
		{
			clearTimeout (menuElementLateral [i].timerID);
			menuElementLateral [i].timerID = -1;
			showLateral (i);
			return 0;
		}
	}

	return -1;
}
function exitItemLateral (menuID, itemID)
{
	for (var i = 0; i < numOfMenusLateral; i++)
	{
		if (menuElementLateral [i].parentID == menuID &&
		    menuElementLateral [i].parentItemID == itemID)
		{
			menuElementLateral [i].timerID = setTimeout ('hideLateral (' + i + ')', delayLateral);
			return 0;
		}
	}
}
function enterMenuLateral (ID)
{
	var parentID = menuElementLateral [ID].parentID;
	if (parentID == -1)
	{
		clearTimeout (menuElementLateral [ID].timerID);
		menuElementLateral [ID].timerID = -1;
	}
	else
		releaseTreeLateral (ID);
}
function exitMenuLateral (ID)
{
	timeoutTreeLateral (ID);
}
function hideTreeLateral (ID)
{
	hideLateral (ID);
	for (var j = 0; j < numOfMenusLateral; j++)
	{
		if (menuElementLateral [j].parentID == ID &&
			menuElementLateral [j].isOn)
		{
			hideTreeLateral (j);
			return 0;
		}
	}
}
function releaseTreeLateral (ID)
{
	clearTimeout (menuElementLateral [ID].timerID);
	menuElementLateral [ID].timerID = -1;

	var parentID = menuElementLateral [ID].parentID;
	if (parentID > -1)
		releaseTreeLateral (parentID);
}
function timeoutTreeLateral (ID)
{
	menuElementLateral [ID].timerID = setTimeout ('hideLateral (' + ID + ')', delayLateral);
	var parentID = menuElementLateral [ID].parentID;
	if (parentID > -1)
		timeoutTreeLateral (parentID);
}

function showLateral (ID)
{
	if (!NS4) {
		document.all['MenuLateral' + ID].style.zIndex = "3";
		document.all['MenuLateral' + ID].style.visibility = "visible";
		}
	else
		document.layers[ID].visibility = "visible";

	menuElementLateral [ID].isOn = true;

	if (menuElementLateral [ID].parentID > -1)
		menuElementLateral [menuElementLateral [ID].parentID].currItemID = ID;
}

function hideLateral (ID)
{
	if (!NS4) {
		document.all['MenuLateral' + ID].style.zIndex = "-1";
		document.all['MenuLateral' + ID].style.visibility = "hidden";
		}
	else
		document.layers['MenuLateral' + ID].visibility = "hide";

	menuElementLateral [ID].isOn = false;

	if (menuElementLateral [ID].parentID > -1)
		menuElementLateral [menuElementLateral [ID].parentID].currItemID = -1;
}

function createMenuTreeLateral ()
{
	for (var i = 0; i < menuContentLateral.length; i++)
	{
		menuElementLateral [i] = new menuConstructorLateral (i, menuContentLateral [i]);
		numOfMenusLateral++;
	}
}

createMenuTreeLateral ();