document.onselectstart = new Function("return false");

object = new Array();
line = new Array();
K  = Math.PI / 180;
N  = 0;
xm = 0;
ym = 0;
mx = 0;
my = 0;
ax = 0;
ay = 0;
Nb = 0;
tit = 0;
img = 0;
////////////////
zM = 4;
bD = "#000 solid 0px";
////////////////

function Cline(){
	// crossbrowser line - Gerard Ferrandez - Feb 2005
	this.o = document.createElement("img");
	document.body.appendChild(this.o);
	this.src = 0;
	this.flip = function flip(s){ if(this.src!=s) this.src=s, this.o.src=document.getElementById("L"+s).src; }
	this.move = function move(x0,y0,x1,y1) {
		if(x1>x0){ // right
			if(y1>y0) with(this.o.style)left=x0, top=y0, width=x1-x0, height=y1-y0, this.flip(1); // bottom
			else with(this.o.style)left=x0, top=y1, width=x1-x0, height=y0-y1, this.flip(2); // up
		} else { // left
			if(y1>y0) with(this.o.style)left=x1, top=y0, width=x0-x1, height=y1-y0, this.flip(2); // bottom
			else with(this.o.style)left=x1, top=y1, width=x0-x1, height=y0-y1, this.flip(1); // up
		}
	}
}

function CObj(N,x,y,z){
	I = img.getElementsByTagName("img")[N%img.getElementsByTagName("img").length];
	o = document.createElement("img");
//	o.onclick=new Function("if(object["+N+"].on==true)object["+N+"].on=false; else object["+N+"].on=true");
	o.onclick=new Function("location.href='page"+(parseInt(N)+1)+".php';");
	o.onmouseover=new Function('if(Nb!='+N+')Nb='+N+',tit.innerHTML=\"'+I.alt+'\";');
	o.onmouseout=new Function("Nb=-1;object["+N+"].on=false;tit.innerHTML=''");
	o.onmousedown=new Function("return false");
	o.src=I.src;
	o.style.border = bD;
	document.body.appendChild(o);
	this.obj  = o.style;
	line[N]   = new Cline();
	this.z    = Math.round(z * ny * .25);
	this.x    = Math.round(x * ny * .25);
	this.y    = Math.round(y * ny * .25);
	this.on   = false;
	this.zOOm = 1;
	this.N    = N;

	this.anim = function () {
		with(this){
			xP = z * Math.sin(mx * K) + x  * Math.cos(mx * K);
			zP = z * Math.cos(mx * K) - x  * Math.sin(mx * K);
			yP = y * Math.cos(my * K) - zP * Math.sin(my * K);
			zP = y * Math.sin(my * K) + zP * Math.cos(my * K);
			w  = (zP * .25 + ny * .25) * zOOm;
			h = w * .8;
			if(zP>0)obj.cursor="hand";
			else obj.cursor="crosshair";
			if(on && zP>0){
				if(zOOm<zM)zOOm+=.05;
			} else {
				if(zOOm>1)zOOm-=.025;
			}
			with(obj){
				left   = xP + nx * .5 - w * .5;
				top    = yP + ny * .5 - h * .5;
				width  = w;
				height = h;
				zIndex = Math.round(100 + w);
			}
			line[N].move(Math.round(nx * .5),Math.round(ny * .5),Math.round(xP + nx * .5),Math.round(yP + ny * .5));
		}
	}

	N++;
}

function run(){
	dx = (1 * xm) - mx;
	dy = (1 * ym) - my;
	mx+= dx / 60;
	my+= dy / 60;
	for(i in object)object[i].anim();
	tit.style.left = xm - 100;
	tit.style.top  = ym + 20;
	setTimeout(run, 16);
}

document.onmousemove = function(e){
	if (window.event) e = window.event;
	xm = (e.x || e.clientX);
	ym = (e.y || e.clientY);
}

function resize(){
	nx = document.body.offsetWidth;
	ny = document.body.offsetHeight;
}
onresize = resize;

onload = function (){
	img = document.getElementById("img");
	tit = document.getElementById("tit");
	resize();
	object[0] = new CObj(0,1,-1,-1);
	object[1] = new CObj(1,1,1,-1);
	object[2] = new CObj(2,-1,-1,-1);
	object[3] = new CObj(3,-1,1,-1);
	object[4] = new CObj(4,1,-1,1);
	object[5] = new CObj(5,1,1,1);
	object[6] = new CObj(6,-1,-1,1);
	object[7] = new CObj(7,-1,1,1);
	run();
}