var XX_MyTooltipArray = new Array();
var XX_MyTooltip=null;

function tooltip(doc,i_padding,i_bgcolor,i_borWid,i_borCol,transparent,auto_width)
{
	//if (XX_MyTooltip!=null)
	//	alert("Warning!!\nYou can create only one instance of tooltip class.");
	this.def_layer=null;
	this.doc = doc;
	this.NS4 = (doc.layers) ? 1 : 0;
	this.IE4 = (doc.all) ? 1 : 0;
	this.UP5 =  doc.getElementById?1:0;
	this.NS6 =  this.UP5&&!this.IE4;
	this.style = (this.NS4 || this.IE4 || this.NS6) ? 1 : 0;
	this.timerID = null;
	this.num = 1;
	this.link_offset = 0;	
	this.ones = 0;
	this.allLinks = new Array;
	this.subelems = new Array; 
	this.subelems[0] = new Object;
	{
	var l = this.subelems[0];
	    l.idx=0;
		l.width = auto_width?auto_width:50;
		l.code = "";
		l.type = -1;
		l.links = new Array();
	}	
  	for (var i = 2; i < arguments.length; i++) 
		l.links[l.links.length] = arguments[i];
	this.padding = 3;
	this.bgcolor = "#FFFFFF"; 
    this.borderWidth = 1; 
	this.borderColor = "#000000";

	this.padding = i_padding;
	this.bgcolor = i_bgcolor; 
	this.borderWidth = i_borWid
	this.borderColor = i_borCol;
	if (!transparent)
		this.transparent = "site_icons/tr.gif";
	else 
		this.transparent = transparent;
		
	if (document.layers)
	{
		if (this.borderWidth>0 && this.padding>0)	 
        {
			this.ns4def = "<table bgcolor='"+  this.bgcolor+"' border=0 cellspacing=0 cellpadding=0>"
				    +"<tr><td bgcolor='" + this.borderColor +"' colspan=5 height='" + this.borderWidth + "' ><img src='"+this.transparent+"'></td></tr>" 
				     
					+"<tr><td width='" + this.borderWidth + "' bgcolor='" + this.borderColor +"' height='" + this.padding + "' ><img src='"+this.transparent+"'></td>" 
						+"<td colspan=3 ><img src='"+this.transparent+"'></td>"
					    +"<td width='" + this.borderWidth + "' bgcolor='" + this.borderColor +"' ><img src='"+this.transparent+"'></td></tr>"

					+"<tr><td bgcolor='" + this.borderColor +"' "+/*height='##height##'*/" width='" + this.borderWidth + "'><img src='"+this.transparent+"'></td>" 
						+"<td width='" + this.padding + "'><img src='"+this.transparent+"'></td>"
						+"<td width='##width##'>##content##</td>"
						+"<td width='" + this.padding + "'><img src='"+this.transparent+"'></td>"
						+"<td bgcolor='" + this.borderColor +"' width='" + this.borderWidth + "'><img src='"+this.transparent+"'></td></tr>"
					
					+"<tr><td bgcolor='" + this.borderColor +"' height='" + this.padding + "' ><img src='"+this.transparent+"'></td>" 
						+"<td colspan=3 ><img src='"+this.transparent+"'></td>"
					    +"<td bgcolor='" + this.borderColor +"' ><img src='"+this.transparent+"'></td></tr>"
					+"<tr><td bgcolor='" + this.borderColor +"' colspan=5 height='" + this.borderWidth + "'><img src='"+this.transparent+"'></td></tr>" 
					+"</table>";
	
		}
        else if (this.borderWidth>0 || this.padding>0)
		{
			var c1=this.borderWidth>0?this.borderColor:this.bgcolor; 
			var s1=this.borderWidth>0?this.borderWidth:this.padding; 
			//c1="#0000FF";
			this.ns4def = "<table bgcolor='"+  this.bgcolor+"' border=0 cellspacing=0 cellpadding=0>"
						+"<tr><td colspan=3 bgcolor='" + c1 +"' height='" + s1 + "'><img src='"+this.transparent+"'></td></tr>"
					+"<tr><td bgcolor='"+c1+"' "+/*height='##height##'*/" width='" + s1 + "'><img src='"+this.transparent+"'></td>"
						+"<td width='##width##'>##content##</td>"
						+"<td bgcolor='"+c1+"' width='" + s1 + "'><img src='"+this.transparent+"'></td></tr>"
						+"<tr><td colspan=3 bgcolor='" + c1 +"' height='" + s1 + "'><img src='"+this.transparent+"'></td>"
					    +"</tr></table>";
		}
		else
		{
			this.ns4def = "<table bgcolor='"+  this.bgcolor+"' border=0 cellspacing=0 cellpadding=0>"
						+"<tr><td "+/*height='##height##'*/" width='##width##'>##content##</td>"
					    +"</tr></table>";
		}
	}
    
	XX_MyTooltip = this;
	this.idx = XX_MyTooltipArray.length;
	XX_MyTooltipArray[XX_MyTooltipArray.length]=this;
}


function getLayXSize(lay)
{
	if (document.layers)
		w= lay.clip.width;
	else if (document.all)
		w = lay.clientWidth;
	else if (document.getElementById)
		w = lay.offsetWidth;
	return w;
}
function getLayYSize(lay)
{
	if (document.layers)
		h= lay.clip.height;
	else if (document.all)
		h = lay.clientHeight;//pixelHeight;
	else if (document.getElementById)
		h = lay.offsetHeight;
	return h;
}
function getWindowYSize(wnd)
{
	if (document.all)
	   return wnd.document.body.clientHeight;	
	else 
	   return wnd.innerHeight;
}

function getWindowXSize(wnd)
{
	if (document.all)
	   return wnd.document.body.clientWidth;	
	else 
	   return wnd.innerWidth;
}

function FillTooltipContent(idx)
{		
	var se = this.subelems[idx];
	if (this.NS4)
	{
			var cont = this.ns4def.replace(/##width##/,se.width);
			cont = cont.replace(/##content##/,se.code);
			se.lay.document.open();
			se.lay.document.write(cont);
			se.lay.document.close();
	}
	else
	{
			se.lay.innerHTML=se.code;
	}
}

function displayEl(left, top) 
{
	with(this)
	{
		if (NS4) doc.releaseEvents(Event.MOUSEMOVE);
			doc.onmousemove = null;
		if (doc.active)
		{
			var whichEl = (NS4)?doc.active.tooltip:doc.active.tooltip.style;
			var lay = doc.active.tooltip;
            if ( doc.active.def.type == 0)
			{
				whichEl.left = left+20;
				whichEl.top = top;
				if (getWindowXSize(window) < parseInt(whichEl.left) + getLayXSize(lay))
					whichEl.left = parseInt(whichEl.left) - getLayXSize(lay)-20;
				if (getWindowYSize(window) < parseInt(whichEl.top) + getLayYSize(lay))
					whichEl.top = parseInt(whichEl.top) - getLayYSize(lay);
				if (parseInt(whichEl.top)<0) whichEl.top=0;
				if (parseInt(whichEl.left)<0) whichEl.left=0;
			}	
			else if (doc.active.def.type == 2)
			{
				doc.active.def.code = doc.active.def.fun(doc.active.def.par);
				FillTooltipContent(doc.active.def.idx);
				whichEl.left = left+20;
				whichEl.top = top;
				if (!document.layers) 
					doc.active.def.lay.style.width= doc.active.def.width;
				if (getWindowXSize(window) < parseInt(whichEl.left) + getLayXSize(lay))
					whichEl.left = parseInt(whichEl.left) - getLayXSize(lay)-20;
				if (getWindowYSize(window) < parseInt(whichEl.top) + getLayYSize(lay))
					whichEl.top = parseInt(whichEl.top) - getLayYSize(lay);
				if (parseInt(whichEl.top)<0) whichEl.top=0;
				if (parseInt(whichEl.left)<0) whichEl.left=0;
			}
			else //type 1
			{
				whichEl.left = doc.active.def.x;
				whichEl.top = doc.active.def.y;
			}

			whichEl.visibility = (NS4) ? "show" : "visible";
		}
	}
}
function clearEl(e,link) 
{
	with(this)
	{
    	if (link.onmouseout_tlp)
			link.onmouseout_tlp(e);
		
	if (doc.active)
	{
		var whichEl = (NS4)?doc.active.tooltip:doc.active.tooltip.style;
		whichEl.visibility = (NS4) ? "hide" : "hidden";
		whichEl.top=0;
		whichEl.left=-doc.active.def.width;
	}

	doc.active = null;
	if (timerID) clearTimeout(timerID);
	if (NS4) doc.releaseEvents(Event.MOUSEMOVE);
		doc.onmousemove = null;
	}
}

function activateEl(e,link) 
{
	with(this)
	{
		
		if (link.onmouseover_tlp)
			link.onmouseover_tlp(e);
		doc.active = link;//.tooltip;
        if (NS4) doc.captureEvents(Event.MOUSEMOVE);
		doc.onmousemove = new Function("e","XX_MyTooltipArray["+this.idx+"].checkEl(e)");
		this.checkEl(e);
	}
}

function checkEl(e) 
{
	with(this)
	{
	if (timerID) clearTimeout(timerID);
	var left = (NS4||NS6) ? e.pageX : event.clientX + doc.body.scrollLeft;
	var top =  (NS4||NS6) ? e.pageY : event.clientY + doc.body.scrollTop; 
	timerID = setTimeout("XX_MyTooltipArray["+this.idx+"].displayEl(" + left + ", " + top + ")", 300);
	
	}
}


function GetAllLinks(arr,doc)
{
	if (!doc) doc=window.document;
	var j;
	for (j = 0; j < doc.links.length; j++) 
	{
		doc.links[j].uesc= unescape(doc.links[j].href);
		arr[arr.length]=doc.links[j];
	}
	if (document.layers)
		{
			for (j = 0; j < doc.layers.length; j++) 
				GetAllLinks(arr,doc.layers[j].document);
		}
}


function TooltipMakeLayers(nn)
{
	
	var se = this.subelems[nn];
	var width= se.width;
//	var code = se.code;
	if (se.type==3) 
	{
		se.lay = this.subelems[0].lay;
		return;
	}
	with(this)
	{
		if (document.all) width += 2*this.padding+2*this.borderWidth//IE
		var id = "tip" + (num++);
		if (document.layers)
		{
			se.lay = new Layer(width+2*this.padding+2*this.borderWidth);
			se.lay.left=0;
			se.lay.top=0;
			se.lay.zIndex=20;
			se.lay.visibility  = "hide";
			FillTooltipContent(nn);
			if (bgcolor!="") se.lay.bgColor = this.bgcolor;
		}
		else
		{      
			if (document.getElementById)
			{
				se.lay = document.createElement("DIV");
				document.body.appendChild(se.lay);
				se.lay.style.position ="absolute";
			}
			else if (document.all)
			{
				document.body.insertAdjacentHTML("beforeEnd","<DIV  style='position:absolute'  id='"+idx+"'>&nbsp;</div>");
				se.lay = document.all[id];
			}
			else return null;
			
			se.lay.style.visibility = "hidden";
			se.lay.style.display="block";
			se.lay.style.padding = ""+ this.padding + "px";
			if (this.bgcolor!="") se.lay.style.backgroundColor = this.bgcolor ;
			if (this.borderWidth>0)
			{
				se.lay.style.borderWidth = ""+this.borderWidth +"px";
				se.lay.style.borderColor = ""+this.borderColor ;
				se.lay.style.borderStyle = "solid";
			}
			se.lay.style.zIndex=20;
			se.lay.style.left="0px";
			se.lay.style.top="0px";
			//lay.style.height="100px";
			se.lay.style.width=""+se.width+"px";
			FillTooltipContent(nn);	
		}
    
	}
}

function AttacheLinks(nn)
{	
	var se = this.subelems[nn];

	with (this)
	{	
		for (var i = 0; i < this.subelems[nn].links.length; i++) 
		{
			
			var par = se.links[i];
			
			if (par.substr(0,1)=="/")
			{
				var loc =  this.doc.location.href;
				loc = loc.match(/(^[^\/]+\/\/[^\/]+)/,"");
				par = RegExp.$1 + par;
			}
			if (!par.match(/^[a-z0-9]+:/i))
			{
				var loc =  this.doc.location.href;
				loc = loc.replace(/[^\/]+$/,"");
				par = loc + par;
			}
			
			par = par.replace(/\/[^\/]+\/\.\.\//,"/");
			if (this.allLinks.length==0)
			{
				GetAllLinks(this.allLinks,window.document);
			}
			
			for (var j = 0; j < this.allLinks.length; j++) 
			{  
				var k= (j+this.link_offset) % this.allLinks.length; 
				var lnk = this.allLinks[k];
                if (lnk.uesc == par) 
				{			 
					this.link_offset = k;
					lnk.tooltip = se.lay;
					lnk.def = se;
					lnk.onmouseover_tlp = lnk.onmouseover;
					lnk.onmouseover = new Function("e","XX_MyTooltipArray["+this.idx+"].activateEl(e,this)");
					lnk.onmouseout_tlp = lnk.onmouseout;
					lnk.onmouseout = new Function("e","XX_MyTooltipArray["+this.idx+"].clearEl(e,this)");
					if (se.ones)
						break;
				}
			}
		}
	}
}

function AddTooltip(width, code) 
{
	var idx = this.subelems.length;
	this.subelems[idx] = new Object;
	var l = this.subelems[idx];
    	l.idx=idx;
	l.width =width;
	l.code = code;
	l.type = 0;
	l.links = new Array();
  	for (var i = 2; i < arguments.length; i++) 
		l.links[l.links.length] = arguments[i];
	l.ones = this.ones;
	return l;	
	
}

function AddAtPosTooltip(width,x,y,code) 
{
	var idx = this.subelems.length;
	this.subelems[idx] = new Object;
	var l = this.subelems[idx];
    l.type = 1;
    l.x = x;
	l.y = y;
	l.idx=idx;
	l.width =width;
	l.code = code;
	l.links = new Array();
  	for (var i = 4; i < arguments.length; i++) 
		l.links[l.links.length] = arguments[i];
	l.ones = this.ones;
	return l;
}

function AddFunTooltip(width,fun,param) 
{
	var idx = this.subelems.length;
	this.subelems[idx] = new Object;
	var l = this.subelems[idx];
	l.fun=fun;
	l.par = param;
    l.type = 2;
	l.idx=idx;
	l.width =width;
	l.code = "empty";
	l.links = new Array();
	l.ones = this.ones;
  	for (var i = 3; i < arguments.length; i++) 
		l.links[l.links.length] = arguments[i];
	return l;
}


function InitTooltips()
{
	
	var i,j;
	for (j=0;j<XX_MyTooltipArray.length;j++)
	{
		for(i=0;i<XX_MyTooltipArray[j].subelems.length;i++)
			XX_MyTooltipArray[j].MakeLayers(i) ;
		for(i=1;i<XX_MyTooltipArray[j].subelems.length;i++)
			XX_MyTooltipArray[j].AttacheLinks(i) ;
	}
}

tooltip.prototype.Add = AddTooltip;
tooltip.prototype.AddAtPos = AddAtPosTooltip;
tooltip.prototype.AddFun = AddFunTooltip;
tooltip.prototype.MakeLayers = TooltipMakeLayers;
tooltip.prototype.displayEl = displayEl;
tooltip.prototype.clearEl = clearEl;
tooltip.prototype.activateEl = activateEl;
tooltip.prototype.checkEl = checkEl;
tooltip.prototype.AttacheLinks = AttacheLinks;
tooltip.prototype.FillTooltipContent  = FillTooltipContent;
/*
//Add tooltips declaration like bellow in header and in onload handler run "InitTooltips" function. 

{
	new tooltip(document,i_padding,i_bgcolor,i_borWid,i_borCol);
	tlp.Add(300, "A web site about creating web sites.<br><b> With thousands of select, annotated links, hourly web news, noted columnists, and free services this is webmaster <I>nirvana</I>.</b>", "http://www.webreference.com/", "http://ars.neurosoft.net/fnac/tests/a.html");
	tlp.Add(300, "Let our leading experts keep you up to date with the latest developments, featuring the columns you need. Each is a respected author in their chosen field.", "http://www.webreference.com/experts/","b.html");
	tlp.AddAtPos(300,x,y,"A JavaScript how-to column with biweekly prescriptions, that are sure to improve your JavaScript health. Shows readers how to utilize the latest JavaScript features.", "http://www.webreference.com/js/","http://ars.neurosoft.net/fnac/tests/c.html");
}

*/


