/* //:::::::::::   POPUP TIP   :::::::::::\\
                 by Micah Goulart

	This script can be used as long as this
	disclaimer is left untouched.
	For bug reports or custom scripts, email me at:
	micahgoulart@mailbr.com.br
	
	IMPORTANT ::
		This script requires the dynlayer.js source file.
		Download it at members.xoom.com/micahgoulart/dhtml
		
	LAST UPDATE :: 26.11.1999
	
   //:::::::::::   copyright 1999   :::::::::::\\ */
	
function popUpTip()
{	var arg = arguments
	
	this.w = arg[0]
		
	this.ID = this.cssID = "popUpTip" + (popUpTip.count++)
	this.ref = this.ID + "Ref"
	eval(this.ref + " = this")
	
	this.borderWidth = 2
	this.borderColor = "Gray"
	this.captionBgColor = "Gray"
	this.textBgColor = "DodgerBlue"
	
	this.align = "right"
	this.checkAlignment = true
	
	this.isHidden = true
	this.isStick = false
	this.isLoaded = false
	
	this.offsetX = 15
	this.offsetY = 15	}

x = false
popUpTip.count = 0
popUpTip.current = null

popUpTip.prototype.build = popUpTipBuild
popUpTip.prototype.activate = popUpTipActivate
popUpTip.prototype.show = popUpTipShow
popUpTip.prototype.hide = popUpTipHide
popUpTip.prototype.check = popUpTipCheck
popUpTip.prototype.stick = popUpTipStick


function popUpTipBuild()
{	this.css = css(this.ID, 0, 0, this.w, null, this.borderColor, "hidden")

	this.div = "\n<DIV ID=" + this.ID + ">&nbsp;</DIV>\n"

	writeCSS(this.css)	}
	
function popUpTipActivate()
{	this.obj = new DynLayer(this.ID)

	popUpTip.current = this
	
	popUpTip.avWidth = (is.ns) ? self.innerWidth : document.body.clientWidth;
	
	this.isLoaded = true	}


function _startMouseTrack()
{	if (is.ns) document.captureEvents(Event.MOUSEMOVE)
	document.onmousemove = mouseMove;
	document.onclick = mouseClick;		}
	
function _stopMouseTrack()
{	if (is.ns) document.releaseEvents(Event.MOUSEMOVE);
	document.onmousemove = null	}
	


//::::::::::: hides the PopUp tip box after if stick is true :::::::::::\\
function mouseClick()
{	for (var i = 0; i < popUpTip.count; i++)
	{	var which = eval("popUpTip" + i + "Ref")
		if (which.isStick) which.hide(1) }
	document.onclick = null
			}

//::::::::::: tracks the mouseMove and positions the popUp Tip :::::::::::\\
function mouseMove(e)
{	x = (is.ns) ? e.layerX : event.clientX + document.body.scrollLeft
	y = (is.ns) ? e.layerY : event.clientY + document.body.scrollTop
	
	if (!popUpTip.current.isStick)
		popUpTip.current.check()

	if (popUpTip.current.align == "left") xPos = x - popUpTip.current.w
	if (popUpTip.current.align == "center")
		xPos = x - (popUpTip.current.w/2) + (popUpTip.current.offsetX/2)
	if (popUpTip.current.align == "right") xPos = x + popUpTip.current.offsetX
	
	if (!popUpTip.current.isStick)
		popUpTip.current.obj.moveTo(xPos, y + popUpTip.current.offsetY)	}


//::::::::::: builds the PopUp Tip then shows it :::::::::::\\
function popUpTipShow(caption, text)
{	if (!this.isLoaded) return

	popUpTip.current = this	

	_startMouseTrack()

	if (is.ie && this.isHidden) mouseMove()

	this.check()
	
	if (is.ns)
		this.obj.bgColor(this.borderColor)
	
	str = 
		"<TABLE BORDER=0 CELLSPACING="+this.borderWidth+" CELLPADDING=0 WIDTH="+this.w+ 
			" BGCOLOR='"+this.borderColor+"'>\n" +
		"<TR>\n" +
			"<TD BGCOLOR='"+this.captionBgColor+"'>\n" +
				"<DIV CLASS="+this.cssID+"Caption>"+caption+"</DIV></TD>\n" +
		"</TR>\n";

	if (text)
	str +=
		"<TR>\n" +
			"<TD BGCOLOR='"+this.textBgColor+"'>\n" +
			"<DIV CLASS="+this.cssID+"Text>"+text+"</DIV></TD>\n" +
		"</TR>\n"
		
	str += "</TABLE>\n"

	this.obj.write(str)

	this.obj.show()
	this.isHidden = this.isStick = false	 }
	

//::::::::::: hides PopUp Tip :::::::::::\\
function popUpTipHide(toggle)
{	if (!this.isStick || toggle) this.obj.hide()	
	_stopMouseTrack()
	this.isHidden = true
	if (toggle)
		this.isStick = false	}


//::::::::::: sticks the PopUp Tip :::::::::::\\
function popUpTipStick(caption, text)
{	if (caption) this.show(caption, text)
	this.isStick = true
	document.onclick = mouseClick }


//::::::::::: checks the PopUp's position :::::::::::\\
function popUpTipCheck()
{	if (!this.checkAlignment || !x) return;

	var total_width = popUpTip.avWidth - this.offsetX;
	
	var align = this.align
	
	if (align == "left" && x < this.w) align = "center"
	if (align == "center" && x < this.w/2) align = "right"
	if (align == "center" && x > (total_width-20) - (this.w/2)) align = "left"
	if (align == "right" && x > (total_width-20) - this.w) align = "center"
	this.align = align	}

