function MoveTool(map, layer, embedDiv, proxyTool, onStartFunc, onDropFunc) {
    this.map = map;
    this.layer = layer;
    this.embedDiv = embedDiv;
    //this.proxyTool = proxyTool;
    //this.cursor = "pointer";
    this.setProxyTool(proxyTool);
    
    
    this.moveObject = null;

    //this.delta = 12;

    this.manipulateFunc = associateObjWithEvent(this, "manipulate");
    this.endManipulationFunc = associateObjWithEvent(this, "endManipulation");

    this.lockedName = "locked";

    this.onStartFunc = onStartFunc;
    this.onDropFunc = onDropFunc;
};
MoveTool.prototype.setProxyTool = function(tool) {
    if(tool){
        this.proxyTool = tool;
        this.cursor   = tool.cursor;
        this.map.setTool(this);
        //alert(this.cursor);
    }
}
MoveTool.prototype.startManipulation = function(orgEvt) {
    evt = new Evt(orgEvt);
    
    var x = evt.x - this.embedDiv.offsetLeft;
    var y = evt.y - this.embedDiv.offsetTop;

    this.startX = evt.x - this.embedDiv.offsetLeft;
    this.startY = evt.y - this.embedDiv.offsetTop;

    this.moveObject = null;
    if (this.layer.geoObjectArray) {
	for (var i = 0; i < this.layer.geoObjectArray.length; i++) {
	    var obj = this.layer.geoObjectArray[i];

	    var point = map.getPosition(x, y);
	    var hit = obj.boundingArea.inside(point.x, point.y);

	    var locked = false;
	    var attributes = obj.attributes;
	    for (var j = 0; j < attributes.length; j++) {
		if (attributes[j].name == this.lockedName) {
		    locked = attributes[j].value;
		    break;
		}
	    }

	    if (hit && !locked) {
		this.moveObject = this.layer.geoObjectArray[i];

		if(document.attachEvent){
		    document.body.attachEvent("onselectstart", returnFalse, false);
		    document.body.attachEvent("ondrag", returnFalse, false);
		}

		Evt.addEventListener(document, "mousemove", this.manipulateFunc, false);
		Evt.addEventListener(document, "mouseup", this.endManipulationFunc, false);

		if (this.onStartFunc) {
		    this.onStartFunc(this.moveObject);
		}

		break;
	    }
	}
    }

    evt.consume();

    if ((this.moveObject == null) && (this.proxyTool != null)) {
	    // No hit, run the proxy tool instead.
	    this.proxyTool.startManipulation(orgEvt);
    }
};

MoveTool.prototype.manipulate = function(evt, element) {
    if (this.moveObject != null) {
	if (this.bufferTimer) {
	    return;
	}
    
	evt = new Evt(evt);
    
	var x = evt.x - this.embedDiv.offsetLeft;
	var y = evt.y - this.embedDiv.offsetTop;
	
	var point = map.getPosition(x, y);

	this.moveObject.setPosition(point.x, point.y, null);

	this.layer.refresh();

	if (isIe6) {
	    //Timeout to allow ie6 to redraw between updates
	    this.bufferTimer = setTimeout(associateObjWithEvent(this, "clearBufferTimer"), 50);
	}
	evt.consume();
    }
};

MoveTool.prototype.cancelManipulation = function() {
    if (this.moveObject != null) {
	this.moveObject = null;

	if(document.detachEvent){
	    document.body.detachEvent("onselectstart", returnFalse, false);
	    document.body.detachEvent("ondrag", returnFalse, false);
	}
	
	Evt.removeEventListener(document, "mousemove", this.manipulateFunc, false);
	Evt.removeEventListener(document, "mouseup", this.endManipulationFunc, false);
	
	evt.consume();
    }
};

MoveTool.prototype.endManipulation = function(evt, element) {
    if (this.moveObject != null) {
	evt = new Evt(evt);
    
	var x = evt.x - this.embedDiv.offsetLeft;
	var y = evt.y - this.embedDiv.offsetTop;

	var point = map.getPosition(x, y);

	this.moveObject.setPosition(point.x, point.y, null);
	
	//this.moveObject = null; //removed by Ingemar Nilsson - see above

	this.layer.refresh();

	if(document.detachEvent){
	    document.body.detachEvent("onselectstart", returnFalse, false);
	    document.body.detachEvent("ondrag", returnFalse, false);
	}
    
	Evt.removeEventListener(document, "mousemove", this.manipulateFunc, false);
	Evt.removeEventListener(document, "mouseup", this.endManipulationFunc, false);

	if (this.onDropFunc) {
	    this.onDropFunc(this.moveObject);
	}
    this.moveObject = null; //added by Ingemar Nilsson - see below

	evt.consume();
    }
};

MoveTool.prototype.unload = function() {
    try	{
	if(document.detachEvent){
	    document.body.detachEvent("onselectstart", returnFalse, false);
	    document.body.detachEvent("ondrag", returnFalse, false);
	}

	Evt.removeEventListener(document, "mousemove", this.manipulateFunc, false);
	Evt.removeEventListener(document, "mouseup", this.endManipulationFunc, false);
    } catch(e) {
    }
};

MoveTool.prototype.clearBufferTimer = function(evt, element) {
    this.bufferTimer = null;
}

