// ***************************************************************************
//                          wmToolTip.js  -  description
//                             -------------------
//    begin                : Fri Dec 9 2005
//    copyright            : (C) 2005 by Andrei Gavrila
//    email                : andrei.gavrila@gmail.com
// ***************************************************************************
//
// ***************************************************************************
// *                                                                         *
// *   This program is free software; you can redistribute it and/or modify  *
// *   it under the terms of the GNU General Public License as published by  *
// *   the Free Software Foundation; either version 2 of the License, or     *
// *   (at your option) any later version.                                   *
// *                                                                         *
// ***************************************************************************

var wmToolTipIndex      = 0;
var wmToolTipQuickIndex = 0;

var wmToolTipQuickArray = Array();

function wmToolTip(element, text)
{
	// Create the tool tip
	//

	var wmToolTip       = document.createElement('div');
	wmToolTip.id        = 'wmToolTip_' + wmToolTipIndex;
	wmToolTip.className = 'wmToolTip';
	wmToolTip.innerHTML = text;

	// Attach the events
	//

	eval('wmAddEventListener(element, "mouseover", function () { wmToolTipMove(' + wmToolTipIndex + ', 0); }, false);');
	eval('wmAddEventListener(element, "mousemove", function () { wmToolTipMove(' + wmToolTipIndex + ', 1); }, false);');
	eval('wmAddEventListener(element, "mouseout",  function () { wmToolTipMove(' + wmToolTipIndex + ', 2); }, false);');

	// Attach it to the main window
	//

	wmGetElementById(wmContainerId).appendChild(wmToolTip);

	wmToolTipIndex++;
}

function wmToolTipMove(index, display)
{
	wmZIndex('wmToolTip_' + index, wmZIndexIndex);
	wmZIndexIndex++;

	wmMove('wmToolTip_' + index, mouse_x + 10, mouse_y + 10);

	if (display == 0) {
		var i = 0;

		for (i = 0; i < wmToolTipIndex; i++)
			if (i != index)
				wmHide('wmToolTip_' + i);

		wmShow('wmToolTip_' + index);
	}

	if (display == 2)
		wmHide('wmToolTip_' + index);
}

function wmToolTipHideAll()
{
	var i = 0;

	for (i = 0; i < wmToolTipIndex; i++)
		wmHide('wmToolTip_' + i);
}

function wmToolTipQuick(name, element, text)
{
	var i     = 0;
	var found = false;

	for (i = 0; i < wmToolTipQuickIndex; i++)
		if (wmToolTipQuickArray[i] == name)
			found = true;

	if (found == false) {
		wmToolTip(element, text);
		wmToolTipMove(wmToolTipIndex - 1, 0);

		wmToolTipQuickArray[wmToolTipQuickIndex] = name;
		wmToolTipQuickIndex++;
	}
}

