var moving;
var finalX;
var finalY;
var lastX;
var lastY;

function moveIt() {
	//set variables
	var xpos = getXOffset();
	var ypos = getYOffset();
	
	//function
	if (xpos == finalX && ypos == finalY) {
		clearInterval(moving);
	 	return true;
	}
	
	if (xpos < finalX) {
		var dist = Math.ceil((finalX - xpos)/10);
		xpos = xpos + dist;
	}
	if (xpos > finalX) {
		var dist = Math.ceil((xpos - finalX)/10);
		xpos = xpos - dist;
	}
	if (ypos < finalY) {
		var dist = Math.ceil((finalY - ypos)/10);
		ypos = ypos + dist;
	}
	if (ypos > finalY) {
		var dist = Math.ceil((ypos - finalY)/10);
		ypos = ypos - dist;
	}
	
	if (lastX == xpos && lastY == ypos) {
		clearInterval(moving);
	 	return true;	
	}
	
	lastX = xpos;
	lastY = ypos;
	window.scrollTo(xpos,ypos);
}

function scrollScreen(thisFinalX,thisFinalY,interval) {
	finalX = thisFinalX;
	finalY = thisFinalY;
	lastX = finalX;
	lastY = finalY;
	if(moving) clearInterval(moving);
	moving = setInterval("moveIt()",interval);
}
