// URL: http://chrisken.utacm.org/code/ :: chrisken
// v2.0 :: 2004-01-10
var bReplaceTitleAttributes = false;
var bTipInstalled = false;
var sUberTooltipDivId = 'tipDiv';
var tip = null;

function installTip( sDivId )
{
	if (document.layers) return; // ns4 = bad
	sUberTooltipDivId = sDivId;
	writeTip( sDivId );

	if (document.addEventListener)
	{
		document.addEventListener("mousemove", mouseMove, false);
	}
	else
	{
		document.onmousemove = mouseMove;
	}
}

function enableReplaceTitleAttributes()
{
	if (document.layers) return; // ns4 = bad
	bReplaceTitleAttributes = true;

	if (document.addEventListener)
	{
		document.addEventListener("mouseover", mouseOverOut, false);
		document.addEventListener("mouseout", mouseOverOut, false);
	}
	else
	{
		document.onmouseout = mouseOverOut;
		document.onmouseover = mouseOverOut;
	}
}

function mouseMove(e)
{
	if ( bTipInstalled )
	{
		tip.mouseMove(e);
	}
}

function mouseOverOut(e)
{
	if ( !bTipInstalled ) return;
	if (typeof(e) == "undefined")
	{
		e = event;
	}

	var obj = e.srcElement;
	if ( !obj && bReplaceTitleAttributes )
	{
		obj = e.target;
	}
	if ( obj )
	{
		if ((obj.tagName.toLowerCase() == "img" || obj.tagName.toLowerCase() == "span") && obj.parentNode.tagName.toLowerCase() == "a")
		{
			obj = obj.parentNode;
		}
		if (obj.tagName && obj.tagName.toLowerCase() == "a" && !obj.ntip)
		{
			if (e.type == "mouseover" && obj.title)
			{
				tip.show(obj.title);
				backupTitle = obj.title;
				obj.title = '';
			}
			else if (e.type == "mouseout" && obj.title == ''
				&& typeof(backupTitle) != "undefined" && backupTitle != '')
			{
				tip.hide();
				obj.title = backupTitle;
				backupTitle = '';
			}
		}
	}
}

function writeTip(divName)
{
	var trans = '-moz-opacity: 0;';
	if ( BrowserType() == "ie" )
	{
		trans = "filter: alpha(opacity=100);";
	}
	document.write( '<div id="' + divName + '" style="position: absolute; visibility: hidden; top: 0px; left: 0px; ' + trans + 
		'z-index: 37"><div id="tipText"></div></div>' );
}

function uberToolTip(id, delay)
{
	this.id = id || sUberTooltipDivId;
	this.textId = "tipText";
	this.mouseX = 0;
	this.mouseY = 0;
	this.doit = false;
	this.obj = null;
	this.textObj = null;
	this.fader = null;
	this.delay = delay || 40;
	this.max = 95;

	this.getMouseX = function()
	{
		var coords = this.getScrollCoords();
		return this.mouseX + (document.all? coords[0] : 0);
	}

	this.getMouseY = function()
	{
		var coords = this.getScrollCoords();
		return this.mouseY + (document.all? coords[1] : 0);
	}

	this.show = function(html)
	{
		if (window.opera) return;
		this.doit = true;
		if (this.fader)
		{
			this.fader.setTrans(0);
			this.fader.fadeIn();
		}
		this.update();
		wdivo(this.textObj, html);
		sdivo(this.obj);
	}

	this.update = function()
	{
		var left = this.getMouseX() + 13;
		var top = this.getMouseY() + (document.all? 20: 15);
		if ( typeof( UbertooltipPosX ) == 'function' && typeof( UbertooltipPosY ) == 'function' )
		{
			left = UbertooltipPosX();
			top = UbertooltipPosY();
		}
		else
		{
			if (this.obj.offsetWidth)
			{
				var w = this.getWinCoords();
				var s = this.getScrollCoords();
				var winb = w[1] + s[1];
				var winr = w[0] + s[0];
				if (top + parseInt(this.obj.offsetHeight) > winb)
				{
					top = winb - this.obj.offsetHeight;
				}
	
				if (left + parseInt(this.obj.offsetWidth) > winr - 20)
				{
					left = winr - this.obj.offsetWidth - 20;
				}
	
			}
		}

		this.obj.style.left = left + "px";
		this.obj.style.top = top + "px";
	}

	this.getWinCoords = function()
	{
		var wx, hx;
		if (window.innerHeight)
		{
			wx = window.innerWidth;
			hx = window.innerHeight;
		}
		else if (document.documentElement && document.documentElement.clientHeight != 0)
		{
			wx = document.documentElement.clientWidth;
			hx = document.documentElement.clientHeight;
		}
		else if (document.body && document.body.clientHeight)
		{
			wx = document.body.clientWidth;
			hx = document.body.clientHeight;
		}

		return [wx, hx];
	}

	this.getScrollCoords = function()
	{
  		var x = 0, y = 0;
  		if (typeof(window.pageYOffset) == "number")
		{
    		y = window.pageYOffset;
    		x = window.pageXOffset;
  		}
		else if (document.documentElement && document.documentElement.clientWidth != 0)
		{
        	y = document.documentElement.scrollTop;
        	x = document.documentElement.scrollLeft;
      	}
		else if (document.body && typeof(document.body.scrollLeft) != "undefined")
		{
      		y = document.body.scrollTop;
      		x = document.body.scrollLeft;
    	}
		return [x, y];
	}

	this.hide = function()
	{
		if (window.opera) return;
		hdivo(this.obj);
		this.doit = false;
		if (this.fader) this.fader.setTrans(0);
		this.obj.style.left = this.obj.style.top = 0;
		wdivo(this.textObj, "");
	}

	this.init = function()
	{
		if (document.layers || window.opera) return;
		this.obj = document.getElementById(this.id);
		this.textObj = document.getElementById(this.textId);
		if (!this.obj)
		{
			return;
		}
		this.loaded = true;
		if (window.ckapi && (document.all || (document.getElementById && document.addEventListener)))
		{
			this.fader = new ckapi(this.id, this.delay, this.max);
			this.fader.setTrans(0);
		}
		if (window.event)
		{
			this.mouseMove( window.event );
		}
	}

	this.mouseMove = function(e)
	{
		var x, y;
		if (window.event)
		{
			x = event.clientX;
			y = event.clientY;
		}
		else
		{
			x = e.pageX;
			y = e.pageY + 10;
		}
		this.mouseX = x;
		this.mouseY = y;
		if (this.obj && this.doit) this.update();
	}

	return this;
}

if (!document.getElementById && document.all)
{
	document.getElementById = function(id) { return document.all[id] }
}
function sdivo(l) { l.style.visibility = "visible"; }
function hdivo(l) { l.style.visibility = "hidden"; }
function wdivo(l, html) {
	if (typeof(l.innerHTML) != "undefined")
	{
		html = html.replace(/&/,"&amp;");
		l.innerHTML = html;
	}
}

function TipShow( sHtml )
{
	if ( bTipInstalled )
	{
		tip.show( sHtml );
	}
}

function TipHide()
{
	if ( bTipInstalled )
	{
		tip.hide();
	}
}

function loadTip()
{
	tip = new uberToolTip(null, BrowserType() == "ie" ? 150 : 20 );
	tip.init();
	bTipInstalled = true;
}

function ckapi(id, fDelay, sTrans)
{
	this.obj = "ckapiObj" + ckapi.count++;
	eval(this.obj + " = this");
	this.layerObj = document.getElementById(id);
	this.delay = fDelay;
	this.start = sTrans;
	this.delta = document.body.id == 'IE' ? 32 : 5;

	this.setTrans = function(trans)
	{
		if (trans > 100)
		{
			trans = 100;
		}

		if (this.layerObj.filters)
		{
			this.layerObj.filters.alpha.opacity = trans;
		}
		if (!document.all && this.layerObj.style.setProperty)
		{
			this.layerObj.style.setProperty("-moz-opacity", trans / 100 , "");
		}
	}

	this.getTrans = function()
	{
		if (document.all)
		{
			if (typeof(this.layerObj.filters.alpha.opacity) != "undefined")
			{
				return this.layerObj.filters.alpha.opacity;
			}
		}
		else if (this.layerObj.style.getPropertyValue)
		{
				return this.layerObj.style.getPropertyValue("-moz-opacity")*100;
		}
		return 100;
	}

	this.fadeIn = function()
	{
		if (!this.layerObj) return;
		clearTimeout(this.timer);
		var trans = this.getTrans();
	    if (trans < this.start)
		{
	        this.setTrans(trans + this.delta);
	        this.timer = setTimeout(this.obj + ".fadeIn()", this.delay);
        }
	}

	return this;
}
ckapi.count = 0;
