/* This notice must be untouched at all times.
Copyright (c) 2002-2008 Walter Zorn. All rights reserved.

wz_tooltip.js	 v. 5.1

The latest version is available at
http://www.walterzorn.com
or http://www.devira.com
or http://www.walterzorn.de

Created 1.12.2002 by Walter Zorn (Web: http://www.walterzorn.com )
Last modified: 10.4.2008

Easy-to-use cross-browser tooltips.
Just include the script at the beginning of the <body> section, and invoke
Tip('Tooltip text') from the desired HTML onmouseover eventhandlers,
and UnTip(), usually from the onmouseout eventhandlers, to hide the tip.
No container DIV required.
By default, width and height of tooltips are automatically adapted to content.
Is even capable of dynamically converting arbitrary HTML elements to tooltips
by calling TagToInTip('ID_of_HTML_element_to_be_converted') instead of Tip(),
which means you can put important, search-engine-relevant stuff into tooltips.
Appearance & behaviour of tooltips can be individually configured
via commands passed to Tip() or TagToInTip().

Tab Width: 4
LICENSE: LGPL

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License (LGPL) as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

For more details on the GNU Lesser General Public License,
see http://www.gnu.org/copyleft/lesser.html
*/

var inconfig = new Object();


//===================  GLOBAL TOOPTIP CONFIGURATION  =========================//
var intt_Debug	= false		// false or true - recommended: false once you release your page to the public
var intt_Enabled= true		// Allows to (temporarily) suppress tooltips, e.g. by providing the user with a button that sets this global variable to false
var TagsToInTip	= false		// false or true - if true, HTML elements to be converted to tooltips via TagToInTip() are automatically hidden;
							// if false, you should hide those HTML elements yourself

// For each of the following config variables there exists a command, which is
// just the variablename in uppercase, to be passed to Tip() or TagToInTip() to
// configure tooltips individually. Individual commands override global
// configuration. Order of commands is arbitrary.
// Example: onmouseover="Tip('Tooltip text', LEFT, true, BGCOLOR, '#FF9900', FADEIN, 400)"

inconfig.Above			= false    	// false or true - tooltip above mousepointer
inconfig.BgColor 		= '#FFFFFF' // Background colour (HTML colour value, in quotes)
inconfig.BgImg			= ''		// Path to background image, none if empty string ''
inconfig.BorderColor	= '#B00303' //  
inconfig.BorderStyle	= 'solid'	// Any permitted CSS value, but I recommend 'solid', 'dotted' or 'dashed'
inconfig.BorderWidth	= 1
inconfig.CenterMouse	= false 	// false or true - center the tip horizontally below (or above) the mousepointer
inconfig.ClickClose		= false 	// false or true - close tooltip if the user clicks somewhere
inconfig.ClickSticky	= false		// false or true - make tooltip sticky if user left-clicks on the hovered element while the tooltip is active
inconfig.CloseBtn		= false 	// false or true - closebutton in titlebar
inconfig.CloseBtnColors	= ['#B00303', '#FFFFFF', '#FFFFFF', '#000000']	  // [Background, text, hovered background, hovered text] - use empty strings '' to inherit title colours
inconfig.CloseBtnText	= '&nbsp;X&nbsp;'	// Close button text (may also be an image tag)
inconfig.CopyContent	= true		// When converting a HTML element to a tooltip, copy only the element's content, rather than converting the element by its own
inconfig.Delay			= 400		// Time span in ms until tooltip shows up
inconfig.Duration		= 0 		// Time span in ms after which the tooltip disappears; 0 for infinite duration, < 0 for delay in ms _after_ the onmouseout until the tooltip disappears
inconfig.FadeIn			= 0 		// Fade-in duration in ms, e.g. 400; 0 for no animation
inconfig.FadeOut		= 0
inconfig.FadeInterval	= 30		// Duration of each fade step in ms (recommended: 30) - shorter is smoother but causes more CPU-load
inconfig.Fix			= null		// Fixated position - x- an y-oordinates in brackets, e.g. [210, 480], or null for no fixation
inconfig.FollowMouse	= true		// false or true - tooltip follows the mouse
inconfig.FontColor		= '#000000'
inconfig.FontFace		= 'Verdana,Geneva,sans-serif'
inconfig.FontSize		= '8pt' 	// E.g. '9pt' or '12px' - unit is mandatory
inconfig.FontWeight		= 'normal'	// 'normal' or 'bold';
inconfig.Height			= 0 		// Tooltip height; 0 for automatic adaption to tooltip content, < 0 (e.g. -100) for a maximum for automatic adaption
inconfig.JumpHorz		= false		// false or true - jump horizontally to other side of mouse if tooltip would extend past clientarea boundary
inconfig.JumpVert		= true		// false or true - jump vertically		"
inconfig.Left			= true   	// false or true - tooltip on the left of the mouse
inconfig.OffsetX		= 14		// Horizontal offset of left-top corner from mousepointer
inconfig.OffsetY		= 8 		// Vertical offset
inconfig.Opacity		= 100		// Integer between 0 and 100 - opacity of tooltip in percent
inconfig.Padding		= 3 		// Spacing between border and content
inconfig.Shadow			= false 	// false or true
inconfig.ShadowColor	= '#C0C0C0'
inconfig.ShadowWidth	= 5
inconfig.Sticky			= false 	// false or true - fixate tip, ie. don't follow the mouse and don't hide on mouseout
inconfig.TextAlign		= 'left'	// 'left', 'right' or 'justify'
inconfig.Title			= ''		// Default title text applied to all tips (no default title: empty string '')
inconfig.TitleAlign		= 'left'	// 'left' or 'right' - text alignment inside the title bar
inconfig.TitleBgColor	= ''		// If empty string '', BorderColor will be used
inconfig.TitleFontColor	= '#FFFFFF'	// Color of title text - if '', BgColor (of tooltip body) will be used
inconfig.TitleFontFace	= ''		// If '' use FontFace (boldified)
inconfig.TitleFontSize	= ''		// If '' use FontSize
inconfig.TitlePadding	= 2
inconfig.Width			= 0 		// Tooltip width; 0 for automatic adaption to tooltip content; < -1 (e.g. -240) for a maximum width for that automatic adaption;
									// -1: tooltip width confined to the width required for the titlebar
//=======  END OF TOOLTIP CONFIG, DO NOT CHANGE ANYTHING BELOW  ==============//




//=====================  PUBLIC  =============================================//
function InTip()
{
	intt_Tip(arguments, null);
}
function TagToInTip()
{
	var t2t = intt_GetElt(arguments[0]);
	if(t2t)
		intt_Tip(arguments, t2t);
}
function UnInTip()
{
	intt_OpReHref();
	if(intt_aV[DURATION] < 0)
		intt_tDurt.Timer("intt_HideInit()", -intt_aV[DURATION], true);
	else if(!(intt_aV[STICKY] && (intt_iState & 0x2)))
		intt_HideInit();
}

//==================  PUBLIC PLUGIN API	 =====================================//
// Extension eventhandlers currently supported:
// OnLoadConfig, OnCreateContentString, OnSubDivsCreated, OnShow, OnMoveBefore,
// OnMoveAfter, OnHideInit, OnHide, OnKill

var intt_aElt = new Array(10), // Container DIV, outer title & body DIVs, inner title & body TDs, closebutton SPAN, shadow DIVs, and IFRAME to cover windowed elements in IE
intt_aV = new Array(),	// Caches and enumerates config data for currently active tooltip
intt_sContent,			// Inner tooltip text or HTML
intt_scrlX = 0, intt_scrlY = 0,
intt_musX, intt_musY,
intt_over,
intt_x, intt_y, intt_w, intt_h; // Position, width and height of currently displayed tooltip

function intt_Extension()
{
	intt_ExtCmdEnum();
	intt_aExt[intt_aExt.length] = this;
	return this;
}
function intt_SetTipPos(x, y)
{
	var css = intt_aElt[0].style;

	intt_x = x;
	intt_y = y;
	css.left = x + "px";
	css.top = y + "px";
	if(intt_ie56)
	{
		var ifrm = intt_aElt[intt_aElt.length - 1];
		if(ifrm)
		{
			ifrm.style.left = css.left;
			ifrm.style.top = css.top;
		}
	}
}
function intt_HideInit()
{
	if(intt_iState)
	{
		intt_ExtCallFncs(0, "HideInit");
		intt_iState &= ~0x4;
		if(intt_flagOpa && intt_aV[FADEOUT])
		{
			intt_tFade.EndTimer();
			if(intt_opa)
			{
				var n = Math.round(intt_aV[FADEOUT] / (intt_aV[FADEINTERVAL] * (intt_aV[OPACITY] / intt_opa)));
				intt_Fade(intt_opa, intt_opa, 0, n);
				return;
			}
		}
		intt_tHide.Timer("intt_Hide();", 1, false);
	}
}
function intt_Hide()
{
	if(intt_db && intt_iState)
	{
		intt_OpReHref();
		if(intt_iState & 0x2)
		{
			intt_aElt[0].style.visibility = "hidden";
			intt_ExtCallFncs(0, "Hide");
		}
		intt_tShow.EndTimer();
		intt_tHide.EndTimer();
		intt_tDurt.EndTimer();
		intt_tFade.EndTimer();
		if(!intt_op && !intt_ie)
		{
			intt_tWaitMov.EndTimer();
			intt_bWait = false;
		}
		if(intt_aV[CLICKCLOSE] || intt_aV[CLICKSTICKY])
			intt_RemEvtFnc(document, "mouseup", intt_OnLClick);
		intt_ExtCallFncs(0, "Kill");
		// In case of a TagToInTip tooltip, hide converted DOM node and
		// re-insert it into document
		if(intt_t2t && !intt_aV[COPYCONTENT])
		{
			intt_t2t.style.display = "none";
			intt_MovDomNode(intt_t2t, intt_aElt[6], intt_t2tDad);
		}
		intt_iState = 0;
		intt_over = null;
		intt_ResetMainDiv();
		if(intt_aElt[intt_aElt.length - 1])
			intt_aElt[intt_aElt.length - 1].style.display = "none";
	}
}
function intt_GetElt(id)
{
	return(document.getElementById ? document.getElementById(id)
			: document.all ? document.all[id]
			: null);
}
function intt_GetDivW(el)
{
	return(el ? (el.offsetWidth || el.style.pixelWidth || 0) : 0);
}
function intt_GetDivH(el)
{
	return(el ? (el.offsetHeight || el.style.pixelHeight || 0) : 0);
}
function intt_GetScrollX()
{
	return(window.pageXOffset || (intt_db ? (intt_db.scrollLeft || 0) : 0));
}
function intt_GetScrollY()
{
	return(window.pageYOffset || (intt_db ? (intt_db.scrollTop || 0) : 0));
}
function intt_GetClientW()
{
	return(document.body && (typeof(document.body.clientWidth) != intt_u) ? document.body.clientWidth
			: (typeof(window.innerWidth) != intt_u) ? window.innerWidth
			: intt_db ? (intt_db.clientWidth || 0)
			: 0);
}
function intt_GetClientH()
{
	// Exactly this order seems to yield correct values in all major browsers
	return(document.body && (typeof(document.body.clientHeight) != intt_u) ? document.body.clientHeight
			: (typeof(window.innerHeight) != intt_u) ? window.innerHeight
			: intt_db ? (intt_db.clientHeight || 0)
			: 0);
}
function intt_GetEvtX(e)
{
	return (e ? ((typeof(e.pageX) != intt_u) ? e.pageX : (e.clientX + intt_scrlX)) : 0);
}
function intt_GetEvtY(e)
{
	return (e ? ((typeof(e.pageY) != intt_u) ? e.pageY : (e.clientY + intt_scrlY)) : 0);
}
function intt_AddEvtFnc(el, sEvt, PFnc)
{
	if(el)
	{
		if(el.addEventListener)
			el.addEventListener(sEvt, PFnc, false);
		else
			el.attachEvent("on" + sEvt, PFnc);
	}
}
function intt_RemEvtFnc(el, sEvt, PFnc)
{
	if(el)
	{
		if(el.removeEventListener)
			el.removeEventListener(sEvt, PFnc, false);
		else
			el.detachEvent("on" + sEvt, PFnc);
	}
}

//======================  PRIVATE  ===========================================//
var intt_aExt = new Array(),	// Array of extension objects

intt_db, intt_op, intt_ie, intt_ie56, intt_bBoxOld,	// Browser flags
intt_body,
intt_ovr_,				// HTML element the mouse is currently over
intt_flagOpa, 			// Opacity support: 1=IE, 2=Khtml, 3=KHTML, 4=Moz, 5=W3C
intt_maxPosX, intt_maxPosY,
intt_iState = 0,			// Tooltip active |= 1, shown |= 2, move with mouse |= 4
intt_opa, 				// Currently applied opacity
intt_bJmpVert, intt_bJmpHorz,// Tip temporarily on other side of mouse
intt_t2t, intt_t2tDad,		// Tag converted to tip, and its parent element in the document
intt_elDeHref,			// The tag from which we've removed the href attribute
// Timer
intt_tShow = new Number(0), intt_tHide = new Number(0), intt_tDurt = new Number(0),
intt_tFade = new Number(0), intt_tWaitMov = new Number(0),
intt_bWait = false,
intt_u = "undefined";


function intt_Init()
{
	intt_MkCmdEnum();
	// Send old browsers instantly to hell
	if(!intt_Browser() || !intt_MkMainDiv())
		return;
	intt_IsW3cBox();
	intt_OpaSupport();
	intt_AddEvtFnc(window, "scroll", intt_OnScrl);
	// IE doesn't fire onscroll event when switching to fullscreen;
	// fix suggested by Yoav Karpeles 14.2.2008
	intt_AddEvtFnc(window, "resize", intt_OnScrl);
	intt_AddEvtFnc(document, "mousemove", intt_Move);
	// In Debug mode we search for TagToInTip() calls in order to notify
	// the user if they've forgotten to set the TagsToTip config flag
	if(TagsToInTip || intt_Debug)
		intt_SetOnloadFnc();
	// Ensure the tip be hidden when the page unloads
	intt_AddEvtFnc(window, "unload", intt_Hide);
}
// Creates command names by translating config variable names to upper case
function intt_MkCmdEnum()
{
	var n = 0;
	for(var i in inconfig)
		eval("window." + i.toString().toUpperCase() + " = " + n++);
	intt_aV.length = n;
}
function intt_Browser()
{
	var n, nv, n6, w3c;

	n = navigator.userAgent.toLowerCase(),
	nv = navigator.appVersion;
	intt_op = (document.defaultView && typeof(eval("w" + "indow" + "." + "o" + "p" + "er" + "a")) != intt_u);
	intt_ie = n.indexOf("msie") != -1 && document.all && !intt_op;
	if(intt_ie)
	{
		var ieOld = (!document.compatMode || document.compatMode == "BackCompat");
		intt_db = !ieOld ? document.documentElement : (document.body || null);
		if(intt_db)
			intt_ie56 = parseFloat(nv.substring(nv.indexOf("MSIE") + 5)) >= 5.5
					&& typeof document.body.style.maxHeight == intt_u;
	}
	else
	{
		intt_db = document.documentElement || document.body ||
				(document.getElementsByTagName ? document.getElementsByTagName("body")[0]
				: null);
		if(!intt_op)
		{
			n6 = document.defaultView && typeof document.defaultView.getComputedStyle != intt_u;
			w3c = !n6 && document.getElementById;
		}
	}
	intt_body = (document.getElementsByTagName ? document.getElementsByTagName("body")[0]
				: (document.body || null));
	if(intt_ie || n6 || intt_op || w3c)
	{
		if(intt_body && intt_db)
		{
			if(document.attachEvent || document.addEventListener)
				return true;
		}
		else
			intt_Err("wz_intern_tooltip.js must be included INSIDE the body section,"
					+ " immediately after the opening <body> tag.", false);
	}
	intt_db = null;
	return false;
}
function intt_MkMainDiv()
{
	// Create the tooltip DIV
	if(intt_body.insertAdjacentHTML)
		intt_body.insertAdjacentHTML("afterBegin", intt_MkMainDivHtm());
	else if(typeof intt_body.innerHTML != intt_u && document.createElement && intt_body.appendChild)
		intt_body.appendChild(intt_MkMainDivDom());
	if(window.intt_GetMainDivRefs /* FireFox Alzheimer */ && intt_GetMainDivRefs())
		return true;
	intt_db = null;
	return false;
}
function intt_MkMainDivHtm()
{
	return('<div id="internWzTtDiV"></div>' +
			(intt_ie56 ? ('<iframe id="internWzTtIfRm" src="javascript:false" scrolling="no" frameborder="0" style="filter:Alpha(opacity=0);position:absolute;top:0px;left:0px;display:none;"></iframe>')
			: ''));
}
function intt_MkMainDivDom()
{
	var el = document.createElement("div");
	if(el)
		el.id = "internWzTtDiV";
	return el;
}
function intt_GetMainDivRefs()
{
	intt_aElt[0] = intt_GetElt("internWzTtDiV");
	if(intt_ie56 && intt_aElt[0])
	{
		intt_aElt[intt_aElt.length - 1] = intt_GetElt("internWzTtIfRm");
		if(!intt_aElt[intt_aElt.length - 1])
			intt_aElt[0] = null;
	}
	if(intt_aElt[0])
	{
		var css = intt_aElt[0].style;

		css.visibility = "hidden";
		css.position = "absolute";
		css.overflow = "hidden";
		return true;
	}
	return false;
}
function intt_ResetMainDiv()
{
	var w = (window.screen && screen.width) ? screen.width : 10000;

	intt_SetTipPos(-w, 0);
	intt_aElt[0].innerHTML = "";
	intt_aElt[0].style.width = (w - 1) + "px";
	intt_h = 0;
}
function intt_IsW3cBox()
{
	var css = intt_aElt[0].style;

	css.padding = "10px";
	css.width = "40px";
	intt_bBoxOld = (intt_GetDivW(intt_aElt[0]) == 40);
	css.padding = "0px";
	intt_ResetMainDiv();
}
function intt_OpaSupport()
{
	var css = intt_body.style;

	intt_flagOpa = (typeof(css.filter) != intt_u) ? 1
				: (typeof(css.KhtmlOpacity) != intt_u) ? 2
				: (typeof(css.KHTMLOpacity) != intt_u) ? 3
				: (typeof(css.MozOpacity) != intt_u) ? 4
				: (typeof(css.opacity) != intt_u) ? 5
				: 0;
}
// Ported from http://dean.edwards.name/weblog/2006/06/again/
// (Dean Edwards et al.)
function intt_SetOnloadFnc()
{
	intt_AddEvtFnc(document, "DOMContentLoaded", intt_HideSrcTags);
	intt_AddEvtFnc(window, "load", intt_HideSrcTags);
	if(intt_body.attachEvent)
		intt_body.attachEvent("onreadystatechange",
			function() {
				if(intt_body.readyState == "complete")
					intt_HideSrcTags();
			} );
	if(/WebKit|KHTML/i.test(navigator.userAgent))
	{
		var t = setInterval(function() {
					if(/loaded|complete/.test(document.readyState))
					{
						clearInterval(t);
						intt_HideSrcTags();
					}
				}, 10);
	}
}
function intt_HideSrcTags()
{
	if(!window.intt_HideSrcTags || window.intt_HideSrcTags.done)
		return;
	window.intt_HideSrcTags.done = true;
	if(!intt_HideSrcTagsRecurs(intt_body))
		intt_Err("There are HTML elements to be converted to tooltips.\nIf you"
				+ " want these HTML elements to be automatically hidden, you"
				+ " must edit wz_intern_tooltip.js, and set TagsToTip in the global"
				+ " tooltip configuration to true.", true);
}
function intt_HideSrcTagsRecurs(dad)
{
	var ovr, asT2t;
	// Walk the DOM tree for tags that have an onmouseover or onclick attribute
	// containing a TagToInTip('...') call.
	// (.childNodes first since .children is bugous in Safari)
	var a = dad.childNodes || dad.children || null;

	for(var i = a ? a.length : 0; i;)
	{--i;
		if(!intt_HideSrcTagsRecurs(a[i]))
			return false;
		ovr = a[i].getAttribute ? (a[i].getAttribute("onmouseover") || a[i].getAttribute("onclick"))
				: (typeof a[i].onmouseover == "function") ? (a[i].onmouseover || a[i].onclick)
				: null;
		if(ovr)
		{
			asT2t = ovr.toString().match(/TagToInTip\s*\(\s*'[^'.]+'\s*[\),]/);
			if(asT2t && asT2t.length)
			{
				if(!intt_HideSrcTag(asT2t[0]))
					return false;
			}
		}
	}
	return true;
}
function intt_HideSrcTag(sT2t)
{
	var id, el;

	// The ID passed to the found TagToInTip() call identifies an HTML element
	// to be converted to a tooltip, so hide that element
	id = sT2t.replace(/.+'([^'.]+)'.+/, "$1");
	el = intt_GetElt(id);
	if(el)
	{
		if(intt_Debug && !TagsToInTip)
			return false;
		else
			el.style.display = "none";
	}
	else
		intt_Err("Invalid ID\n'" + id + "'\npassed to TagToInTip()."
				+ " There exists no HTML element with that ID.", true);
	return true;
}
function intt_Tip(arg, t2t)
{
	if(!intt_db)
		return;
	if(intt_iState)
		intt_Hide();
	if(!intt_Enabled)
		return;
	intt_t2t = t2t;
	if(!intt_ReadCmds(arg))
		return;
	intt_iState = 0x1 | 0x4;
	intt_AdaptConfig1();
	intt_MkTipContent(arg);
	intt_MkTipSubDivs();
	intt_FormatTip();
	intt_bJmpVert = false;
	intt_bJmpHorz = false;
	intt_maxPosX = intt_GetClientW() + intt_scrlX - intt_w - 1;
	intt_maxPosY = intt_GetClientH() + intt_scrlY - intt_h - 1;
	intt_AdaptConfig2();
	// Ensure the tip be shown and positioned before the first onmousemove
	intt_OverInit();
	intt_ShowInit();
	intt_Move();
}
function intt_ReadCmds(a)
{
	var i;

	// First load the global config values, to initialize also values
	// for which no command is passed
	i = 0;
	for(var j in inconfig)
		intt_aV[i++] = inconfig[j];
	// Then replace each cached config value for which a command is
	// passed (ensure the # of command args plus value args be even)
	if(a.length & 1)
	{
		for(i = a.length - 1; i > 0; i -= 2)
			intt_aV[a[i - 1]] = a[i];
		return true;
	}
	intt_Err("Incorrect call of InTip() or TagToInTip().\n"
			+ "Each command must be followed by a value.", true);
	return false;
}
function intt_AdaptConfig1()
{
	intt_ExtCallFncs(0, "LoadConfig");
	// Inherit unspecified title formattings from body
	if(!intt_aV[TITLEBGCOLOR].length)
		intt_aV[TITLEBGCOLOR] = intt_aV[BORDERCOLOR];
	if(!intt_aV[TITLEFONTCOLOR].length)
		intt_aV[TITLEFONTCOLOR] = intt_aV[BGCOLOR];
	if(!intt_aV[TITLEFONTFACE].length)
		intt_aV[TITLEFONTFACE] = intt_aV[FONTFACE];
	if(!intt_aV[TITLEFONTSIZE].length)
		intt_aV[TITLEFONTSIZE] = intt_aV[FONTSIZE];
	if(intt_aV[CLOSEBTN])
	{
		// Use title colours for non-specified closebutton colours
		if(!intt_aV[CLOSEBTNCOLORS])
			intt_aV[CLOSEBTNCOLORS] = new Array("", "", "", "");
		for(var i = 4; i;)
		{--i;
			if(!intt_aV[CLOSEBTNCOLORS][i].length)
				intt_aV[CLOSEBTNCOLORS][i] = (i & 1) ? intt_aV[TITLEFONTCOLOR] : intt_aV[TITLEBGCOLOR];
		}
		// Enforce titlebar be shown
		if(!intt_aV[TITLE].length)
			intt_aV[TITLE] = " ";
	}
	// Circumvents broken display of images and fade-in flicker in Geckos < 1.8
	if(intt_aV[OPACITY] == 100 && typeof intt_aElt[0].style.MozOpacity != intt_u && !Array.every)
		intt_aV[OPACITY] = 99;
	// Smartly shorten the delay for fade-in tooltips
	if(intt_aV[FADEIN] && intt_flagOpa && intt_aV[DELAY] > 100)
		intt_aV[DELAY] = Math.max(intt_aV[DELAY] - intt_aV[FADEIN], 100);
}
function intt_AdaptConfig2()
{
	if(intt_aV[CENTERMOUSE])
	{
		intt_aV[OFFSETX] -= ((intt_w - (intt_aV[SHADOW] ? intt_aV[SHADOWWIDTH] : 0)) >> 1);
		intt_aV[JUMPHORZ] = false;
	}
}
// Expose content globally so extensions can modify it
function intt_MkTipContent(a)
{
	if(intt_t2t)
	{
		if(intt_aV[COPYCONTENT])
			intt_sContent = intt_t2t.innerHTML;
		else
			intt_sContent = "";
	}
	else
		intt_sContent = a[0];
	intt_ExtCallFncs(0, "CreateContentString");
}
function intt_MkTipSubDivs()
{
	var sCss = 'position:relative;margin:0px;padding:0px;border-width:0px;left:0px;top:0px;line-height:normal;width:auto;',
	sTbTrTd = ' cellspacing="0" cellpadding="0" border="0" style="' + sCss + '"><tbody style="' + sCss + '"><tr><td ';

	intt_aElt[0].innerHTML =
		(''
		+ (intt_aV[TITLE].length ?
			('<div id="internWzTiTl" style="position:relative;z-index:1;">'
			+ '<table id="internWzTiTlTb"' + sTbTrTd + 'id="internWzTiTlI" style="' + sCss + '">'
			+ intt_aV[TITLE]
			+ '</td>'
			+ (intt_aV[CLOSEBTN] ?
				('<td align="right" style="' + sCss
				+ 'text-align:right;">'
				+ '<span id="internWzClOsE" style="position:relative;left:2px;padding-left:2px;padding-right:2px;'
				+ 'cursor:' + (intt_ie ? 'hand' : 'pointer')
				+ ';" onmouseover="intt_OnCloseBtnOver(1)" onmouseout="intt_OnCloseBtnOver(0)" onclick="intt_HideInit()">'
				+ intt_aV[CLOSEBTNTEXT]
				+ '</span></td>')
				: '')
			+ '</tr></tbody></table></div>')
			: '')
		+ '<div id="internWzBoDy" style="position:relative;z-index:0;">'
		+ '<table' + sTbTrTd + 'id="internWzBoDyI" style="' + sCss + '">'
		+ intt_sContent
		+ '</td></tr></tbody></table></div>'
		+ (intt_aV[SHADOW]
			? ('<div id="internWzTtShDwR" style="position:absolute;overflow:hidden;"></div>'
				+ '<div id="internWzTtShDwB" style="position:relative;overflow:hidden;"></div>')
			: '')
		);
	intt_GetSubDivRefs();
	// Convert DOM node to tip
	if(intt_t2t && !intt_aV[COPYCONTENT])
	{
		// Store the tag's parent element so we can restore that DOM branch
		// once the tooltip is hidden
		intt_t2tDad = intt_t2t.parentNode || intt_t2t.parentElement || intt_t2t.offsetParent || null;
		if(intt_t2tDad)
		{
			intt_MovDomNode(intt_t2t, intt_t2tDad, intt_aElt[6]);
			intt_t2t.style.display = "block";
		}
	}
	intt_ExtCallFncs(0, "SubDivsCreated");
}
function intt_GetSubDivRefs()
{
	var aId = new Array("internWzTiTl", "internWzTiTlTb", "internWzTiTlI", "internWzClOsE", "internWzBoDy", "internWzBoDyI", "internWzTtShDwB", "internWzTtShDwR");

	for(var i = aId.length; i; --i)
		intt_aElt[i] = intt_GetElt(aId[i - 1]);
}
function intt_FormatTip()
{
	var css, w, h, pad = intt_aV[PADDING], padT, wBrd = intt_aV[BORDERWIDTH],
	iOffY, iOffSh, iAdd = (pad + wBrd) << 1;
	
	//--------- Title DIV ----------
	if(intt_aV[TITLE].length)
	{
		padT = intt_aV[TITLEPADDING];
		css = intt_aElt[1].style;
		css.background = intt_aV[TITLEBGCOLOR];
		css.paddingTop = css.paddingBottom = padT + "px";
		css.paddingLeft = css.paddingRight = (padT + 2) + "px";
		css = intt_aElt[3].style;
		css.color = intt_aV[TITLEFONTCOLOR];
		if(intt_aV[WIDTH] == -1)
			css.whiteSpace = "nowrap";
		css.fontFamily = intt_aV[TITLEFONTFACE];
		css.fontSize = intt_aV[TITLEFONTSIZE];
		css.fontWeight = "bold";
		css.textAlign = intt_aV[TITLEALIGN];
		// Close button DIV
		if(intt_aElt[4])
		{
			css = intt_aElt[4].style;
			css.background = intt_aV[CLOSEBTNCOLORS][0];
			css.color = intt_aV[CLOSEBTNCOLORS][1];
			css.fontFamily = intt_aV[TITLEFONTFACE];
			css.fontSize = intt_aV[TITLEFONTSIZE];
			css.fontWeight = "bold";
		}
		if(intt_aV[WIDTH] > 0)
			intt_w = intt_aV[WIDTH];
		else
		{
			intt_w = intt_GetDivW(intt_aElt[3]) + intt_GetDivW(intt_aElt[4]);
			// Some spacing between title DIV and closebutton
			if(intt_aElt[4])
				intt_w += pad;
			// Restrict auto width to max width
			if(intt_aV[WIDTH] < -1 && intt_w > -intt_aV[WIDTH])
				intt_w = -intt_aV[WIDTH];
		}
		// Ensure the top border of the body DIV be covered by the title DIV
		iOffY = -wBrd;
	}
	else
	{
		intt_w = 0;
		iOffY = 0;
	}

	//-------- Body DIV ------------
	css = intt_aElt[5].style;
	css.top = iOffY + "px";
	if(wBrd)
	{
		css.borderColor = intt_aV[BORDERCOLOR];
		css.borderStyle = intt_aV[BORDERSTYLE];
		css.borderWidth = wBrd + "px";
	}
	if(intt_aV[BGCOLOR].length)
		css.background = intt_aV[BGCOLOR];
	if(intt_aV[BGIMG].length)
		css.backgroundImage = "url(" + intt_aV[BGIMG] + ")";
	css.padding = pad + "px";
	css.textAlign = intt_aV[TEXTALIGN];
	if(intt_aV[HEIGHT])
	{
		css.overflow = "auto";
		if(intt_aV[HEIGHT] > 0)
			css.height = (intt_aV[HEIGHT] + iAdd) + "px";
		else
			intt_h = iAdd - intt_aV[HEIGHT];
	}
	// TD inside body DIV
	css = intt_aElt[6].style;
	css.color = intt_aV[FONTCOLOR];
	css.fontFamily = intt_aV[FONTFACE];
	css.fontSize = intt_aV[FONTSIZE];
	css.fontWeight = intt_aV[FONTWEIGHT];
	css.background = "";
	css.textAlign = intt_aV[TEXTALIGN];
	if(intt_aV[WIDTH] > 0)
		w = intt_aV[WIDTH];
	// Width like title (if existent)
	else if(intt_aV[WIDTH] == -1 && intt_w)
		w = intt_w;
	else
	{
		// Measure width of the body's inner TD, as some browsers would expand
		// the container and outer body DIV to 100%
		w = intt_GetDivW(intt_aElt[6]);
		// Restrict auto width to max width
		if(intt_aV[WIDTH] < -1 && w > -intt_aV[WIDTH])
			w = -intt_aV[WIDTH];
	}
	if(w > intt_w)
		intt_w = w;
	intt_w += iAdd;

	//--------- Shadow DIVs ------------
	if(intt_aV[SHADOW])
	{
		intt_w += intt_aV[SHADOWWIDTH];
		iOffSh = Math.floor((intt_aV[SHADOWWIDTH] * 4) / 3);
		// Bottom shadow
		css = intt_aElt[7].style;
		css.top = iOffY + "px";
		css.left = iOffSh + "px";
		css.width = (intt_w - iOffSh - intt_aV[SHADOWWIDTH]) + "px";
		css.height = intt_aV[SHADOWWIDTH] + "px";
		css.background = intt_aV[SHADOWCOLOR];
		// Right shadow
		css = intt_aElt[8].style;
		css.top = iOffSh + "px";
		css.left = (intt_w - intt_aV[SHADOWWIDTH]) + "px";
		css.width = intt_aV[SHADOWWIDTH] + "px";
		css.background = intt_aV[SHADOWCOLOR];
	}
	else
		iOffSh = 0;

	//-------- Container DIV -------
	intt_SetTipOpa(intt_aV[FADEIN] ? 0 : intt_aV[OPACITY]);
	intt_FixSize(iOffY, iOffSh);
}
// Fixate the size so it can't dynamically change while the tooltip is moving.
function intt_FixSize(iOffY, iOffSh)
{
	var wIn, wOut, h, add, pad = intt_aV[PADDING], wBrd = intt_aV[BORDERWIDTH], i;

	intt_aElt[0].style.width = intt_w + "px";
	intt_aElt[0].style.pixelWidth = intt_w;
	wOut = intt_w - ((intt_aV[SHADOW]) ? intt_aV[SHADOWWIDTH] : 0);
	// Body
	wIn = wOut;
	if(!intt_bBoxOld)
		wIn -= (pad + wBrd) << 1;
	intt_aElt[5].style.width = wIn + "px";
	// Title
	if(intt_aElt[1])
	{
		wIn = wOut - ((intt_aV[TITLEPADDING] + 2) << 1);
		if(!intt_bBoxOld)
			wOut = wIn;
		intt_aElt[1].style.width = wOut + "px";
		intt_aElt[2].style.width = wIn + "px";
	}
	// Max height specified
	if(intt_h)
	{
		h = intt_GetDivH(intt_aElt[5]);
		if(h > intt_h)
		{
			if(!intt_bBoxOld)
				intt_h -= (pad + wBrd) << 1;
			intt_aElt[5].style.height = intt_h + "px";
		}
	}
	intt_h = intt_GetDivH(intt_aElt[0]) + iOffY;
	// Right shadow
	if(intt_aElt[8])
		intt_aElt[8].style.height = (intt_h - iOffSh) + "px";
	i = intt_aElt.length - 1;
	if(intt_aElt[i])
	{
		intt_aElt[i].style.width = intt_w + "px";
		intt_aElt[i].style.height = intt_h + "px";
	}
}
function intt_DeAlt(el)
{
	var aKid;

	if(el)
	{
		if(el.alt)
			el.alt = "";
		if(el.title)
			el.title = "";
		aKid = el.childNodes || el.children || null;
		if(aKid)
		{
			for(var i = aKid.length; i;)
				intt_DeAlt(aKid[--i]);
		}
	}
}
// This hack removes the native tooltips over links in Opera
function intt_OpDeHref(el)
{
	if(!intt_op)
		return;
	if(intt_elDeHref)
		intt_OpReHref();
	while(el)
	{
		if(el.hasAttribute("href"))
		{
			el.t_href = el.getAttribute("href");
			el.t_stats = window.status;
			el.removeAttribute("href");
			el.style.cursor = "hand";
			intt_AddEvtFnc(el, "mousedown", intt_OpReHref);
			window.status = el.t_href;
			intt_elDeHref = el;
			break;
		}
		el = el.parentElement;
	}
}
function intt_OpReHref()
{
	if(intt_elDeHref)
	{
		intt_elDeHref.setAttribute("href", intt_elDeHref.t_href);
		intt_RemEvtFnc(intt_elDeHref, "mousedown", intt_OpReHref);
		window.status = intt_elDeHref.t_stats;
		intt_elDeHref = null;
	}
}
function intt_OverInit()
{
	if(window.event)
		intt_over = window.event.target || window.event.srcElement;
	else
		intt_over = intt_ovr_;
	intt_DeAlt(intt_over);
	intt_OpDeHref(intt_over);
}
function intt_ShowInit()
{
	intt_tShow.Timer("intt_Show()", intt_aV[DELAY], true);
	if(intt_aV[CLICKCLOSE] || intt_aV[CLICKSTICKY])
		intt_AddEvtFnc(document, "mouseup", intt_OnLClick);
}
function intt_Show()
{
	var css = intt_aElt[0].style;

	// Override the z-index of the topmost wz_dragdrop.js D&D item
	css.zIndex = Math.max((window.dd && dd.z) ? (dd.z + 2) : 0, 1020);
	if(intt_aV[STICKY] || !intt_aV[FOLLOWMOUSE])
		intt_iState &= ~0x4;
	if(intt_aV[DURATION] > 0)
		intt_tDurt.Timer("intt_HideInit()", intt_aV[DURATION], true);
	intt_ExtCallFncs(0, "Show")
	css.visibility = "visible";
	intt_iState |= 0x2;
	if(intt_aV[FADEIN])
		intt_Fade(0, 0, intt_aV[OPACITY], Math.round(intt_aV[FADEIN] / intt_aV[FADEINTERVAL]));
	intt_ShowIfrm();
}
function intt_ShowIfrm()
{
	if(intt_ie56)
	{
		var ifrm = intt_aElt[intt_aElt.length - 1];
		if(ifrm)
		{
			var css = ifrm.style;
			css.zIndex = intt_aElt[0].style.zIndex - 1;
			css.display = "block";
		}
	}
}
function intt_Move(e)
{
	if(e)
		intt_ovr_ = e.target || e.srcElement;
	e = e || window.event;
	if(e)
	{
		intt_musX = intt_GetEvtX(e);
		intt_musY = intt_GetEvtY(e);
	}
	if(intt_iState & 0x04)
	{
		// Prevent jam of mousemove events
		if(!intt_op && !intt_ie)
		{
			if(intt_bWait)
				return;
			intt_bWait = true;
			intt_tWaitMov.Timer("intt_bWait = false;", 1, true);
		}
		if(intt_aV[FIX])
		{
			var iY = intt_aV[FIX][1];
			// For a fixed tip to be positioned above the mouse, use the
			// bottom edge as anchor
			// (recommended by Christophe Rebeschini, 31.1.2008)
			if(intt_aV[ABOVE])
				iY -= intt_h;
			intt_iState &= ~0x4;
			intt_SetTipPos(intt_aV[FIX][0], intt_aV[FIX][1]);
		}
		else if(!intt_ExtCallFncs(e, "MoveBefore"))
			intt_SetTipPos(intt_Pos(0), intt_Pos(1));
		intt_ExtCallFncs([intt_musX, intt_musY], "MoveAfter")
	}
}
function intt_Pos(iDim)
{
	var iX, bJmpMode, cmdAlt, cmdOff, cx, iMax, iScrl, iMus, bJmp;

	// Map values according to dimension to calculate
	if(iDim)
	{
		bJmpMode = intt_aV[JUMPVERT];
		cmdAlt = ABOVE;
		cmdOff = OFFSETY;
		cx = intt_h;
		iMax = intt_maxPosY;
		iScrl = intt_scrlY;
		iMus = intt_musY;
		bJmp = intt_bJmpVert;
	}
	else
	{
		bJmpMode = intt_aV[JUMPHORZ];
		cmdAlt = LEFT;
		cmdOff = OFFSETX;
		cx = intt_w;
		iMax = intt_maxPosX;
		iScrl = intt_scrlX;
		iMus = intt_musX;
		bJmp = intt_bJmpHorz;
	}
	if(bJmpMode)
	{
		if(intt_aV[cmdAlt] && (!bJmp || intt_CalcPosAlt(iDim) >= iScrl + 16))
			iX = intt_PosAlt(iDim);
		else if(!intt_aV[cmdAlt] && bJmp && intt_CalcPosDef(iDim) > iMax - 16)
			iX = intt_PosAlt(iDim);
		else
			iX = intt_PosDef(iDim);
	}
	else
	{
		iX = iMus;
		if(intt_aV[cmdAlt])
			iX -= cx + intt_aV[cmdOff] - (intt_aV[SHADOW] ? intt_aV[SHADOWWIDTH] : 0);
		else
			iX += intt_aV[cmdOff];
	}
	// Prevent tip from extending past clientarea boundary
	if(iX > iMax)
		iX = bJmpMode ? intt_PosAlt(iDim) : iMax;
	// In case of insufficient space on both sides, ensure the left/upper part
	// of the tip be visible
	if(iX < iScrl)
		iX = bJmpMode ? intt_PosDef(iDim) : iScrl;
	return iX;
}
function intt_PosDef(iDim)
{
	if(iDim)
		intt_bJmpVert = intt_aV[ABOVE];
	else
		intt_bJmpHorz = intt_aV[LEFT];
	return intt_CalcPosDef(iDim);
}
function intt_PosAlt(iDim)
{
	if(iDim)
		intt_bJmpVert = !intt_aV[ABOVE];
	else
		intt_bJmpHorz = !intt_aV[LEFT];
	return intt_CalcPosAlt(iDim);
}
function intt_CalcPosDef(iDim)
{
	return iDim ? (intt_musY + intt_aV[OFFSETY]) : (intt_musX + intt_aV[OFFSETX]);
}
function intt_CalcPosAlt(iDim)
{
	var cmdOff = iDim ? OFFSETY : OFFSETX;
	var dx = intt_aV[cmdOff] - (intt_aV[SHADOW] ? intt_aV[SHADOWWIDTH] : 0);
	if(intt_aV[cmdOff] > 0 && dx <= 0)
		dx = 1;
	return((iDim ? (intt_musY - intt_h) : (intt_musX - intt_w)) - dx);
}
function intt_Fade(a, now, z, n)
{
	if(n)
	{
		now += Math.round((z - now) / n);
		if((z > a) ? (now >= z) : (now <= z))
			now = z;
		else
			intt_tFade.Timer("intt_Fade("
							+ a + "," + now + "," + z + "," + (n - 1)
							+ ")",
							intt_aV[FADEINTERVAL],
							true);
	}
	now ? intt_SetTipOpa(now) : intt_Hide();
}
function intt_SetTipOpa(opa)
{
	// To circumvent the opacity nesting flaws of IE, we set the opacity
	// for each sub-DIV separately, rather than for the container DIV.
	intt_SetOpa(intt_aElt[5], opa);
	if(intt_aElt[1])
		intt_SetOpa(intt_aElt[1], opa);
	if(intt_aV[SHADOW])
	{
		opa = Math.round(opa * 0.8);
		intt_SetOpa(intt_aElt[7], opa);
		intt_SetOpa(intt_aElt[8], opa);
	}
}
function intt_OnScrl()
{
	intt_scrlX = intt_GetScrollX();
	intt_scrlY = intt_GetScrollY();
}
function intt_OnCloseBtnOver(iOver)
{
	var css = intt_aElt[4].style;

	iOver <<= 1;
	css.background = intt_aV[CLOSEBTNCOLORS][iOver];
	css.color = intt_aV[CLOSEBTNCOLORS][iOver + 1];
}
function intt_OnLClick(e)
{
	//  Ignore right-clicks
	e = e || window.event;
	if(!((e.button && e.button & 2) || (e.which && e.which == 3)))
	{
		if(intt_aV[CLICKSTICKY] && (intt_iState & 0x4))
		{
			intt_aV[STICKY] = true;
			intt_iState &= ~0x4;
		}
		else if(intt_aV[CLICKCLOSE])
			intt_HideInit();
	}
}
function intt_Int(x)
{
	var y;

	return(isNaN(y = parseInt(x)) ? 0 : y);
}
Number.prototype.Timer = function(s, iT, bUrge)
{
	if(!this.value || bUrge)
		this.value = window.setTimeout(s, iT);
}
Number.prototype.EndTimer = function()
{
	if(this.value)
	{
		window.clearTimeout(this.value);
		this.value = 0;
	}
}
function intt_SetOpa(el, opa)
{
	var css = el.style;

	intt_opa = opa;
	if(intt_flagOpa == 1)
	{
		if(opa < 100)
		{
			// Hacks for bugs of IE:
			// 1.) Once a CSS filter has been applied, fonts are no longer
			// anti-aliased, so we store the previous 'non-filter' to be
			// able to restore it
			if(typeof(el.filtNo) == intt_u)
				el.filtNo = css.filter;
			// 2.) A DIV cannot be made visible in a single step if an
			// opacity < 100 has been applied while the DIV was hidden
			var bVis = css.visibility != "hidden";
			// 3.) In IE6, applying an opacity < 100 has no effect if the
			//	   element has no layout (position, size, zoom, ...)
			css.zoom = "100%";
			if(!bVis)
				css.visibility = "visible";
			css.filter = "alpha(opacity=" + opa + ")";
			if(!bVis)
				css.visibility = "hidden";
		}
		else if(typeof(el.filtNo) != intt_u)
			// Restore 'non-filter'
			css.filter = el.filtNo;
	}
	else
	{
		opa /= 100.0;
		switch(intt_flagOpa)
		{
		case 2:
			css.KhtmlOpacity = opa; break;
		case 3:
			css.KHTMLOpacity = opa; break;
		case 4:
			css.MozOpacity = opa; break;
		case 5:
			css.opacity = opa; break;
		}
	}
}
function intt_MovDomNode(el, dadFrom, dadTo)
{
	if(dadFrom)
		dadFrom.removeChild(el);
	if(dadTo)
		dadTo.appendChild(el);
}
function intt_Err(sErr, bIfDebug)
{
	if(intt_Debug || !bIfDebug)
		alert("InTooltip Script Error Message:\n\n" + sErr);
}

//============  EXTENSION (PLUGIN) MANAGER  ===============//
function intt_ExtCmdEnum()
{
	var s;

	// Add new command(s) to the commands enum
	for(var i in inconfig)
	{
		s = "window." + i.toString().toUpperCase();
		if(eval("typeof(" + s + ") == intt_u"))
		{
			eval(s + " = " + intt_aV.length);
			intt_aV[intt_aV.length] = null;
		}
	}
}
function intt_ExtCallFncs(arg, sFnc)
{
	var b = false;
	for(var i = intt_aExt.length; i;)
	{--i;
		var fnc = intt_aExt[i]["On" + sFnc];
		// Call the method the extension has defined for this event
		if(fnc && fnc(arg))
			b = true;
	}
	return b;
}

intt_Init();

