/* Track Mouse Movement
 * Copyright MILLIONDOLLARPIXELSCRIPTPHP.COM 2006. All rights reserved
 * One license is only valid for one domain and server. Read the accompanying EULA.

Initialisation: add this where it is used:
	<script src="lib/gridcoord.js"></script>
	<script>
	var oGridCoord = new GridCoord();
	
	window.onload = function () {
		var old = document.onmousemove;	
		document.onmousemove= old ? function(e) { old(e); oGridCoord.OnMouseMove(e); } : oGridCoord.OnMouseMove;
	
		oGridCoord.Init(0, 90, 10);	// this is to be calibrated
	}
	</script>

To Query the coordinate:
	oGridCoord.GetGridCoord()
*/

function GridCoord() {
	this.l_xcurs = 0;
	this.l_ycurs = 0;
	this.headerHeight = 65;
	this.marginLeft   = 0;
	this.scale = 10;
	this.pageWidth = 1000;
	
	// statics:
	var ns6=document.getElementById && !document.all; // netscape / mozilla?
	var ietruebody = 
		(document.compatMode && document.compatMode!="BackCompat") ? document.documentElement : document.body;
	var ie=document.all;

	// fns:

	this.GetGridCoord = function () {
		return "(" + this.l_xcurs + ", " + this.l_ycurs + ") ";
	}
	
	this.OnMouseMove = function(e) {
		var lhs = (document.body.offsetWidth - this.pageWidth)/2;
		var xcurs = 0;
		var ycurs = 0;

		var winwidth=ie&&!window.opera? ietruebody.clientWidth : window.innerWidth-20;

	
		if (ns6) {
			lhs = lhs + this.scale;
			lhs = lhs + (winwidth < this.pageWidth ? this.pageWidth - winwidth : 0)/2;
			xcurs = e.pageX;
			ycurs = e.pageY;
		} else {
			lhs = lhs + (winwidth < this.pageWidth ? this.pageWidth - winwidth : 0)/2;
			xcurs = event.clientX;
			ycurs = event.clientY;
		}
	
		if (ns6) {
			this.l_xcurs = Math.floor((xcurs - lhs - this.marginLeft)/this.scale) + 1;
			this.l_ycurs = Math.floor((ycurs - this.headerHeight)/this.scale);
		} else {
			this.l_xcurs = Math.floor((xcurs - lhs - this.marginLeft + document.body.scrollLeft)/this.scale) + 1;
			this.l_ycurs = Math.floor((ycurs - this.headerHeight + document.body.scrollTop)/this.scale);
		}
	}

	this.Init = function(pagewidth, relativeToTop, scale) {
		this.headerHeight = relativeToTop;
		this.pageWidth    = pagewidth;
		this.scale		  = scale;
	}


}