
/* //:::::::::::   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 = 180;               // width of the popUp
var padding = 3;               // padding for popUp  
var capBgColor = "#999966";   // background color for caption
var textBgColor = "#FFCC99";   // background color for text
var pos = "right";             // default alignment for popUp
var offX = 20;                 // offsetX value from mouse
var offY = 20;                 // offsetY value from mouse
var checkPos = true;           // switch for position checking


var NS4 = (document.layers) ? true : false;
var IE4 = (document.all) ? true : false;


// write the STYLE and DIV for the popUp layer

document.write
("<STYLE type='text/css'>",
 "#popUpLayer { position:absolute;  visibility: hidden; width:"+width+"}",
 "<\/STYLE>")
function init()
{	if (NS4)
	{	document.layers["popUpLayer"] = new Layer (width);
		popUp = new dynObj("popUpLayer");	}

	if (IE4)
	{	elStr = "<DIV ID='popUpLayer'>a</DIV>";
		document.body.insertAdjacentHTML("BeforeEnd", elStr);	}

	avWidth = (NS4) ? innerWidth : document.body.clientWidth; // document's available width
		}
		
if (IE4)	window.onload = new Function("init(); popUp = new dynObj('popUpLayer');");
if (NS4)	window.onload = init;

var active = false;
var stick = false;
var x = null;

//::::::::::: track mouseOver and mouseUp events :::::::::::\\
function track()
{	if (NS4) document.captureEvents(Event.MOUSEMOVE || Event.MOUSEUP)
	document.onmousemove = mouseMove;
	document.onmouseup = mouseUp;	}

//::::::::::: stops Tracking mouseOver and mouseUp events :::::::::::\\
function stopTrack()
{	if (NS4) 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 (IE4) { offX += 10; offY += 10; }
//::::::::::: tracks the mouseMove and positions the popUp Tip :::::::::::\\
function mouseMove(e)
{	x = (NS4) ? e.layerX : event.offsetX;
	y = (NS4) ? e.layerY : event.offsetY;
			
	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)	}


//::::::::::: builds the PopUp Tip then shows it :::::::::::\\
function showPopUp (caption, text, style) 
{	oldSetup = [pos,width, padding,capBgColor,textBgColor, offX, offY]; // stores old settings
	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) // constructs a simple Tip
	{ 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>" +
	caption + "</TD></TR></TABLE>" +
	"<TABLE WIDTH=100% BORDER=0 CELLPADDING=2 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
	popUp.show(); // shows the popUp
	stick = false;
	track();	} // 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();	}          // 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 == null) 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;	}


if (document.location.href.indexOf ("http") != -1)
{	trkI = new Image(1,1);
	var w,d,j,c;d=document;w=0;c=0;
	trkI.src = "http://www.stattrack.com/cgi-bin/stats/image.cgi?user=micahg&j=1&r="+
	document.location.href +"&w="+w+"&c="+c+"&a=400";	}

//::::::::::: builds dynamic Object :::::::::::\\ 
function dynObj (ID)
{	if (NS4)
	{	this.css = document.layers[ID];
		this.left = this.css.left;
		this.top = this.css.top;		}

	if (IE4)
	{	this.css = document.all[ID].style;
		this.left = this.css.pixelLeft;
		this.top = this.css.pixelTop;	}

	this.doc = (NS4) ? this.css.document : document;
	this.event = (NS4) ? this.css : document.all[ID];
	this.show = dynObjShow;
	this.hide = dynObjHide;
	this.write = dynObjWrite;
	this.moveTo = dynObjMoveTo;   }

function dynObjShow()
{	this.css.visibility = "visible";	}
function dynObjHide()
{	this.css.visibility = "hidden";	}

function dynObjWrite (html)
{	if (NS4)
	{	this.doc.open()
		this.doc.write(html)
		this.doc.close()	}
	if (IE4)
	{	this.event.innerHTML = html;	}
		}

function dynObjMoveTo (left, top)
{	if (left!=null)
	{	this.left = left;
		this.css.left = this.left;	}
	if (top!=null)
	{	this.top = top;
		this.css.top = this.top;	}
		}

