﻿//overload the onmove function of moveable so we can check where the element is in relation to
//the bounding box
dojo.declare("dojo.dnd.Moveable",
        [ dojo.dnd.Moveable ],
        // class properties:
        {
		onMove: function(/* dojo.dnd.Mover */ mover, /* Object */ leftTop){
			// summary: called during every move notification,
			//	should actually move the node, can be overwritten.
			this.onMoving(mover, leftTop);
			var s = mover.node.style;
			var boxSize = dojo.coords(mover.node,true);
			var parentSize = dojo.coords(mover.node.parentNode);
			//keeps the element inside the parent element
			//note, only coded to work with a relativly positioned parent node
			//remove if statment (keep body) to restore default functionality
			if(leftTop.l > (boxSize.w * -.9) && leftTop.t > (boxSize.h * -.9) && leftTop.l-(boxSize.w*.9) < parentSize.w-boxSize.w && leftTop.t-(boxSize.h*.9) < parentSize.h-boxSize.h)
			{
				s.left = leftTop.l + "px";
				s.top  = leftTop.t + "px";
				setClip();			
			}
			this.onMoved(mover, leftTop);
		},
		// mouse event processors
		onMouseDown: function(e){
			// summary: event processor for onmousedown, creates a Mover for the node
			// e: Event: mouse event			
			//added a test to make the on mouse down get ignored for right click			
			if(e.button==2){return;}
			//original code below
			if(this.skip && dojo.dnd.isFormElement(e)){ return; }
			if(this.delay){
				this.events.push(dojo.connect(this.handle, "onmousemove", this, "onMouseMove"));
				this.events.push(dojo.connect(this.handle, "onmouseup", this, "onMouseUp"));
				this._lastX = e.pageX;
				this._lastY = e.pageY;
			}else{
				new this.mover(this.node, e, this);
			}
			dojo.stopEvent(e);
		}
});
