var aMouse=new Object();
aMouse.handle=new Array();
aMouse.isStatic=new Array();
aMouse.current;
aMouse.startX;
aMouse.startY;

aMouse.register=function(handle){
	//A HANDLE THAT DOES MOVE
	//REGISTER THE MOUSE handle TO RECIEVE MOVEMENT EVENTS
	if (!handle.mouseDown || !handle.mouseDrag || !handle.mouseUp) error("aMouse.register: Handle must be assigned mouse methods");
	this.handle.push(handle);
}//register

aMouse.down=function(event){
	event=aEvent(event);
	this.current=this.getHandle(event);
	if (this.current){
		this.startX=event.pageX;
		this.startY=event.pageY;
		if (this.current.mouseDown)	this.current.mouseDown(this.startX-this.current.left, this.startY-this.current.top);
	}//endif
}//down

aMouse.up=function(event){
	event=aEvent(event);
	if (this.current){
		//SEND ONE LAST DRAG
		this.current.mouseDrag(event.pageX, event.pageY);
		if (this.current.mouseUp) this.current.mouseUp();
		this.current=null;

		//MAKE SURE CURSOR IS SET CORRECTLY
		var over=this.getHandle(event);
		if (over){
			document.body.style.cursor="move";
		}else{
			document.body.style.cursor="default";
		}//endif
	}//endif
}//up

aMouse.move=function(event){
	event=aEvent(event);
	if (this.current){
		if (this.current.mouseDrag) this.current.mouseDrag(event.pageX, event.pageY);
	}else{
		var over=this.getHandle(event);

		if (over){
			document.body.style.cursor="move";
		}else{
			document.body.style.cursor="default";
		}//endif
	}//endif
}//move


///////////////////////////////////////////////////////////////////
//PRIVATE//////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////

aMouse.getHandle=function(event){
	for(i=0;i<this.handle.length;i++){
		var handle=this.handle[i];
		var dx=event.pageX-handle.left;
		var dy=event.pageY-handle.top;
		if (dx>=0 && dx<=handle.width && dy>0 && dy<=handle.height){
			return handle;
		}//endif
	}//for
	return null;
}//getHandle

