/* //:::::::::::   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
	
	the dynObj builder cannot be used unless I am
	first contacted and permission is given.
	
   //:::::::::::   copyright 1999   :::::::::::\\ */


var width = 375               // width of the popUp
var padding = 2               // padding for popUp  
var capBgColor = "#E00000"       // background color for caption
var textBgColor = "#FFFAFA"     // background color for text
var pos = "right"             // default alignment for popUp
var offX = -40                 // offsetX value from mouse
var offY = -200                 // offsetY value from mouse
var checkPos = true           // switch for position checking

var left = "left"
var center = "center"
var right = "right"

// write the STYLE for the popUp layer
writeCSS(css("popUpLayer",0,0,width,null,null,"hidden"))

function initPopUp()
{	if (NS) document.layers["popUpLayer"] = new Layer(width)
	if (IE)
	{	document.body.insertAdjacentHTML("BeforeEnd", 
			"<DIV ID='popUpLayer' STYLE='position:absolute;'></DIV>")	}
	popUp = new dynObj("popUpLayer")
	avWidth = (NS) ? innerWidth : document.body.clientWidth; // document's available width
	popUp.isHidden = true
		}
		
window.onload = initPopUp

var stick = x = yz = false

//::::::::::: track mouseOver and mouseUp events :::::::::::\\
function track()
{	if (NS) document.captureEvents(Event.MOUSEMOVE || Event.MOUSEUP)
	document.onmousemove = mouseMove;
	document.onmouseup = mouseUp;		}

//::::::::::: stops Tracking mouseOver and mouseUp events :::::::::::\\
function stopTrack()
{	if (NS) document.releaseEvents(Event.MOUSEMOVE || Event.MOUSEUP);
		document.onmousemove = new Function ("return true");	}

//::::::::::: hides the PopUp tip box after if stick is true :::::::::::\\
function mouseUp()
{	if (stick) popUp.hide() }


if (IE) { offX += 10; offY += 10; }
//::::::::::: tracks the mouseMove and positions the popUp Tip :::::::::::\\
function mouseMove(e)
{	x = (NS) ? e.layerX : event.x + document.body.scrollLeft
	y = (NS) ? e.layerY : event.y + document.body.scrollTop

	if (pos == "left") xPos = x - width
	if (pos == "center") xPos = x - (width/2) + (offX/2)
	if (pos == "right") xPos = x + offX
	
	checkPopUpPos(pos)

	if (!stick) popUp.moveTo(xPos, y + offY)
	if (popUp.isHidden)
	{	popUp.show()
		popUp.isHidden = false	}	}


//::::::::::: builds the PopUp Tip then shows it :::::::::::\\
function showPopUp(caption, text, style) 
{	track() // enables mouse tracking
	if (IE && popUp.isHidden) mouseMove()
	oldSetup = [pos,width, padding,capBgColor,textBgColor, offX, offY]; // stores old settings
	if (style) eval(style)        // used for changing popUp Tip settings
	checkPopUpPos(pos) // checks the popUp's position	

	str = "<TABLE BORDER=0 CELLPADDING=" + padding + " CELLSPACING=0 WIDTH=" + width +
	" BGCOLOR=" + capBgColor + "><TR><TD>";

	if (caption == null || caption == "null") // constructs a simple popUp
		str+="<CENTER><A CLASS=simpleText>" + text + "</A></CENTER></TD></TR></TABLE>"

	else
	str += "<TABLE WIDTH=100% BORDER=0 CELLPADDING=0 CELLSPACING=0><TR><TD CLASS=caption>" +
	"&nbsp;" + caption + "</TD></TR></TABLE>" + "<TABLE WIDTH=100% BORDER=0 CELLPADDING=3" +
	" CELLSPACING=0 BGCOLOR=" + textBgColor + "><TR><TD CLASS=text>" + text + "</TD></TR>" +
	"</TABLE></TD></TR></TABLE>"

	popUp.write(str)  // writes out the table to the popUp layer
	stick = false	 }   // ensures that the popUp isn't sticky
	

//::::::::::: hides PopUp Tip :::::::::::\\
function hidePopUp()
{	if (!stick) popUp.hide()
	pos = oldSetup[0]
	width = oldSetup[1]       // resets the old setting for width
	padding = oldSetup[2]     // resets the old setting for padding   
	capBgColor = oldSetup[3]  // resets the old setting for capBgColor
	textBgColor = oldSetup[4] // resets the old setting for textBgColor
	offX = oldSetup[5]        // resets the old setting for offX
	offY = oldSetup[6]        // resets the old setting for offY
	
	stopTrack()
	popUp.isHidden = true	}         // stops tracking mouse


//::::::::::: sticks the PopUp Tip :::::::::::\\
function stickPopUp (caption, text, style)
{	if (caption) showPopUp(caption, text, style)
	stick = true; }


//::::::::::: checks the PopUp's position :::::::::::\\
function checkPopUpPos (currPos)
{	if (!checkPos || !x) return; // returns if checkPos is off
	totalWidth = width + offX;
	if (currPos == "left" && x < totalWidth-20) currPos = "center"
	if (currPos == "center" && x < (totalWidth/2 - offX)) currPos = "right"
	if (currPos == "center" && x > (avWidth-20) - (totalWidth/2)) currPos = "left"
	if (currPos == "right" && x > (avWidth-20) - totalWidth) currPos = "center"
	pos = currPos;				}
