var UIProc = 
{
	Init: function ()
	{
		UIProc.ContainerID = "MainContainer";
		UIProc.ObjectID = "MainObject";
		UIProc.Cache = UIProc.ObjectID;

		if (window.addEventListener)
		{
			window.addEventListener ("mousedown", UIProc.onGeckoMouseDown(), true);
		}
		else
		{
			document.getElementById (UIProc.ContainerID).onmouseup = function()
			{
				document.getElementById (UIProc.ContainerID).releaseCapture();
			}
			document.oncontextmenu = function()
			{
				if (window.event.srcElement.id == UIProc.ObjectID)
				{
					return false;
				}
				else
				{
					UIProc.Cache = "nan";
				}
			}
			document.getElementById (UIProc.ContainerID).onmousedown = UIProc.onIEMouseDown;
		}
	},

	UnInit: function ()
	{			
		if (window.RemoveEventListener)
		{			
			window.addEventListener ("mousedown", null, true);
			window.RemoveEventListener ("mousedown", UIProc.onGeckoMouseDown(), true);
		}
		else
		{						
			document.getElementById (UIProc.ContainerID).onmouseup = "";
			document.oncontextmenu = "";
			document.getElementById (UIProc.ContainerID).onmousedown = "";
		}
	},

	onIEMouseDown: function()
	{
	  	if (event.button > 1)
		{
			if (window.event.srcElement.id == UIProc.ObjectID && UIProc.Cache == UIProc.ObjectID)
			{
				UIProc.RaiseUIEvent_RightClick(); 
			}
			document.getElementById (UIProc.ContainerID).setCapture();
			if (window.event.srcElement.id)
			{
				UIProc.Cache = window.event.srcElement.id;
			}
		}
	},

	onGeckoMouseDown: function(ev)
	{
	  	return function(ev)
		{
	    		if (ev.button != 0)
			{
				UIProc.CaptureEvents(ev);
				if (ev.target.id == UIProc.ObjectID && UIProc.Cache == UIProc.ObjectID)
				{
					UIProc.RaiseUIEvent_RightClick();
				}
				UIProc.Cache = ev.target.id;
			}
	  	}
	},

	CaptureEvents: function(eventObject)
	{
		if (eventObject)
		{
			if (eventObject.stopPropagation)
			{
				eventObject.stopPropagation();
			}
			if (eventObject.preventDefault)
			{
				eventObject.preventDefault();
			}
			if (eventObject.preventCapture)
			{
				eventObject.preventCapture();
			}
	   		if (eventObject.preventBubble)
			{
				eventObject.preventBubble();
			}
		}
	},

	RaiseUIEvent_RightClick: function()
	{
		// document.getElementById (UIProc.ObjectID).RightClick();
		return;
	}
}
