var xxx = 0; var yyy = 0;
var dist = distX = distY = 0;
var stepx = 2;
var stepy = 2;
function distance(s,e) {return Math.abs(s-e)}
function direction(s,e) {return s>e?-1:1}
function rate(a,b) {return a<b?a/b:1}

function nextEnd() {
var eX = Math.floor(Math.random()* (pageWidth()-objWidth('myobj')));
var eY = Math.floor(Math.random()* (pageHeight()-objHeight('myobj')));
dist = distX = distance(xxx,eX);
distY = distance(yyy,eY);
stepx = 2 * direction(xxx,eX) * rate(distX,distY);
stepy = 2 * direction(yyy,eY) * rate(distY,distX); 
}

function start() {
var w = objWidth('myobj');
var h = objHeight('myobj');
xxx = (pageWidth()-w-80);
yyy = (600-h-20);

nextEnd();
moveit();
setObjVis('myobj','visible');
mover();
}
function moveit() {
var x = (posLeft()+xxx) + 'px';
var y = (posTop()+yyy) + 'px';

moveObjTo('myobj',x,y);
}
function mover() {
if (dist > 0) {
xxx += stepx;
yyy += stepy;
dist -= Math.abs(stepx);}
else {nextEnd();}
 moveit(); setTimeout('mover()',25);
}
//window.onload = start;
//window.onscroll = moveit;
