/*Designed by Maxim Popov — ecto.ru */

function delay_move(id)
{
var obj=document.getElementById(id);
var startx;
var starty;
var destx;
var desty;
var fullPath;
var halfFullPath;
var maxSpeed=10;
var timeout;
var sinu;
var cosi;
var nowx;
var nowy;
var speed=0;
var speedOfSpeed=10;

this.move=function(x,y)
{
	destx=x;
	desty=y;
	nowx=obj.offsetLeft;
	nowy=obj.offsetTop;
	startx=obj.offsetLeft;
	starty=obj.offsetTop;
	fullPath=countPath(nowx,nowy);
	halfFullPath=fullPath/2;
	window.clearInterval(timeout);
	timeout=window.setInterval(moving,15);
	sinu=(destx-nowx)/fullPath;
	cosi=(desty-nowy)/fullPath;
	speed=0;
}

function moving()
{
	if((path=countPath(nowx,nowy))<=1)
	{
	setPosition(destx,desty);
	window.clearInterval(timeout);
	return false;
	}

	if(path>halfFullPath)
	{
	speed=(fullPath-path)/speedOfSpeed+0.5;
	//speed+=0.4 //linear speed
	}
	else
	{
	speed=(path)/speedOfSpeed+0.5;
	//speed-=0.4 //linear speed
	}

	if(speed>maxSpeed)
	speed=maxSpeed;

	if(speed<0.1)
	speed=0.1;

	setPosition(nowx+speed*sinu,nowy+speed*cosi);
	return true;
}


function setPosition(x,y)
{ obj.style.left=x+‘px’; obj.style.top=y+‘px’;
	nowx=x;
	nowy=y;
}

function countPath(x,y)
{
return Math.sqrt(Math.pow(x-destx,2)+Math.pow(y-desty,2));
}

}