var movetimeout;
var locktimeout;

function reposition(object, newx, newy) {
	object.style.top = newy+"px";
	object.style.left = newx+"px";
}

function lockToCursor(strObject) {
	clearTimeout(locktimeout)
	var object = document.getElementById(strObject);
	object.style.position = "absolute"
	object.style.top = parseInt(tempY)+10+"px";
	object.style.left = parseInt(tempX)+10+"px";
	locktimeout = setTimeout("lockToCursor('"+strObject+"')", 20)
}

function animatedReposition (id, newx, newy) {
	object = document.getElementById(id);
	clearTimeout(movetimeout);
	//find current position of the object
	curx = parseInt(object.style.top);
	cury = parseInt(object.style.left);
	diffx = 0;
	diffy = 0;
	
	//alert(curx + ", " + cury);
	//find out the difference between old position and new position
	if (curx<newx) {
		diffx = newx - curx;
	} else {
		diffx = curx - newx;
	}
	
	if (cury<newy) {
		diffy = newy - cury;
	} else {
		diffy = cury - newy;
	}
	//alert(diffx+", "+diffy);
	//work out the y for x (or the x for y)
	ysubstep = false;
	step = 0;
	substep = 0;
	if (diffx < diffy) {
		step = diffy;
		substep = step/diffx;
	} else if (diffx > diffy) {
		step = diffx;
		substep = step/diffy;
		ysubstep = true;
	}
	//alert(step+", "+substep);
	i = 0;
	
	if (ysubstep) {
		if (parseInt(object.style.top) < newx) {
			object.style.top = (parseInt(object.style.top) + 1) + "px";
		} else if (parseInt(object.style.top) > newx) {
			object.style.top = (parseInt(object.style.top) - 1) + "px";
		}
		if (parseInt(object.style.left) < newy) {
			object.style.left = (parseInt(object.style.left) + substep) + "px";
		} else if (parseInt(object.style.left) > newy) {
			object.style.left = (parseInt(object.style.left) - substep) + "px";
		}
	} else {
		if (parseInt(object.style.top) < newx) {
			object.style.top = (parseInt(object.style.top) + substep) + "px";
		} else if (parseInt(object.style.top) > newx) {
			object.style.top = (parseInt(object.style.top) - substep) + "px";
		}
		if (parseInt(object.style.left) < newy) {
			object.style.left = (parseInt(object.style.left) + 1) + "px";
		} else if (parseInt(object.style.left) > newy) {
			object.style.left = (parseInt(object.style.left) - 1) + "px";
		}
	}
	
	if ((parseInt(object.style.top) != newx) && (parseInt(object.style.left) != newy)) {
		setTimeout("animatedReposition ('"+id+"', "+newx+", "+newy+")", 20)
	}
}