var isMovingx = new Object;
var isMovingy = new Object;
var actualLeft = new Object;
var actualTop  = new Object;

function movediv(obj, x, y, time, callwhendone) {
	isMovingx[obj.id] = 1;
	isMovingy[obj.id] = 1;
	actualLeft[obj.id] = obj.style.pixelLeft;
	actualTop[obj.id]  = obj.style.pixelTop;
	var speedx = (Math.abs(Math.abs(x) - Math.abs(obj.style.pixelLeft))) / (time/10);
	var speedy = (Math.abs(Math.abs(y) - Math.abs(obj.style.pixelTop))) / (time/10);
	domove(obj, actualLeft[obj.id], actualTop[obj.id], x, y, speedx, speedy, callwhendone);
}

function movedivcheck(obj, prevx, prevy, x, y, time, callwhendone) {
	if( obj.style.pixelLeft == prevx && obj.style.pixelTop == prevy ) { movediv(obj, x, y, time, callwhendone); }
}

function domove(obj, prevx, prevy, x, y, speedx, speedy, callwhendone) {
	if( obj.style.pixelLeft == prevx && obj.style.pixelTop == prevy ) {
		if( Math.abs(Math.abs(x) - Math.abs(obj.style.pixelLeft)) > speedx )  {
			if( obj.style.pixelLeft > x ) { actualLeft[obj.id] = actualLeft[obj.id] - speedx; }
			if( obj.style.pixelLeft < x ) { actualLeft[obj.id] = actualLeft[obj.id] + speedx; }
			obj.style.left= actualLeft[obj.id] + "px";
		} else {
			if( obj.style.pixelLeft != x ) { obj.style.left = x; }
			isMovingx[obj.id] = 0;
		}

		if( Math.abs(Math.abs(y) - Math.abs(obj.style.pixelTop)) > speedy )  {
			if( obj.style.pixelTop > y ) { actualTop[obj.id] = actualTop[obj.id] - speedy; }
			if( obj.style.pixelTop < y ) { actualTop[obj.id] = actualTop[obj.id] + speedy; }
			obj.style.top= actualTop[obj.id] + "px";
		} else {
			if( obj.style.pixelTop != y ) { obj.style.top = y; }
			isMovingy[obj.id] = 0;
		}

		if( isMovingx[obj.id] != 0 || isMovingy[obj.id] != 0 ) {
			prevx = obj.style.pixelLeft;
			prevy = obj.style.pixelTop;
			setTimeout("domove(" + obj.id + ", " + prevx + ", " + prevy + ", " + x + ", " + y + ", " + speedx + ", " + speedy + ", \"" + callwhendone + "\")", 10);
		} else {
			if( callwhendone != 0 ) { eval(callwhendone); }
		}
	}
}