
/* CSS Example:

	.hover-title
	{
		background-color: #FF6600; color: white; border: 1px solid #4F5C71; padding: 2px;
		position: absolute; left: 0; top: 0; height: 18; visibility: hidden;
		filter: progid:DXImageTransform.Microsoft.BasicImage(opacity=0.8); -moz-opacity: 0.8;
	}
*/

HoverTitle = function (elemObj)
{
	var title = this.getAttribute("title");
	var hovertitle = this.getAttribute("hovertitle");

	if (title != null && title != "")
		this.ht__title = title.replace(/\n/g, "<br/>");

	if (hovertitle != null && hovertitle != "")
		this.hovertitle = hovertitle;

	this.setAttribute("title", "");
}

HoverTitle.HoverAllTitles = false;
HoverTitle.PopupLayer = null;
HoverTitle.WindowCoord = [0,0];
HoverTitle.DefaultWidthMax = 300;
HoverTitle.DefaultFont = null;
HoverTitle.DefaultFontSize = null;
HoverTitle.FixedFont = "Dina, Courier New";
HoverTitle.FixedFontSize = "8pt";
HoverTitle.HtmlElem = null;
HoverTitle.BodyElem = null;
HoverTitle.ClassNamePopupLayer = "hoverlayer";
HoverTitle.ClassNameHover = "hovertitle";

HoverTitle.setup = function ()
{
	HoverTitle.HtmlElem = top.document.getElementsByTagName("HTML")[0];
	HoverTitle.BodyElem = top.document.body;

	HoverTitle.initializeElements();
	HoverTitle.initializeCoordinates();
}

HoverTitle.initializeElements = function ()
{
	HoverTitle.hide();

	var elements;
	if (arguments.length != 0)
	{
		if (arguments.length == 1 && isFunction(arguments[0].push))
			elements = arguments[0];
		else
			elements = arguments;
	}
	else
		elements = document.getElementsByTagName("*");

	for (var i = 0; i < elements.length; i++)
	{
		if (elements[i].getAttribute("hovertitle") || elements[i].ht__title ||
			 (elements[i].getAttribute("title") && HoverTitle.HoverAllTitles) ||
			 (css.containsClassName(elements[i], HoverTitle.ClassNameHover)))
					HoverTitle.initializeSingleElement(elements[i]);
	}

	if (HoverTitle.PopupLayer == null)
		HoverTitle.createPopupLayer();
}

HoverTitle.initializeSingleElement = function (elementObj)
{
	util.applyPrototypes(elementObj, HoverTitle);
}

HoverTitle.initializeCoordinates = function ()
{
	HoverTitle.WindowCoord = [0,0];

	var currentWindow = window;
	if (window != window.parent)
	{
		while (currentWindow != top)
		{
			currentWindow = currentWindow.parent;
			var frames1 = currentWindow.document.getElementsByTagName("IFRAME");
			var frames2 = currentWindow.document.getElementsByTagName("FRAME");
			var foundFrame = false;
			for (var i = 0; i < frames1.length; i++)
			{
				if (frames1[i].contentWindow == window)
				{
					HoverTitle.WindowCoord[0] += dom.getLeft(frames1[i]);
					HoverTitle.WindowCoord[1] += dom.getTop(frames1[i]);
					foundFrame = true;
					break;
				}
			}
			if (foundFrame != true)
			{
				for (var i = 0; i < frames2.length; i++)
				{
					if (frames2[i].contentWindow == window)
					{
						HoverTitle.WindowCoord[0] += dom.getLeft(frames2[i]);
						HoverTitle.WindowCoord[1] += dom.getTop(frames2[i]);
						foundFrame = true;
						break;
					}
				}
			}
		}
	}
}

HoverTitle.createPopupLayer = function ()
{
	var doc = top.document;
	var body = doc.body;

	var hlayer = document.getElementById("__hoverlayer");
	if (hlayer != null)
	{
		HoverTitle.PopupLayer = hlayer;
	}
	else
	{
		HoverTitle.PopupLayer = body.insertBefore(doc.createElement("DIV"), body.childNodes[0]);
		HoverTitle.PopupLayer.className = HoverTitle.ClassNamePopupLayer;
		HoverTitle.PopupLayer.id = "__hoverlayer";

		window.setTimeout(HoverTitle.saveFontStyle, 500);
	}
}

HoverTitle.hide = function ()
{
	css.hide(HoverTitle.PopupLayer);
}

HoverTitle.saveFontStyle = function ()
{
	HoverTitle.DefaultFont = HoverTitle.PopupLayer.style.fontFamily;
	HoverTitle.DefaultFontSize = HoverTitle.PopupLayer.style.fontSize;
}

HoverTitle.prototype.onmouseover = function (e)
{
	var event = e || window.event;
	var maxWidth = this.getAttribute("hoverwidth") || HoverTitle.DefaultWidthMax;
	var useFixed = this.getAttribute("hoverfixed") || false;

	HoverTitle.PopupLayer.innerHTML = "";
	HoverTitle.PopupLayer.style.visibility = "hidden";

	if (useFixed != false)
	{
		HoverTitle.PopupLayer.style.fontFamily = HoverTitle.FixedFont;
		HoverTitle.PopupLayer.style.fontSize = HoverTitle.FixedFontSize;
	}
	else
	{
		HoverTitle.PopupLayer.style.fontFamily = HoverTitle.DefaultFont;
		HoverTitle.PopupLayer.style.fontSize = HoverTitle.DefaultFontSize;
	}

	var title = this.hovertitle || this.ht__title;
	if (title && title.trim().length != 0)
	{
		HoverTitle.PopupLayer.innerHTML = this.hovertitle || this.ht__title;
		HoverTitle.PopupLayer.style.width = "auto";
		HoverTitle.PopupLayer.style.height = "auto";
		HoverTitle.active = true;

		if (HoverTitle.PopupLayer.offsetWidth > maxWidth)
			css.setPixelWidth(HoverTitle.PopupLayer, maxWidth);
		else
			css.setPixelWidth(HoverTitle.PopupLayer, HoverTitle.PopupLayer.offsetWidth);
	}
	else
		HoverTitle.active = false;
}

HoverTitle.prototype.onmousemove = function (e)
{
	if (HoverTitle.active == false)
		return;

	var event = e || window.event;
	HoverTitle.PopupLayer.style.visibility = "hidden";
	HoverTitle.PopupLayer.style.left = "0px";
	HoverTitle.PopupLayer.style.top = "0px";

	try
	{
		var doc = top.document;

		var bodyObj = HoverTitle.BodyElem;
		var htmlObj = HoverTitle.HtmlElem;

		var bodyHeight = htmlObj.scrollHeight || bodyObj.scrollHeight;
		var bodyWidth = htmlObj.scrollWidth || bodyObj.scrollWidth;

		var scrollTop = htmlObj.scrollTop || bodyObj.scrollTop;
		var scrollLeft = htmlObj.scrollLeft || bodyObj.scrollLeft;

		var eventX = event.clientX + HoverTitle.WindowCoord[0];
		var eventY = event.clientY + HoverTitle.WindowCoord[1];

		var targetLeft = (eventX + scrollLeft) + 10;
		var targetTop = (eventY + scrollTop) - HoverTitle.PopupLayer.offsetHeight - 3;

		if ((targetTop + HoverTitle.PopupLayer.offsetHeight) > bodyHeight - 5)
			targetTop -= HoverTitle.PopupLayer.offsetHeight;
		if (targetTop < 0)
			targetTop = 5;

		if ((targetLeft + HoverTitle.PopupLayer.offsetWidth) > bodyWidth - 5)
			targetLeft -= (HoverTitle.PopupLayer.offsetWidth + 30);
		if (targetLeft < 0)
			targetLeft = 5;

		HoverTitle.PopupLayer.style.left = targetLeft + "px";
		HoverTitle.PopupLayer.style.top = targetTop + "px";
		HoverTitle.PopupLayer.style.visibility = "visible";
		HoverTitle.PopupLayer.style.zIndex = 100;
	}
	catch(e)
	{
		window.status = "ERROR: " + e.message + " top: " + top + " top.document: " + top.document + " document: " + document;
	}
}

HoverTitle.prototype.onmouseout = function ()
{
	HoverTitle.hide();
}

evt.addHandler(window, "onready", HoverTitle.setup);
evt.addHandler(window, "onresize", HoverTitle.initializeCoordinates);

