/*
 * Namespace: DCTip
 *
 * A (small) alternative to OverLib.
 */

var DCTip =
{
	/*
	 * This is the element that acts as our tooltip. If null, it's not been
	 * initialised yet.
	 */
	toolTip : null,

	/* Offset from the corner of the mouse to show the tip at. */
	xOffset : -54,
	yOffset : -54,

	/**
	 * Initialises the system.
	 *
	 * @param  idDiv    Id of the div to use to display the tooltip. Default
	 *                  is 'tooltip'.
	 * @param  xOffset  X Offset from the corner of the pointer to display the
	 *                  tip at. Default is 15.
	 * @param  yOffset  Y Offset from the corner of the pointer to display the
	 *                  tip at. Default is 10.
	 */
	Initialise : function(idDiv, xOffset, yOffset)
	{
		if (this.toolTip)
			return;

		if (!idDiv)
			idDiv = "tooltip";
		this.toolTip = document.getElementById(idDiv);
		this.toolTip.style.display  = "none";
		this.toolTip.style.position = "absolute";

		if (xOffset)
			this.xOffset = xOffset;
		if (yOffset)
			this.yOffset = yOffset;

		if (DCTip.toolTip)
		{
		    if (document.addEventListener)
		        document.addEventListener("mousemove", this.OnMouseMove, true);
			else if (document.attachEvent)
				document.attachEvent('onmousemove', this.OnMouseMove);
			else
				document.onmousemove = this.OnMouseMove;
		}
	},

	/**
	 * Show a tooltip with the given content.
	 */
	Show : function(content)
	{
		this.Initialise();
		if (!this.toolTip || content == "")
			return;

		// Write the tip.
		if (document.createRange)
		{
			// Not IE: Use the DOM to set it up.
			var range = document.createRange();
			range.setStartBefore(this.toolTip);
			var frag = range.createContextualFragment(content);
			while (this.toolTip.hasChildNodes())
				this.toolTip.removeChild(this.toolTip.lastChild);
			this.toolTip.appendChild(frag);
		}
		else
		{
			this.toolTip.innerHTML = content;
		}

		this.toolTip.style.display = "block";
	},

	/**
	 */
	Hide : function()
	{
		if (this.toolTip)
			this.toolTip.style.display = "none";
	},

	OnMouseMove : function(evt)
	{
		evt = evt ? evt : window.event;
		DCTip.toolTip.style.left = (DCTip.GetX(evt) + DCTip.xOffset) + "px";
		DCTip.toolTip.style.top  = (DCTip.GetY(evt) + DCTip.yOffset) + "px";
	},

	GetX : function(evt)
	{
		var x = evt.clientX;
		if (window.event)
			return x + document.documentElement.scrollLeft + document.body.scrollLeft;
		return x + window.scrollX;
	},

	GetY : function(evt)
	{
		var y = evt.clientY;
		if (window.event)
			return y + document.documentElement.scrollTop + document.body.scrollTop;
		return y + window.scrollY;
	}
};

///////////////////////////////////////////// Basic OverLib Compatibility ///

function overlib(content)
{
	DCTip.Show(content);
}

function nd()
{
	DCTip.Hide();
	return false;
}

