
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~/
 * Gallery Mouse Tracking Scripts, v1.0
 * (c) 2004 timallen.com
 * created by bivia of bivia.com, August 20 2004
 * $Id: galleryMouseTracker.js,v 1.2 2004/09/24 10:25:00 bcurtis Exp $
 *
 *----*/

var Mouse = { "x":0, "y":0 };
var Page  = { "x":0, "y":0, "r":350 };


// this should be called to set the default relative zero and radius for this page
	var bv_setMouseTrackAxisPosition_defer = false;
	function bv_setMouseTrackAxisPosition(x,y,r) {
		if ((x < 0 || y < 0) && !window.innerWidth && !(document.body && document.body.offsetWidth)) {
			bv_setMouseTrackAxisPosition_defer = setTimeout("bv_setMouseTrackAxisPosition("+x+","+y+","+r+")", 1000);
		} else {
			if (x < 0) {
				if (window.innerWidth) x += window.innerWidth;
				else if (document.body.offsetWidth) x += document.body.offsetWidth;
				else if (document.body.parentNode) x += document.body.parentNode.clientWidth;
			}
			if (y < 0) {
				if (window.innerHeight) y += window.innerHeight;
				else if (document.body.offsetHeight) y += document.body.offsetHeight;
				else if (document.body.parentNode) y += document.body.parentNode.clientHeight;
			}
			Page  = { "x":x, "y":y, "r":Math.abs(r) };
		}
		return Page;
	}

// this should be overridden if you want to do things
	function bv_mouseTrackListener(x,y) {}

// this may be overridden if you want to have values other than % off center
	function bv_mouseTrackHandler() {
		var Xat  = Mouse.x - Page.x;
		var Xpct = (Xat) ? Math.min(parseInt(Math.abs(Xat * 100) / Page.r), 100) * (Xat / Math.abs(Xat)) : 0;
		var Yat  = Mouse.y - Page.y;
		var Ypct = (Yat) ? Math.min(parseInt(Math.abs(Yat * 100) / Page.r), 100) * (Yat / Math.abs(Yat)) : 0;
		bv_mouseTrackListener(Xpct,Ypct);
	}

// leave this baby be
	function bv_trackMouse(e) {
		if (!e) var e = window.event;
		if (e.pageX || e.pageY) {
			if (e.pageX >= 0) { // Safari reports x == -1 and y == {max win height} when mouse is off page; skip update, then
				Mouse.x = e.pageX;
				Mouse.y = e.pageY;
			}
		} else if (e.clientX || e.clientY) {
			Mouse.x = e.clientX + document.body.scrollLeft;
			Mouse.y = e.clientY + document.body.scrollTop;
		}
		bv_mouseTrackHandler();
	}
document.onmousemove = bv_trackMouse;

