﻿//
// FollowMouse.js
//

// Author: Colin Jaggs
// Date: 24th May 2007
// Description: functions to follow the mouse around for floating layers

// requires:
//		var floatingInfoMaxX = 460;		maximum x position for floating layer - should be automatic based on layer width but few problems in doing it that way
//		var floatingLayers = new Array("layer1id", "layer2id");		ids of floating layers available on the website that we want to move with the mouse
var floatX = 0, floatY = 0;

function followMouse(e)
{
	// determine correct body element
	if (document.documentElement) body = document.documentElement;
	else if (document.body) body = document.body;

	for (var i = 0; i < floatingLayers.length; i++)
	{
		if (objectById(floatingLayers[i]))
		{
			// determine new x and y co-ordinates for the floating layer
			var tempX = 0, tempY = 0;
			if (typeof (e) != "undefined")
			{
				tempX = e.pageX;
				tempY = e.pageY;
			}
			else if (typeof (window.event) != "undefined")
			{
				tempX = body.scrollLeft + event.clientX;
				tempY = body.scrollTop + event.clientY;

				// check boundaries to make sure we're not going off screen
				var maxX = body.clientWidth - objectById(floatingLayers[i]).offsetWidth - xOffset;
				var maxY = body.clientHeight - objectById(floatingLayers[i]).offsetHeight - yOffset;
				if (tempX > maxX) tempX = maxX;
				if (tempY - body.scrollTop > maxY) tempY = maxY + body.scrollTop;
			}

			//if ((tempX != floatX) || (tempY != floatY))
			//{
				//floatX = tempX;
				//floatY = tempY;
				objectById(floatingLayers[i]).style.left = tempX + xOffset + "px";
				objectById(floatingLayers[i]).style.top = tempY + yOffset + "px";
			//}
		}
	}
	
	return true;
}

var IE = document.all ? true : false;
if (!IE) document.captureEvents(Event.MOUSEMOVE);
document.onmousemove = followMouse;
