/* This notice must be untouched at all times.

tooltip.js    v. 3.0
The latest version is available at http://www.walterzorn.de/

Copyright (c) 2002 Walter Zorn. All rights reserved.
Created 1. 12. 2002 by Walter Zorn <walter@kreuzotter.de>
Last modified: 10. 1. 2003

A cross-browser tooltip script that works even in Opera 5 and 6
(as well as in NN 4, Gecko-Browsers, IE4+, Opera 7 and even Konqueror),
and doesn't require onmouseouts.
Appearance of tooltips may be individually configured
via commands inside the onmouseovers.

This software is provided "as is", without a warranty of any kind.
*/


//////////////  Tags with tooltip functionality  ////////////////////
var tt_tags = new Array('a','area','b','big','caption','center','code','dd','div','dl','dt','em','h1','h2','h3','h4','h5','h6','i','img','input','li','map','ol','p','pre','s','small','span','strike','strong','sub','sup','table','td','th','tr','tt','u','var','ul','layer');
/////////////////////////////////////////////////////////////////////


////////////////  Global Tooltip Configuration  /////////////////////
var ttWidth        = 300;
var ttPadding      = 5;
var ttBorderColor  = '#000099';
var ttBorderWidth  = 1;
var ttBgColor      = '#e6ecff';
var ttBgImg        = '';
var ttFontFace     = 'arial,helvetica,sans-serif';
var ttFontColor    = '#000066';
var ttFontSize     = '11px';
var ttFontWeight   = 'normal'; // alternative is 'bold';
var ttOffsetX      = 8;
var ttOffsetY      = 19;
/////////////////////////////////////////////////////////////////////



var tt_obj,                         // current tooltip
tt_objWidth = 0, tt_objHeight = 0,  // width and height of current tooltip
tt_offsetX = 0, tt_offsetY = 0,
xlim = 0, ylim = 0,                 // right and bottom borders of visible client area
tt_wait = false,
tt_vis = false,                     // tooltip visibility flag
tt_dwn = false,                     // true if tooltip below mousepointer
tt_u = 'undefined';


var tt_db = (document.compatMode && document.compatMode != 'BackCompat')? document.documentElement : document.body? document.body : null,
tt_n = navigator.userAgent.toLowerCase();


// Browser flags
var tt_op = (window.opera && document.getElementById)? true : false,
tt_ie = tt_n.indexOf('msie') != -1 &&
	document.all &&
	tt_db &&
	!tt_op,
tt_n4 = navigator.appName + parseInt(navigator.appVersion) == 'Netscape4' && document.layers,
tt_n6 = (tt_n6i = tt_n.indexOf('gecko')) != -1 ||
	tt_n.indexOf('galeon') != -1,
tt_kqi = tt_n.indexOf('konq'),
tt_kq = tt_kqi > -1,
tt_kqnew = tt_kq &&
	parseInt(tt_n.substring(tt_kqi + (5<<1))) > 2 &&
	tt_n.substring(tt_kqi + (5<<1), tt_kqi + (6<<1|1)) != '3.0';


tt_n = '';


function tt_Int(x)
{
	var y;
	return isNaN(y = parseInt(x))? 0 : y;
}


// Substitute for String.replace.
// Doesn't require regExp as to-be-replaced arg
function wzReplace(x, y)
{
	var ret = '',
	str = this,
	xI;
	while ((xI = str.indexOf(x)) != -1)
	{
		ret += str.substring(0, xI) + y;
		str = str.substring(xI + x.length);
	}
	return ret+str;
}
String.prototype.wzReplace = wzReplace;


function tt_n4Tags(tagtyp, d, y)
{
	d = d || document;
	y = y || new Array();
	var x = (tagtyp=='a')? d.links : d.layers;
	for (var z = 0; z<x.length; z++) y[y.length] = x[z];
	for (var z = 0; z<d.layers.length; z++)
	{
		y = tt_n4Tags(tagtyp, d.layers[z].document, y);
	}
	return y;
}


function tt_Htm(tt, id, txt)
{
	var ttw   = (typeof tt.T_WIDTH != tt_u)? tt.T_WIDTH  : ttWidth,
	ttpadd    = (typeof tt.T_PADDING != tt_u)? tt.T_PADDING : ttPadding,
	ttbc      = (typeof tt.T_BORDERCOLOR != tt_u)? tt.T_BORDERCOLOR : ttBorderColor,
	ttbw      = (typeof tt.T_BORDERWIDTH != tt_u)? tt.T_BORDERWIDTH : ttBorderWidth,
	ttbgc     = (typeof tt.T_BGCOLOR != tt_u)? tt.T_BGCOLOR : ttBgColor,
	ttbgimg   = (typeof tt.T_BGIMG != tt_u)? tt.T_BGIMG : ttBgImg,
	ttff      = (typeof tt.T_FONTFACE != tt_u)? tt.T_FONTFACE : ttFontFace,
	ttfc      = (typeof tt.T_FONTCOLOR != tt_u)? tt.T_FONTCOLOR : ttFontColor,
	ttfsz     = (typeof tt.T_FONTSIZE != tt_u)? tt.T_FONTSIZE : ttFontSize,
	ttfwght   = (typeof tt.T_FONTWEIGHT != tt_u)? tt.T_FONTWEIGHT : ttFontWeight;
	
	var y = '<div id="' + id + '" style="position:absolute;z-index:'+ (2<<8) + ';left:0px;top:0px;width:' + ttw + 'px;visibility:' + (tt_n4? 'hide' : 'hidden') + ';">\n';
	y += '<table border="0" cellpadding="0" cellspacing="0" bgcolor="' + ttbc + '" width="' + ttw + '">\n<tr>\n<td>\n';
	y += '<table border="0" cellpadding="' + ttpadd + '" cellspacing="' + ttbw + '" width="100%">\n';
	y += '<tr>\n<td bgcolor="' + ttbgc + '"' + (ttbgimg? ' background="' + ttbgimg + '"' : '') + (tt_n6? (' style="padding:' + ttpadd + 'px;"') : '') + '>\n';
	y += '<font style="font-family:' + ttff + ';color:' + ttfc + ';font-size:' + ttfsz + ';">';
	if (ttfwght == 'bold') y += '<b>';
	y += txt;
	if (ttfwght == 'bold') y += '<\/b>';
	y += '<\/font><\/td>\n<\/tr>\n<\/table>\n<\/td>\n<\/tr>\n<\/table>\n<\/div>\n';
	return y;
}


function tt_Init()
{
	if (!(tt_op || tt_n4 || tt_n6 || tt_ie || tt_kq)) return;
	
	var htm = tt_n4? '<div style="position:absolute;"><\/div>' : '',
	tag,
	over,
	esc = 'return escape(';
	for (var i = 0; i<tt_tags.length; i++)
	{
		var tags = tt_ie? (document.all.tags(tt_tags[i]) || 1)
			: document.getElementsByTagName? (document.getElementsByTagName(tt_tags[i]) || 1)
			: (!tt_n4 && tt_tags[i]=='a')? document.links
			: 1;
		if (tt_n4 && (tt_tags[i] == 'a' || tt_tags[i] == 'layer')) tags = tt_n4Tags(tt_tags[i]);
		for (var j = 0; j<tags.length; j++)
		{
			if (typeof tags[j].onmouseover == 'function' && tags[j].onmouseover.toString().indexOf(esc) != -1 || tt_n6 && (over = tags[j].getAttribute('onmouseover')) && over.indexOf(esc) != -1)
			{
				if (over) tags[j].onmouseover = new Function(over);
				var txt = unescape(tags[j].onmouseover());
				htm += tt_Htm(
					tags[j],
					'tOoLtIp'+i+''+j,
					txt.wzReplace('& lt;','&lt;').wzReplace('& gt;','&gt;').wzReplace('& quot;','&quot;')
				);

				var offx = (typeof tags[j].T_OFFSETX != tt_u)? tags[j].T_OFFSETX : ttOffsetX,
				offy = (typeof tags[j].T_OFFSETY != tt_u)? tags[j].T_OFFSETY : ttOffsetY;
				
				tags[j].onmouseover = new Function(
					'tt_Show("tOoLtIp' +i+''+j+ '", '+
					offx + ', '+
					offy +
					');'
				);
				tags[j].onmouseout = tt_Hide;
			}
		}
	}
	document.write(htm);
}


function tt_GetDiv(id)
{
	return (
		tt_n4? (document.layers[id] || null)
		: tt_ie? (document.all[id] || null)
		: (document.getElementById(id) || null)
	);
}


function tt_GetDivWidth()
{
	return (
		tt_n4? tt_obj.clip.width
		: tt_obj.style && tt_obj.style.pixelWidth? tt_obj.style.pixelWidth
		: tt_obj.offsetWidth
	);
}


function tt_GetDivHeight()
{
	return (
		tt_n4? tt_obj.clip.height
		: tt_obj.style && tt_obj.style.pixelHeight? tt_obj.style.pixelHeight
		: tt_obj.offsetHeight
	);
}


// Compat with DragDrop Lib: Ensure that z-index of tooltip is lifted beyond toplevel dragdrop element
function tt_SetDivZindex()
{
	var i = tt_obj.style || tt_obj;
	if (window.dd && dd.zIndex)
		i.zIndex = Math.max(dd.zIndex + 1, i.zIndex);
}


function tt_SetDivPos(x, y)
{
	var i = tt_obj.style || tt_obj;
	i.left = x;
	i.top = y;
}


function tt_ShowDiv()
{
	if (tt_n4) tt_obj.visibility = 'show';
	else tt_obj.style.visibility = 'visible';
	tt_vis = true;
}


function tt_HideDiv()
{
	if (tt_n4) tt_obj.visibility = 'hide';
	else tt_obj.style.visibility = 'hidden';
	tt_vis = false;
}


function tt_Show(id, offx, offy)
{
	if (tt_obj) tt_Hide();
	if (document.onmousemove) return;  // return if onmousemove currently active (for instance drag operation?)


	tt_obj = tt_GetDiv(id);			
	if (tt_obj)
	{
		tt_objWidth = tt_GetDivWidth();
		tt_objHeight = tt_GetDivHeight();
		tt_offsetX = offx;
		tt_offsetY = offy;
		if (tt_op)
		{
			tt_offsetX -= 5<<1;
			tt_offsetY += 5<<2;
		}
	
		tt_dwn = true;
							
		xlim = tt_Int((tt_db && tt_db.clientWidth)? tt_db.clientWidth : window.innerWidth) +
			tt_Int(window.pageXOffset || (tt_db? tt_db.scrollLeft : 0) || 0) -
			tt_objWidth -
			(tt_n4? 5<<2 : 0);

		ylim = tt_Int(window.innerHeight || tt_db.clientHeight) +
			tt_Int(window.pageYOffset || (tt_db? tt_db.scrollTop : 0) || 0) -
			tt_objHeight - tt_offsetY;
			
		tt_SetDivZindex();

		if (document.captureEvents)	document.captureEvents(Event.MOUSEMOVE);
		document.onmousemove = tt_Move;
	}
}


function tt_Move(e)
{
	if (!tt_obj) return;
	if (tt_n6 || tt_kq)
	{
		if (tt_wait) return;
		tt_wait = true;
		setTimeout('tt_wait = false;', 5);
	}
	
	
	e = e || window.event;

	var x = tt_Int(e.pageX || e.clientX || 0) +
		tt_Int((tt_ie || tt_kqnew)? tt_db.scrollLeft : 0) +
		tt_offsetX;
	var y = tt_Int(e.pageY || e.clientY || 0) +
		tt_Int((tt_ie || tt_kqnew)? tt_db.scrollTop : 0);
		
		
	if (x > xlim) x = xlim;	
	if (y > ylim || !tt_dwn && y > ylim-(6<<2))
	{
		y -= (tt_objHeight + 5);
		tt_dwn = false;
	}
	else
	{
		y += tt_offsetY;
		tt_dwn = true;
	}
		
	tt_SetDivPos(x, y);
	if (!tt_vis) tt_ShowDiv();	
}


function tt_Hide()
{
	if (typeof tt_obj != tt_u && tt_obj)
	{
		tt_HideDiv();
		tt_obj = null;
		if (document.releaseEvents)	document.releaseEvents(Event.MOUSEMOVE);
		document.onmousemove = null;
	}
}


tt_Init();
