// ====================================================
// script: Gerard Ferrandez - Ge-1-doot - June 2005
// http://www.dhteumeuleu.com/
// ====================================================

window.onerror         = new Function("return true");
document.onselectstart = new Function("return false");

var object = new Array();
var margin = 20;
var K = 0;

function CObj(N,x,y,txt){
	this.obj = document.createElement("span");
	this.obj.innerHTML = txt;
	this.obj.className = "word";
	this.obj.onmouseover = new Function("this.className='word_over',object["+N+"].izoom();");
	document.getElementById("sp").appendChild(this.obj);
	this.obj.style.left = x;
	this.obj.style.top  = y;
	this.obz = 0;
	this.x  = x;
	this.y  = y;
	this.x0 = x;
	this.y0 = y;
	this.fs = 12;
	this.c  = 0;
	this.px = txt.length * .02;
	this.py = .04;
	this.zoom = function () {
		with(this){
			fs *= 1.08;
			c = 512 - fs * 2;
			x -= fs * px;
			y -= fs * py;

			with(obz.style){
				left = x;
				top  = y;
				fontSize = Math.round(fs);
				color = "RGB("+Math.round(255-c*.5)+","+Math.round(255-c*.5)+","+Math.round(255-c*.5)+")";
			}

			if(c<8){
				document.getElementById("sp").removeChild(obz);
				obj.className="word";
				x = x0;
				y = y0;
				fs = 12;
				obz = 0;
				K--;
			} else setTimeout("object["+N+"].zoom();",16);
		}
	}
	this.izoom = function () {
		with(this){
			if(K<20){
				if(obz == 0){
					obz = document.createElement("span");
					obz.className = "word_zoom";
					obz.innerHTML = txt;
					obz.style.left = x-1;
					obz.style.top  = y;
					document.getElementById("sp").appendChild(obz);
					zoom();
					K++;
				}
			} else setTimeout("object["+N+"].izoom();",128);
		}
	}
}


function fontWidth(word){
	// arial font
	var S = "a68b68c68d68e68f31g68h68i31j31k68l31m108n68o68p68q68r39s68t39u68v50w90x68y68z68A90B90C90D90E90F78G98H90I28J59K90L68M108N90O98P90Q98R90S90T68U90V90W130X68Y90Z68'30.42!29?68-41/41=72";
	var l = word.length;
	var s = 0;
	var x = 0;
	var c = 0;
	for(i=0;i<l;i++){
		c = word.charAt(i);
		x = S.indexOf(c);
		if(c>="0" && c<="9")s+=69;
		else if(x>=0)s+=parseInt(S.substring(x+1,x+4));
		else s+=68;
	}
	return s/10;
}

function loader(text){

	T = text;

	x = 0;
	y = 0;
	k = 0;
	for(j in T){
		Tx = T[j].split(" ");
		// justify
		xt = 0;
		for(i in Tx){
			txt = Tx[i];
			xt += fontWidth(txt);
		}
		if(Tx.length)sP = (-2*margin + parseInt(document.getElementById("sp").style.width) - xt) / (Tx.length-1); else sP = 0;
		// insert word
		for(i in Tx){
			txt = Tx[i];
			if(txt) {
				object[k] = new CObj(k, margin+x, margin+y, txt);
				x += (fontWidth(txt)+sP);
				k++;
			}
		}
		y += 18;
		x = 0;
	}
}
