var x=0;
var y=0;
var maxX=100;
var maxY=90;
var speed=0.5;
var refresh=5;
var toX=0;
var toY=0;
var stepX=0;
var stepY=0;
var SoluSkaits=0;
var Solis=0;



function moveYourFuc_inBaloon()
{
    toX=Math.floor(Math.random()*(maxX*2+1))-maxX;
    toY=Math.floor(Math.random()*(maxY*2+1))-maxY;
    SoluSkaits=Math.max(Math.abs(toX-x), Math.abs(toY-y)) / speed;
    stepX=Math.abs( (toX-x) / SoluSkaits );
    stepY=Math.abs( (toY-y) / SoluSkaits );
    Solis=0;
    SoluSkaits=SoluSkaits+4;
    goTo();
}


function goTo()
{
    Solis++;
    solisY=stepY;
    solisX=stepX;

    if(Solis==1)solisY=stepY/6;
    if(Solis==2)solisY=stepY/3;
    if(Solis==3)solisY=stepY/2;
    if(Solis==SoluSkaits-2)solisY=stepY/2;
    if(Solis==SoluSkaits-1)solisY=stepY/3;
    if(Solis==SoluSkaits)solisY=stepY/6;

    if(Solis==1)solisX=stepX/6;
    if(Solis==2)solisX=stepX/3;
    if(Solis==3)solisX=stepX/2;
    if(Solis==SoluSkaits-2)solisX=stepX/2;
    if(Solis==SoluSkaits-1)solisX=stepX/3;
    if(Solis==SoluSkaits)solisX=stepX/6;


    if(Math.round(y)<toY)yyy=solisY;
    if(Math.round(y)>toY)yyy=0-solisY;
    if(Math.round(y)==toY)yyy=0;
    if(Math.round(x)<toX)xxx=solisX;
    if(Math.round(x)>toX)xxx=0-solisX;
    if(Math.round(x)==toX)xxx=0;
    x=x+xxx;
    y=y+yyy;

    //alert('x='+x+' toX='+toX+'        y='+y+'   toY='+toY);

    a=document.getElementById('mansBalons');
    a.style.top=Math.round(y);
    a.style.left=Math.round(x);

    t=setTimeout('goTo()',refresh);
    if(Math.round(x)==toX && Math.round(y)==toY)
    {
        clearTimeout(t);
        var date = new Date();
	    var curDate = null;

	    do { curDate = new Date(); }
	    while(curDate-date < 50);
        moveYourFuc_inBaloon();
    }
}
