HoverPopup = new Object();
HoverPopup._variableName = "HoverPopup";
HoverPopup._popupPanel = null;
HoverPopup._currentElement = null;
HoverPopup._initialized = false;
HoverPopup._currentElementInfo = null;
HoverPopup._bodyOnMouseMove = null;

HoverPopup.Register = function(id, html, cssClass, hoverCssClass)
{
	var element = document.getElementById(id);
	if (element)
	{
		element._hoverPopup_html = html;
		element._hoverPopup_cssClass = cssClass;
		element._hoverPopup_hoverCssClass = hoverCssClass;
		element.onmouseover = new Function(this._variableName + '.Show(this);');
	}
}

HoverPopup.Show = function(element)
{
	if (element == this._currentElement)
		return;

	if (!this._initialized)
		this._initialize();
		
	if (this._popupPanel.IsShown())
		this._hide();

	this._currentElement = element;
	this._currentElement.className = this._currentElement._hoverPopup_hoverCssClass;
	this._currentElementInfo = Telligent_Common.GetElementInfo(this._currentElement);
	
	this._popupPanel.SetPanelContent(this._currentElement._hoverPopup_html);
	this._popupPanel.Refresh();
	this._popupPanel.ShowAtElement(this._currentElement);	
}

HoverPopup._onMouseMove = function(event)
{
	if (this._initialized && this._currentElementInfo != null)
	{
		if (!event)
			event = window.event;
		
		var x = event.pageX ? event.pageX : (event.clientX + document.documentElement.scrollLeft);
		var y = event.pageY ? event.pageY : (event.clientY + document.documentElement.scrollTop);
		
		if (x < this._currentElementInfo.Left || x > this._currentElementInfo.Left + this._currentElementInfo.Width || y < this._currentElementInfo.Top || y > this._currentElementInfo.Top + this._currentElementInfo.Height)
			this._hide();
	}
	
	if (this._bodyOnMouseMove)
		this._bodyOnMouseMove(event);
}

HoverPopup._hide = function()
{
	if (this._initialized && this._popupPanel.IsShown())
	{
		this._popupPanel.Hide();
		if (this._currentElement)
			this._currentElement.className = this._currentElement._hoverPopup_cssClass;
		
		this._currentElement = null;
		this._currentElementInfo = null;
	}
}

HoverPopup._initialize = function()
{
	this._popupPanel = new Telligent_PopupPanel(this._variableName + '._popupPanel', '', 'updown', 100, null, null, false, '');
	this._popupPanel._initialize();
	
	if (document.documentElement.onmousemove != null)
		this._bodyOnMouseMove = document.documentElement.onmousemove;
		
	document.documentElement.onmousemove = new Function('event', this._variableName + "._onMouseMove(event);");
	
	this._initialized = true;
}
