// ============================================================================
// script realized by Gérard Ferrandez - June 2006
// http://www.dhteumeuleu.com
// ============================================================================
//////////////////////////////////////////////////////////////////////////////
var O    = [];
var cont = 0;
var N    = 0;
var S    = 0;
var img, spa;
var s = {xm:0, ym:0, nx:0, ny:0, nw:0, nh:0, cx:0, cy:0, zoom:1};
var c = {x:0, y:0, z:-40000, xt:0, yt:0, zt:0};

//////////////////////////////////////////////////////////////////////////////

function _resize() {

	with(document.getElementById("canvas")){
		s.nx = offsetLeft;
		s.ny = offsetTop;
		s.nw = offsetWidth;
		s.nh = offsetHeight;
		s.zoom = s.nh / 700;
	}
}

document.onmousemove = function(e){
	if(window.event) e=window.event;
	s.xm = (e.x || e.clientX) - s.nx - s.nw * .5;
	s.ym = (e.y || e.clientY) - s.ny - s.nh * .5;
}

function CObj(n){
	this.n = n;
	this.x = s.zoom * Math.random() * s.nw * 2 - s.nw;
	this.y = s.zoom * Math.random() * s.nh * 2 - s.nh;
	this.z = Math.round(n * (10000 / N));
	this.w = img[n].width;
	this.h = img[n].height;
	this.oxt = spa[n];
	this.txt = spa[n].innerHTML;
	this.oxt.innerHTML = "";
	this.obj = img[n];
	this.obj.parent = this;
	this.obj.onclick = new Function("this.parent.click();");
	this.obj.ondrag = new Function("return false;");
	this.oxt.style.zIndex = this.obj.style.zIndex = Math.round(1000000 - this.z);
	this.F = false;
	this.CF = 100;
	this.sto = [];
	this.anim = function(){
		with(this){
			var f = 700 + z - c.z;
			if (f > 0) {
				var d = 1000 / f;
				var X = s.nw * .5 + ((x - c.x - s.cx) * d);
				var Y = s.nh * .5 + ((y - c.y - s.cy) * d);
				var W = d * w * s.zoom;
				var H = d * h * s.zoom;
				with(obj.style){
					left   = Math.round(X - W * .5)+"px";
					top    = Math.round(Y - H * .5)+"px";
					width  = Math.round(W)+"px";
					height = Math.round(H)+"px";
				}
				with(oxt.style){
					visibility = (CF-- > 0 && Math.random() > .9)?"hidden":"visible";
					left   = Math.round(X - W * .5)+"px";
					top    = Math.round(Y + H * .5)+"px";
					if((c.zt - c.z) < 20){
						if(!F){
							F = true;
							CF = Math.random() * 200;
							fontSize = 1 + Math.round(d * 20 * s.zoom)+"px";
							var T = "";
							var tn = txt.length;
							for(var i=0; i<tn; i++){
								T+=txt.charAt(i);
								sto[i] = setTimeout('O['+n+'].oxt.innerHTML = "'+(T+"_")+'";', Math.round(f/4)+32*i);
							}
						}
					} else F=false, oxt.innerHTML="";
				}
			} else {
				x = s.zoom * Math.random() * s.nw * 2 - s.nw;
				y = s.zoom * Math.random() * s.nh * 2 - s.nh;
				z += 10000;
				oxt.style.zIndex = obj.style.zIndex = Math.round(1000000 - z);
			}
		}
	}

	this.cto = function(){
		with(this){
			var tn = txt.length;
			for(var i=0; i<tn; i++){
				clearTimeout(sto[i]);
			}
		}
	}

	this.click = function(){
		for(var i in O)O[i].cto();
		with(this){
			var tn = txt.length;
			for(var i=0; i<tn; i++){
				clearTimeout(sto[i]);
			}
			if(S!=this){
				c.xt = x;
				c.yt = y;
				c.zt = z;
				S = this;
			} else {
				S = 0;
				c.zt += 1600;
			}
		}
	}
}

function run(){
	s.cx += (s.xm - s.cx) / 10;
	s.cy += (s.ym - s.cy) / 10;
    c.x  += (c.xt - c.x)  / 20;
    c.y  += (c.yt - c.y)  / 20;
    c.z  += (c.zt - c.z)  / 20;
	for(var i=0; i<N; i++) O[i].anim();
	setTimeout("run();", 16);
}

function dom_onload() {
	_resize();
	s.cx = s.nw / 2;
	s.cy = s.nh / 2;
	cont = document.getElementById("canvas");
	img = document.getElementById("canvas").getElementsByTagName("img");
	spa = document.getElementById("canvas").getElementsByTagName("span");
	N = img.length;
	for(var i=0; i<N; i++) O[i] = new CObj(i);
	run();
	O[0].click();

}
