// Title: Tigra Hints
// URL: http://www.softcomplex.com/products/tigra_hints/
// Version: 1.2
// Date: 04/18/2003 (mm/dd/yyyy)
// Feedback: feedback@softcomplex.com (specify product title in the subject)
// Note: Permission given to use this script in ANY kind of applications if
//    header lines are left unchanged.
// About us: Our company provides offshore IT consulting services.
//    Contact us at sales@softcomplex.com if you have any programming task you
//    want to be handled by professionals. Our typical hourly rate is $20.

function PointerXY ()
{
    this.x = 0;
    this.y = 0;
    
    this.setCoords = function (x, y) 
    {
        this.x = x;
        this.y = y;
    }
}
var coords = new PointerXY (); 
 
function THints (o_cfg, items, obj_name) 
{
    this.obj_name = obj_name;
	this.top = o_cfg.top ? o_cfg.top : 0;
	this.left = o_cfg.left ? o_cfg.left : 0;
	this.n_dl_show = o_cfg.show_delay;
	this.n_dl_hide = o_cfg.hide_delay;
	this.b_wise = o_cfg.wise;
	this.b_follow = o_cfg.follow;
	this.x = 0;
	this.y = 0;
	this.divs = [];
	this.show  = TTipShow;
	this.showD = TTipShowD;
	this.hide = TTipHide;
	this.move = TTipMove;
	if (document.layers) return;
	var b_IE = navigator.userAgent.indexOf('MSIE') > -1,
	s_tag = ['<div id="' + this.obj_name + 'TTip%name%" style="visibility:hidden;position:absolute;top:0px;left:0px;',  b_IE ? 'width:1px;height:1px;' : '', o_cfg['z-index'] != null ? 'z-index:' + o_cfg['z-index'] : '', '"><table cellpadding="0" cellspacing="0" border="0"><tr><td class="', o_cfg.css, '">%text%</td></tr></table></div>'].join('');


	this.getElem = 
		function (id) { return document.all ? document.all[id] : document.getElementById(id); };
		
	this.showElem = 
		function (id, hide) { this.divs[id].o_css.visibility = hide ? 'hidden' : 'visible'; };
		
	this.getWinSz = window.innerHeight != null 
		? function (b_hight) { return b_hight ? innerHeight : innerWidth; }
		: function (b_hight) { return document.body[b_hight ? 'clientHeight' : 'clientWidth']; };
        	
	this.getWinSc = window.innerHeight != null 
		? function (b_hight) { return b_hight ? pageYOffset : pageXOffset; }
		: function (b_hight) { return document.body[b_hight ? 'scrollTop' : 'scrollLeft']; };
        	
        	
	if (window.opera) 
    {
		this.getSize = function (id, b_hight) { 
			return this.divs[id].o_css[b_hight ? 'pixelHeight' : 'pixelWidth']
		};
	}
	else 
    {
		this.getSize = function (id, b_hight) { 
			return this.divs[id].o_obj[b_hight ? 'offsetHeight' : 'offsetWidth'] 
		};
	}

    if(document.addEventListener)
    {
        document.addEventListener ('mousemove',f_onMouseMove,false);
    }
    if(window.attachEvent)
    {
        document.attachEvent ('onmousemove',f_onMouseMove);
    }
    else
    {
        document.onmousemove=f_onMouseMove;
    }
	
	for (i in items) {
		document.write (s_tag.replace(/%text%/, items[i]).replace(/%name%/, i));
		this.divs[i] = { 'o_obj' : this.getElem(this.obj_name + 'TTip' + i) };
		this.divs[i].o_css = this.divs[i].o_obj.style;
	}
}

function TTipShow (id) 
{
	if (document.layers) return;
	this.hide();
	if (this.divs[id]) {
		if (this.n_dl_show) this.divs[id].timer = setTimeout(this.obj_name + ".showD(" + id + ")", this.n_dl_show);
		else this.showD(id);
		this.visible = id;
	}
}

function TTipShowD (id) 
{
	this.move(id);
	this.showElem(id);
	if (this.n_dl_hide) this.timer = setTimeout(this.obj_name + ".hide()", this.n_dl_hide);
}

function TTipMove (id) 
{
    this.x = coords.x;
	this.y = coords.y;
	
	var n_x = this.x + this.left, n_y = this.y + this.top;
	if (this.b_wise) {
		var n_w = this.getSize(id), n_h = this.getSize(id, true),
		n_win_w = this.getWinSz(), n_win_h = this.getWinSz(true),
		n_win_l = this.getWinSc(), n_win_t = this.getWinSc(true);
		if (n_x + n_w > n_win_w + n_win_l) n_x = n_win_w + n_win_l - n_w;
		if (n_x < n_win_l) n_x = n_win_l;
		if (n_y + n_h > n_win_h + n_win_t) n_y = n_win_h + n_win_t - n_h;
		if (n_y < n_win_t) n_y = n_win_t;
	}
	this.divs[id].o_css.left = n_x + "px";
	this.divs[id].o_css.top = n_y + "px";
}

function TTipHide () 
{
	if (this.timer) clearTimeout(this.timer);
	if (this.visible != null) {
		if (this.divs[this.visible].timer) clearTimeout(this.divs[this.visible].timer);
		setTimeout(this.obj_name + ".showElem(" + this.visible + ", true)", 10);
		this.visible = null;
	}
}


function f_onMouseMove (H)
{
    if (!H && window.event) H = window.event;
    if (!H) return true;
    var n_mouseX = H.pageX ? H.pageX : H.clientX + f_scrollLeft ();
    var n_mouseY = H.pageY ? H.pageY+2 : H.clientY + f_scrollTop ();
    coords.setCoords (n_mouseX, n_mouseY);
}

function f_scrollLeft ()
{
    if (typeof (window.pageXOffset) == 'number') return window.pageXOffset;
    if (document.body && document.body.scrollLeft) return document.body.scrollLeft;
    if (document.documentElement && document.documentElement.scrollLeft) return document.documentElement.scrollLeft;
    return 0;
}

function f_scrollTop ()
{
    if (typeof (window.pageYOffset) == 'number') return window.pageYOffset;
    if (document.body && document.body.scrollTop) return document.body.scrollTop;
    if (document.documentElement && document.documentElement.scrollTop) return document.documentElement.scrollTop;
    return 0;
}



var HINTS_CFG = {
	'top'        : 5, // a vertical offset of a hint from mouse pointer
	'left'       : 10, // a horizontal offset of a hint from mouse pointer
	'css'        : 'hintsClass', // a style class name for all hints, TD object
	'show_delay' : 400, // a delay between object mouseover and hint appearing
	'hide_delay' : 6000, // a delay between hint appearing and hint hiding
	'wise'       : true,
	'follow'     : false,
	'z-index'    : 0 // a z-index for all hint layers
};
