var IE = document.all ? true : false;

if(!IE)
	document.captureEvents(Event.MOUSEMOVE);

var follow_cursor = null;

function update_cursor(e)
{
	var x, y;
	if(!follow_cursor)
		return true;
	if(IE)
	{
		x = event.clientX + document.body.scrollLeft;
		y = event.clientY + document.body.scrollTop;
	}
	else
	{
		x = e.pageX;
		y = e.pageY;
	}
	if(x < 0)
		x = 0;
	if(y < 0)
		y = 0;
	/* start it a little offset from the cursor */
	x += 5;
	y += 5;
	/* but don't go off the screen */
	/* 4 = width of left/right borders */
	if(x + follow_cursor.clientWidth >= document.body.clientWidth - 4)
		x = document.body.clientWidth - 4 - follow_cursor.clientWidth;
	/* 9 = width of top/bottom borders */
	if(y + follow_cursor.clientHeight >= document.body.clientHeight - 9)
		y = document.body.clientHeight - 9 - follow_cursor.clientHeight;
	follow_cursor.style.top = y;
	follow_cursor.style.left = x;
	return true;
}

document.onmousemove = update_cursor;

/* user code should call these */

function mouse_float(id)
{
	var element = document.getElementById(id);
	if(follow_cursor)
		mouse_unfloat();
	if(IE)
		element.setAttribute("className", "visible_popup");
	else
		element.setAttribute("CLASS", "visible_popup");
	follow_cursor = element;
}

function mouse_unfloat()
{
	if(follow_cursor)
	{
		if(IE)
			follow_cursor.setAttribute("className", "popup");
		else
			follow_cursor.setAttribute("CLASS", "popup");
		follow_cursor = null;
	}
}
