// JavaScript Document

//*************************************************************
// Defime IMouse properties and Mathods
//*************************************************************
function IMouse() {
	this.x = 0;
	this.y = 0;
	
	this.coordX;
	this.coordY;

	//methods
	this.getCoords = getCoords;
	this.getXY = getXY;
	this.getCoordXY = getCoordXY;
	this.moveMouse = moveMouse;
}

//*************************************************************
// Call the nessessary functions in order to get coords
//*************************************************************

function getCoords(e,pMap) {
	
	this.getXY(e,pMap) 
	this.getCoordXY(IMouse.x,IMouse.y,pMap) 
}


//*************************************************************
// Get the X and Y of the mouse on the map Layer
//*************************************************************
function getXY(e,pMap) {
	var top = parseInt(pMap.layer.offsetTop);
	var left = parseInt(pMap.layer.offsetLeft);
	if (isNav) {
		IMouse.x =e.pageX -left;
		IMouse.y=e.pageY - top;
	} else {
		IMouse.x=event.clientX + document.body.scrollLeft - left ;
		IMouse.y=event.clientY + document.body.scrollTop - top ;
	}
	
}



//*************************************************************
// send the Mouse X and Y and convert to spatial coords
//*************************************************************
function getCoordXY(xIn,yIn,pMap) {
	
	var mouseXX = xIn;
	var pixelX = (parseFloat(pMap.envelope.maxx)-parseFloat(pMap.envelope.minx)) / parseFloat(pMap.width);
	var newX = pixelX * mouseXX + parseFloat(pMap.envelope.minx);
	var mouseYY = parseFloat(pMap.height) - yIn;
	var pixelY = (parseFloat(pMap.envelope.maxy)-parseFloat(pMap.envelope.miny)) / parseFloat(pMap.height);
	var newY = (pixelY * mouseYY) + parseFloat(pMap.envelope.miny);
	
	IMouse.coordX = newX;
	IMouse.coordY = newY;

	
}



//*************************************************************
// Assign an onmousemove event to show coords.
//*************************************************************
function moveMouse(pMap) 
{
	
	pMap.layer.onmousemove= function(e) {
		getCoords(e,pMap);
		mapMoveMouseOperations();

	}
}









