
var MouseOverPopup =
{
	_private_functions:
	{
		_getPopup: function() { return this._popup; },
		_getBase: function() { return this._base; },

		_init: function()
		{
			this.getPopup = MouseOverPopup._private_functions._getPopup;
			this.getBase = MouseOverPopup._private_functions._getBase;
			this._callback_over = MouseOverPopup._private_functions._callback_over;
			this._callback_out = MouseOverPopup._private_functions._callback_out;

			var base = this.getBase();
			var popup = this.getPopup();

			if (base == null || popup == null)
				return;

			var b = this;

			var func_over = function (evt) { return b._callback_over.call(b, evt); };
			var func_out = function (evt) { return b._callback_out.call(b, evt); };

			jslib_Core.public_utility_functions.addEventListener(base, "mouseover", func_over, true);
			jslib_Core.public_utility_functions.addEventListener(base, "mousemove", func_over, true);
			jslib_Core.public_utility_functions.addEventListener(base, "mouseout", func_out, true);
		},

		_callback_over: function(evt)
		{
			var target;
			var mousepopup = this;

			if (evt == null)
			{
				evt = window.event;
				target = evt.srcElement;
			}
			else
			{
				target = evt.target;
				if (target == null)
					target = evt.srcElement;

				if (target == null)
					return;
			}

			var popup = mousepopup.getPopup();

			if (popup == null)
				return;

			if (mousepopup.getBase() != target)
				return;

			var vp = jslib_Core.public_utility_functions.viewPort();

			var total_width = vp.width;
			var total_height = vp.height;

			var pos_x = evt.clientX + 1;
			var pos_y = evt.clientY + 1;

			if (popup.style.display == "none")
			{
			        popup.style.display = "";
			        popup.style.position = "fixed";
			}

			if (pos_x + popup.offsetWidth > total_width)
				pos_x = total_width - popup.offsetWidth;

			if (pos_y + popup.offsetHeight > total_height)
				pos_y = total_height - popup.offsetHeight;


			popup.style.top = pos_y + "px";
			popup.style.left = pos_x + "px";
		},

		_callback_out: function(evt)
		{
			var target;
			var mousepopup = this;

			if (evt == null)
			{
				evt = window.event;
				target = evt.srcElement;
			}
			else
			{
				target = evt.target;
				if (target == null)
					target = evt.srcElement;

				if (target == null)
					return;
			}

			var popup = mousepopup.getPopup();

			if (popup == null)
			return;
	
			if (mousepopup.getBase() != target)
				return;

			popup.style.display = "none";
		}
	},

	inst: function(base_elem, popup_elem)
	{
		this._base = base_elem;
		this._popup = popup_elem;
		this._init = MouseOverPopup._private_functions._init;
		this._init();

		return;
	}
};

