
function SubMenu(imgID, arrItems, width, height)
{
	this.AlignmentImage = document.getElementById(imgID);
	this.DivObj = document.createElement("DIV");
	this.DivObj.style.display = "none";
	this.DivObj.style.position = "absolute";
	this.DivObj.style.zIndex = "1000";
	this.DivObj.style.width = width;
	this.DivObj.style.height = height;
	this.AlignmentImage.parentNode.appendChild(this.DivObj);
	this.ArrItems = arrItems;
	this.ConstructMenu();
	this.SetVisibility(false);
};

SubMenu.prototype.ConstructMenu = function()
{
	var tableObject = document.createElement("TABLE");
	tableObject.className = "SubMenu";
	tableObject.cellSpacing = 0;
	tableObject.cellPadding = 3;
	this.DivObj.appendChild(tableObject);
	for (var i=0; i<this.ArrItems.length;i++)
	{
		this.AddMenuRow(tableObject, this.ArrItems[i]);
	}
};

SubMenu.prototype.AddMenuRow = function(TableObject, MenuItem)
{
	var rowObject = TableObject.insertRow(TableObject.rows.length);
	var cellObject = rowObject.insertCell(rowObject.cells.length);
	cellObject.innerHTML = MenuItem[0];
	cellObject.noWrap = true;
	cellObject.ContainerMenu = this;

	var theSubMenu = this;
	if (document.all)
	{
		cellObject.attachEvent('onmouseover', theSubMenu.OnItemMouseOver);
		cellObject.attachEvent('onmouseout', theSubMenu.OnItemMouseOut);
		cellObject.attachEvent('onclick', theSubMenu.OnItemClick);
	}
	else
	{
		cellObject.addEventListener('mouseover', theSubMenu.OnItemMouseOver, false);
		cellObject.addEventListener('mouseout', theSubMenu.OnItemMouseOut, false);
		cellObject.addEventListener('click', theSubMenu.OnItemClick, false);
	}
};

SubMenu.prototype.AlignToImage = function()
{
	this.DivObj.style.posLeft = this.AlignmentImage.offsetLeft - 6;
};

SubMenu.prototype.OnItemMouseOver = function(e)
{
	if (e == null)
	{
		e = event;
	}
	var target;
	if(document.all)
	{
		target = e.srcElement;
	}
	else
	{
		target = e.target;
	}
	var theIndex = target.parentNode.rowIndex;
	var theSubMenu = target.ContainerMenu;	
	if (theIndex == 1 && theSubMenu.ArrItems[theIndex][1].search('aboutrhodopesituation') != -1) {
	   MISubMenu.SetVisibility(true);
	   var offset = 143
	   if (theSubMenu.ArrItems[theIndex][1].search('en') != -1) offset = 120
	   MISubMenu.DivObj.style.posLeft = MISubMenu.AlignmentImage.offsetLeft + offset;
	}	
	window.setTimeout(function(){target.className = "Over";}, 2);
};

SubMenu.prototype.OnItemMouseOut = function(e)
{
	if (e == null)
	{
		e = event;
	}
	var target;
	if(document.all)
	{
		target = e.srcElement;
	}
	else
	{
		target = e.target;
	}
	var theIndex = target.parentNode.rowIndex;
	var theSubMenu = target.ContainerMenu;	
	if (theSubMenu.ArrItems[theIndex][1].search('aboutrhodopesituation') == -1) {
	   MISubMenu.SetVisibility(false);
	}	
	window.setTimeout(function(){target.className = "";}, 2);
};

SubMenu.prototype.SetVisibility = function(visible)
{
	this.AlignToImage();
	if (visible)
	{
		this.DivObj.style.display = 'inline';
	}
	else
	{
		this.DivObj.style.display = 'none';
	}
};

SubMenu.prototype.OnItemClick = function(e)
{
	if (e == null)
	{
		e = event;
	}
	var target;
	if(document.all)
	{
		target = e.srcElement;
	}
	else
	{
		target = e.target;
	}
	var theIndex = target.parentNode.rowIndex;
	target.className = "";
	var theSubMenu = target.ContainerMenu;
	theSubMenu.SetVisibility(false);
	window.document.location.href = theSubMenu.ArrItems[theIndex][1];
};

