var ContextMenu = 
{
	ContextMenuObj : null,
	
	SetOnClick : function()
	{
		document.onclick = this.MenuHide.bind(this);
	},
	
	MenuHide : function() 
	{
		this.ContextMenuObj.style.display = "none";
		document.onclick = null;
	},

	Highlight : function(e) 
	{
		var obj = (document.all) ? event.srcElement : e;
		if (obj.className == "menuitems") 
		{
			obj.style.backgroundColor = "highlight";
			obj.style.color = "white";
		}
	},
	
	Normal : function(e) 
	{
		var obj = (document.all) ? event.srcElement : e;
		if (obj.className == "menuitems") 
		{
			obj.style.backgroundColor = "";
			obj.style.color = "black";
		}
	}
};

ContextMenu.Show = Class.create();
ContextMenu.Show.prototype = ContextMenu.extend
(
	{
		initialize : function(elem, menuitem)
		{
			this.ContextMenuObj = $(menuitem);
			var rightedge = document.body.clientWidth - mouseX;
			var bottomedge = document.body.clientHeight - mouseY;
			if (rightedge < this.ContextMenuObj.offsetWidth)
				this.ContextMenuObj.style.left = (document.body.scrollLeft + mouseX - this.ContextMenuObj.offsetWidth) + "px";
			else
				this.ContextMenuObj.style.left = (document.body.scrollLeft + mouseX) + "px";
			if (bottomedge < this.ContextMenuObj.offsetHeight)
				this.ContextMenuObj.style.top = (document.body.scrollTop + mouseY - this.ContextMenuObj.offsetHeight) + "px";
			else
				this.ContextMenuObj.style.top = (document.body.scrollTop + mouseY) + "px";
			this.ContextMenuObj.style.display = "";
			setTimeout(this.SetOnClick.bind(this), 500);
		}
	}
);

