
//	You need to create a blank div
//	before this will work

function CPopBox(oName,globalsName,divID)
{
	//	Object ID's
	this.oName=oName;
	this.oGlobal=globalsName;
	this.divID=divID;
	this.oDiv=null;
	
	//	Vars
	this.lastCaller=null;
	this.popText="";
	this.mouseX=0;
	this.mouseY=0;
	this.stickyMouseX=0;
	this.stickyMouseY=0;

	//	Functions
	this.Show=CPopBox_Show;
	this.Hide=CPopBox_Hide;
	this.UpdateState=CPopBox_UpdateState;
	this.GetMousePosition=CPopBox_GetMousePosition;
}

//	Sets the text to the div and shows it
function CPopBox_Show(caller,text)
{
	//	Assign data
	this.popText=text;
	this.lastCaller=caller;
	
	//	Update cursor pos
	this.GetMousePosition();
	this.stickyMouseX=this.mouseX;
	this.stickyMouseY=this.mouseY;	
	
	setTimeout(this.oName+".UpdateState();",100);
}

//	Hides this pop box
function CPopBox_Hide()
{
	//	Only hide if the cursor has moved enough
	this.GetMousePosition();
	if(
		Math.abs(this.mouseX-this.stickyMouseX)<20
		&&
		Math.abs(this.mouseY-this.stickyMouseY)<20
		)
	{
		setTimeout(this.oName+".Hide();",100);
		return;
	}

	////////////////////////////////////
	//	If we make it here, kill the box	
	this.popText='';
	this.lastCaller=null;
	
	setTimeout(this.oName+".UpdateState();",100);
}

///////////////////////////////////////////////
//	Shows or Hides the div and sets its new pos
function CPopBox_UpdateState()
{
	this.oDiv=document.getElementById(this.divID);
	if(!this.oDiv){
		return false;
	}
	
	if(this.popText==""){
		this.oDiv.style.display='none';
		return true;
	}
	
	//	Update cursor pos
	this.GetMousePosition();

	//	Set the text and display style
	this.oDiv.innerHTML=this.popText;
	this.oDiv.style.display='inline';
	
	//	Get screen halfs
	var middleX=document.body.offsetWidth/2;
	var middleY=(document.body.clientHeight/2);
	
	//////////////////
	//	Set the coords
	if(this.mouseX>middleX){
		this.oDiv.style.left=this.mouseX-this.oDiv.offsetWidth;
	}
	else{
		//	Need the padding so it doesn't de-handify the mouse
		this.oDiv.style.left=this.mouseX+10;
	}
	if(this.mouseY-document.body.scrollTop>middleY){
		this.oDiv.style.top=this.mouseY-this.oDiv.offsetHeight;
	}
	else{
		this.oDiv.style.top=this.mouseY+10;
	}
	
	return true;
}

//	Grabs the mouse coords from global
function CPopBox_GetMousePosition()
{
	var toEval=
		'this.mouseX='+this.oGlobal+'.mouseX;'
		+'this.mouseY='+this.oGlobal+'.mouseY;';
	eval(toEval);
	
	return true;
}

