// Title: Tigra Hints
// URL: http://www.softcomplex.com/products/tigra_hints/
// Version: 1.3
// Date: 09/03/2003 (mm/dd/yyyy)
// Note: Permission given to use this script in ANY kind of applications if
//    header lines are left unchanged.

var THintsS = [];
function THints (o_cfg, items) {
	this.top = o_cfg.top ? o_cfg.top : 0;
	this.left = o_cfg.left ? o_cfg.left : 0;
	this.centerx = o_cfg.centerx ? o_cfg.centerx : false;
	this.n_dl_show = o_cfg.show_delay;
	this.n_dl_hide = o_cfg.hide_delay;
	this.n_dl_fade = o_cfg.fade_delay;
	this.b_wise = o_cfg.wise;
	this.b_follow = o_cfg.follow;
	this.b_manpos = o_cfg.manualpos;
	this.x = o_cfg.x ? o_cfg.x : 0;
	this.y = o_cfg.y ? o_cfg.y : 0;
	this.divs = [];
//	this.iframes = [];
	this.show  = TTipShow;
	this.showD = TTipShowD;
	this.showF = TTipShowFade;
	this.hide = TTipHide;
	this.hideD = TTipHideD;
	this.hideF = TTipHideFade;
	this.move = TTipMove;
	this.visible = null;
	// register the object in global collection
	this.n_id = THintsS.length;
	THintsS[this.n_id] = this;
	// filter Netscape 4.x out
	if (document.layers) { alert("layers"); return; }
	var b_IE = navigator.userAgent.indexOf('MSIE') > -1,
	s_tag = ['<div id="TTip%name%" style="visibility:hidden;position:absolute;top:0px;left:0px;',   b_IE ? 'width:auto;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, '" nowrap>%text%</td></tr></table></div>'].join('');
//	s_tag = ['<iframe frameborder="0" scrolling="No" id="TTifip%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'] : '', '" width=1 height=1></iframe><div id="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, '" nowrap>%text%</td></tr></table></div>'].join('');


	this.setPos =
		function (pos,move) {
			this.x = pos.x;
			this.y = pos.y;
			if ( move && this.visible!=null )
				this.move(this.visible);
	};
	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.iframes[id].o_css.visibility = hide ? 'hidden' : 'visible';
			if ( hide ) {
				this.divs[id].o_css.display = 'none'; 
//				this.iframes[id].o_css.display = 'none';
			}
		};
	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 = function (b_hight) {
		if (window.pageYOffset)	{ return b_hight ? window.pageYOffset : window.pageXOffset; }
		else if (document.documentElement && document.documentElement.scrollTop) { return b_hight ? document.documentElement.scrollTop : document.documentElement.scrollLeft; }
		else if (document.body) { return b_hight ? document.body.scrollTop : document.body.scrollLeft; }
	};
	if (window.opera) {
		this.getSize = function (id, b_hight) { 
			return this.divs[id].o_css[b_hight ? 'pixelHeight' : 'pixelWidth']
		};
		document.onmousemove = function () {
			for (var n_i in THintsS) {
				if ( THintsS[n_i].b_manpos ) continue;
				THintsS[n_i].x = event.clientX;
				THintsS[n_i].y = event.clientY;
				if (THintsS[n_i].b_follow && THintsS[n_i].visible!=null) 
					THintsS[n_i].move(THintsS[n_i].visible);
			}
			return true;
		};
	}
	else {
		this.getSize = function (id, b_hight) { 
			return this.divs[id].o_obj[b_hight ? 'offsetHeight' : 'offsetWidth'] 
		};
		document.onmousemove = b_IE
		? function () {
			var sl = 0, st = 0;
			if (document.documentElement && document.documentElement.scrollTop) {
				st = document.documentElement.scrollTop;
				sl = document.documentElement.scrollLeft;
			}
			else if (document.body) {
				st = document.body.scrollTop;
				sl = document.body.scrollLeft;
			}
			for (var n_i in THintsS) {
				if ( THintsS[n_i].b_manpos ) continue;
				THintsS[n_i].x = event.clientX + sl;
				THintsS[n_i].y = event.clientY + st;
				if (THintsS[n_i].b_follow && THintsS[n_i].visible!=null) 
					THintsS[n_i].move(THintsS[n_i].visible);
			}
			return true;
		} 
		: function (e) {
			for (var n_i in THintsS) {
				if ( THintsS[n_i].b_manpos ) continue;
				THintsS[n_i].x = e.pageX;
				THintsS[n_i].y = e.pageY;
				if (THintsS[n_i].b_follow && THintsS[n_i].visible!=null) 
					THintsS[n_i].move(THintsS[n_i].visible)
			}
			return true;
		};
	}
	for (i in items) {
//		s_tag = ['<div id="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, '" nowrap>%text%</td></tr></table></div>'].join('');
		st_tag = ['<table cellpadding="0" cellspacing="0" border="0"><tr><td class="', o_cfg.css, '" nowrap>%text%</td></tr></table>'].join('');
		var div = document.createElement('div');
		div.id = 'TTip' + i;
		div.style.visibility = "hidden";
		div.style.position = "absolute";
		div.style.top = "0px";
		div.style.left = "0px";
		if ( b_IE ) {
			div.style.width = div.style.height = "auto";
		}
		if ( o_cfg['z-index'] != null ) {
//			div.style.z-index = o_cfg['z-index'];
		}
		div.innerHTML = st_tag.replace(/%text%/g, items[i]).replace(/%name%/g, i);
		document.getElementsByTagName('body')[0].appendChild(div);

//		this.divs[i] = { 'o_obj' : div };
//		document.write (s_tag.replace(/%text%/g, items[i]).replace(/%name%/g, i));
		this.divs[i] = { 'o_obj' : this.getElem('TTip' + i) };
		this.divs[i].o_css = this.divs[i].o_obj.style;
//		this.iframes[i] = { 'o_obj' : this.getElem('TTifip' + i) };
//		this.iframes[i].o_css = this.iframes[i].o_obj.style;
		this.divs[i].o_css.visibility = 'hidden';
		this.divs[i].o_css.display = 'none';
//		this.iframes[i].o_css.visibility = 'hidden';
//		this.iframes[i].o_css.display = 'none';
		
	}
}
function TTipShow (id,nofade) {
	if (document.layers) return;
	this.hide();
	if (this.divs[id]) {
		if (this.divs[id].timer) clearTimeout(this.divs[id].timer);
		if (this.n_dl_show) this.divs[id].timer = setTimeout('THintsS[' + this.n_id + '].showD("' + id + '")', this.n_dl_show);
		else this.showD(id,nofade);
		this.visible = id;
	}
}

function TTipShowD (id,nofade) {
	this.divs[id].o_css.display = 'block';
	this.divs[id].o_css.height = '';
//	this.iframes[id].o_css.display = 'block'; 
	this.move(id);
	this.showElem(id);
	if (this.n_dl_hide) this.timer = setTimeout("THintsS[" + this.n_id + "].hide()", this.n_dl_hide);
	if (!nofade && this.n_dl_fade) this.showF(id);

}

function TTipMove (id) {
	var left = this.left, top = this.top;
	if ( this.centerx ) {
		var _w = this.getSize(id);
		left = _w/-2;
	}
		
	var n_x = this.x + left, n_y = this.y + 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';
//	this.iframes[id].o_css.left = n_x+'px';
//	this.iframes[id].o_css.top = n_y+'px';
//	this.iframes[id].o_css.height = n_h-this.top;
//	this.iframes[id].o_css.width = this.getSize(id, false)-this.left;
}

function TTipHide () {
	if (this.timer) clearTimeout(this.timer);
	if (this.visible != null) {
		if (this.divs[this.visible].timer) clearTimeout(this.divs[this.visible].timer);
		if (this.n_dl_fade) THintsS[this.n_id].hideF(this.visible);	//this.divs[this.visible].timer = setTimeout('THintsS[' + this.n_id + '].hideD("' + this.visible + '")', this.n_dl_fade);
		else {
			//setTimeout('THintsS[' + this.n_id + '].showElem("' + this.visible + '", true)', 10);
			THintsS[this.n_id].showElem(this.visible, true);
			this.visible = null;
		}
	}
}

function TTipHideFade (id, t, oh) {
	var d = new Date();
	var curTime = d.getTime();
	if ( !t ) {
		if ( !this.divs[id].o_css.overflowY ) this.divs[id].o_css.overflowY = 'hidden';
		t = curTime;
		oh = this.divs[id].o_css.height.replace(/px/i,"");
		if ( oh == "" ) {
			oh = this.divs[id].o_obj.clientHeight;
			this.divs[id].o_css.height = oh+'px';
		}
	}

	var scale = 1-((curTime - t)/this.n_dl_fade);
	h = Math.ceil(oh*scale);

	if ( h <= 0 ) {
		THintsS[this.n_id].hideD();
	}
	else {
		this.divs[id].timer = setTimeout('THintsS[' + this.n_id + '].hideF("' + id + '",' + t + ',' + oh + ')', 20);
		this.divs[id].o_css.height = h+'px';
	}
}

function TTipHideD () {
	if (this.divs[this.visible].timer) clearTimeout(this.divs[this.visible].timer);
	if (this.visible != null) {
		THintsS[this.n_id].showElem(this.visible, true);
		this.visible = null;
	}
}

function TTipShowFade (id, t, fh) {
	var d = new Date();
	var curTime = d.getTime();
	if ( !t ) {
		if ( !this.divs[id].o_css.overflowY ) this.divs[id].o_css.overflowY = 'hidden';
		t = curTime;
		fh = this.divs[id].o_obj.clientHeight;
		this.divs[id].o_css.height = '0px';
	}

	var scale = ((curTime - t)/this.n_dl_fade);
	h = Math.ceil(fh*scale);

	if ( h >= fh ) {
		this.divs[id].o_css.height = "";
	}
	else {
		this.divs[id].timer = setTimeout('THintsS[' + this.n_id + '].showF("' + id + '",' + t + ',' + fh + ')', 20);
		this.divs[id].o_css.height = h+'px';
	}
}

