DragHandler = {
	evtAction : "mouse",
	mouseDownHandler : function (e) {
		
		if (this.mouseIsDown) return;
		else this.mouseIsDown = true;
		
		if ( arguments.length == 0 )
		   e = event;
		
		var nsEvent = e.which != undefined;
		if ( (nsEvent && e.which != 1) || (!nsEvent && e.button != 1))
		   return;
	
		// manage event
		this.mouseMoveHandlerFunc = this.mouseMoveHandler.bindAsEventListener(this);
		this.mouseUpHandlerFunc = this.mouseUpHandler.bindAsEventListener(this);
		Event.observe(document, "mousemove", this.mouseMoveHandlerFunc );
		Event.observe(document, "mouseup", this.mouseUpHandlerFunc );
	    
		//get Target Information
		this.targetElement = Event.element(e);
		
		// position information
		this.getOriginalPosition(e);
		this[this.evtAction+"DownAction"](e);
		
	},
	
	mouseMoveHandler : function (e) {
		
		if ( arguments.length == 0 )
		   e = event;
		
		
		this.getMousePosition(e);
		this[this.evtAction+"MoveAction"](e);
		
	},
	
	mouseUpHandler : function (e) {
		
		if (this.mouseIsDown) this.mouseIsDown = false;
		else return;
		
		Event.stopObserving(document, "mousemove", this.mouseMoveHandlerFunc );
		Event.stopObserving(document, "mouseup", this.mouseUpHandlerFunc );
		
		this[this.evtAction+"UpAction"](e);
		
	},
	

	getOriginalPosition : function (e) {
		this.origx = 0;
		this.origy = 0;
		this.getMousePosition(e);
		this.origx = this.posx;
		this.origy = this.posy;
	},
	
	getMousePosition : function (e) {
	
		// specify the startx, starty
		this.posx = Event.pointerX(e);
		this.posy = Event.pointerY(e);

		this.dx = (this.posx - this.origx);
		this.dy = (this.posy - this.origy);
		
	},
	
	implementHandler : function (evtName, mousedown, mousemove, mouseup) {
		this[evtName+"DownAction"] = mousedown;
		this[evtName+"MoveAction"] = mousemove;
		this[evtName+"UpAction"] = mouseup;
		
	},
	
	startHandler : function (evtAction) {
		var ev = evtAction;
		var obj = this;
		return function (e) {
			obj.evtAction = ev;
			obj.mouseDownHandler(e);
		}
	},
	
	observeDrag : function (element, evtAction) {
		evtAction = evtAction || "mouse";
		Event.observe($(element), 'mousedown', this.startHandler(evtAction) );
	},
	
	/* to be implemented */
	mouseDownAction : function () {},
	mouseMoveAction : function () {},
	mouseUpAction : function () {}
	
	/* accesible variable
		this.posx, this.posy
		this.dx, this.dy
		this.origx, this.orgy
		this.targetElement
	*/
	
}
	