var maxX,maxY,userX,userY;
var maxBubbleWidth = 150;
var bubbleMargin = 5;
var nBubbleContainer = null;
var nBody = null;
var nCanvas = null;

function initBubble(mX,mY){
	if(typeof document.getElementById == "undefined")return false;

	nBody = document.getElementsByTagName("body")[0];
	nCanvas = document.getElementsByTagName("html")[0];

	userX=mX;
	userY=mY;

	maxBubbleWidth=(arguments[2])?arguments[2]:maxBubbleWidth;
	
	nBubbleContainer = document.createElement("div");
	
	nBubbleContainer.id = "bubble";
	nBubbleContainer.className = "bubble";

	with (nBubbleContainer.style){
		border = "1px solid #006C8C";
		width = maxBubbleWidth + "px";
		zIndex = "25";
	}
	
	nBody.appendChild(nBubbleContainer);
		
	return true;
}

function getBounds(){
	maxX = (userX>-1)?userX:(window.innerWidth!=null)?window.innerWidth+nCanvas.scrollLeft-bubbleMargin:nCanvas.offsetWidth+nCanvas.scrollLeft-bubbleMargin;
	maxY = (userY>-1)?userY:(window.innerHeight!=null)?window.innerHeight+nCanvas.scrollTop-bubbleMargin:nCanvas.offsetHeight+nCanvas.scrollTop-bubbleMargin;
}

function createBubble(content){
	if(nBody == null)return false;

	window.cLink = false;

	nBubbleContainer.appendChild(document.createTextNode(content));

	getBounds();
	
	if(window.captureEvents){
		window.captureEvents(Event.MOUSEMOVE)
	}
	document.onmousemove = moveBubble;

	return true;
}

function killBubble(){
	if(nBody == null)return false;

	document.onmousemove = null;
	
	nBubbleContainer.style.visibility="hidden";
	while(nBubbleContainer.hasChildNodes())nBubbleContainer.removeChild(nBubbleContainer.firstChild);

	window.cLink = true;
	
	return true;
}

function moveBubble(e){
	var eX,eY;

	eX=(window.event != null)?window.event.clientX+nCanvas.scrollLeft:e.pageX;
	eY=(window.event != null)?window.event.clientY+20+nCanvas.scrollTop:e.pageY+20;

	eX=(eX+nBubbleContainer.offsetWidth<maxX)?eX:maxX-nBubbleContainer.offsetWidth;
	eY=(eY+nBubbleContainer.offsetHeight<maxY-20)?eY:eY-nBubbleContainer.offsetHeight-40;

	with (nBubbleContainer.style){
		//left = eX+"px";
		left = "20px";
		top= eY+"px";
		visibility="visible";
	}
}

function onloadBubble(){
	window.oOnload = window.onload;
	if(window.captureEvents)window.captureEvents(Event.LOAD);
	window.onload = function nOnload(){
		initBubble(360,-1,180,'#006699');
		if(window.oOnload!=null)window.oOnload();
	}
}
onloadBubble();

