// ====================================================
// script: Gerard Ferrandez - Ge-1-doot - JANUARY 2005
// news://news.leibowitz.org/nzn.fr.html
// http://www.dhteumeuleu.com/
// ====================================================

window.onerror         = new Function("return true");
document.onselectstart = new Function("return false");
screen.bufferDepth     = 16;

nx  = 0;
ny  = 0;
xm  = 0;
ym  = -1000000;
S   = 0;
O   = 0;
M   = 10;
var H;
var W;
var img;

/////////////
RAD  = 2;
Nx   = 12;
Ny   = 14;
visc = .01;
/////////////

function CObj(parent,x,y){
	o = document.createElement("span");
	o.className="spanCls";
	o.style.width = W + 2;
	o.style.height = H + 2;
	im = document.createElement("img");
	im.className="imgCls";
	im.src = img.src;
	im.style.left = -x * W;
	im.style.top = -y * H;
	o.appendChild(im);
	document.getElementById("SP").appendChild(o);
	x = -(Nx / 2) * W + (x * W);
	y = -(Ny / 2) * H + (y * H);
	this.obj  = o.style;
	this.x   = x;
	this.y   = y;
	this.x0  = x;
	this.y0  = y;
	this.anim = function () {
		with(this){
			dx = xm - x;
			dy = ym - y;
			d = Math.sqrt(dx * dx + dy * dy);
			obj.left = x = x - S / d * (dx / d) + (x0 - x) * visc;
			obj.top  = y = y - S / d * (dy / d) + (y0 - y) * visc;
			if(parent)parent.anim();
		}
	}
}

function run(){
	O.anim();
	setTimeout("run()", 16);
}

document.onmousemove = function(e){
	if (window.event) e = window.event;
	xm = (e.x || e.clientX) - nx;
	ym = (e.y || e.clientY) - ny;
}

function resize(){
	nx = document.body.offsetWidth * .5;
	ny = document.body.offsetHeight * .5;
}

onload = function(){
	resize();
	img = document.getElementById("IMG");
	W = img.width / Nx;
	H = img.height / Ny;
	S = img.width * RAD;
	for(y=0;y<Ny;y++) for(x=0;x<Nx;x++) O = new CObj(O, x, y);
	run();
}
