(function() {
var obs, movL, i;
obs = [];
movL = function(obj, l, t, x, y) {
var dir, rate, rl, rt, dl, dt, sl, st, ob;
dir = function(s,e) {return s>e?-2:2;};
rate = function(a,b) {return a<b?a/b:1;};
this.isEnd = function() {
return (dl !== 0 && Math.abs(l-sl) < Math.abs(dl)) ||
(dt !== 0 && Math.abs(t-st) < Math.abs(dt) ||
(dl === 0 && dt === 0));
};
this.endP = function(x, y) {
if (y === undefined) st = Math.floor(($B.height - ob.height) * Math.random());
else st = y;
if (x === undefined) sl = Math.floor(($B.width - ob.width) * Math.random());
else sl = x;
rl = Math.abs(l-sl);
rt = Math.abs(t-st);
dl = dir(l,sl)*rate(rl,rt);
dt = dir(t,st)*rate(rt,rl);
}
this.pos = function() {
ob.moveto(Math.floor($B.left()+l)+'px',Math.floor($B.top()+t)+'px');
};
this.inc = function() {
l += dl;
t += dt;
}
if (t === undefined) t = parseInt(obj.top,10) - $B.top();
if (l === undefined) l = parseInt(obj.left,10) - $B.left();
ob = obj;
this.endP(x,y);
return this;
}
obs[0] = {};
obs[0].path = {x:[],y:[]};
obs[0].anim = new $O('myobj1');
obs[0].path.x[0] = ($B.width-obs[0].anim.width)/2;
obs[0].path.y[0] = 20;
obs[0].path.x[1] = 20;
obs[0].path.y[1] = obs[0].path.y[2] = $B.height - obs[0].anim.height - 20;
obs[0].path.x[2] = $B.width - obs[0].anim.width - 20;
obs[0].p = new movL(obs[0].anim, obs[0].path.x[0], -obs[0].anim.height, obs[0].path.x[0], obs[0].path.y[0]);
obs[0].end = function() {
obs[0].p.endP(obs[0].path.x[obs[0].n], obs[0].path.y[obs[0].n++]);
if (obs[0].n >= obs[0].path.x.length) obs[0].n = 0;
};
obs[1] = {};
obs[1].anim = new $O('myobj2');
obs[1].p = new movL(obs[1].anim, ($B.width-obs[1].anim.width)/2, $B.height+obs[1].anim.height, ($B.width-obs[1].anim.width)/2, $B.height - obs[1].anim.height - 20);
obs[1].end = function() {obs[1].p.endP();};
for (i = obs.length-1; i>=0; i--) {
(function() {
var ob = obs[i];
ob.n = 1;
ob.f = function() {
if (ob.p.isEnd()) {ob.end();}
ob.p.inc();
ob.p.pos();
};
ob.stop = function() {clearInterval(ob.c);};
ob.start = function() {ob.c= setInterval(ob.f,50);};
ob.anim.setVisibility('visible');
ob.c = setInterval(ob.f,50);
$E.add(ob.anim,'mouseover', ob.stop);
$E.add(ob.anim,'mouseout',ob.start);
$E.add(window,'scroll',ob.p.pos);
})();
}
})();
|