

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

nx  = 0;
ny  = 0;
xm  = 0;
ym  = -1000000;
O   = 0;

/////////////
VS  = .2;
S   = 5000;
W   = 400;
H   = 320;
FX  = 1.1;
/////////////

// 


function showGlobals() {
	console.log(
		"nx: " + nx +
		" ny: " + ny +
		" xm: " + xm +
		" ym: " + ym +
		" VS: " + VS +
		" S: " + S +
		" W: " + W +
		" H: " + H +
		" FX: " + FX
	);
}

// 


function CObj(parent,x,y,txt){
	o = document.createElement("span");
	o.innerHTML = txt;
	document.getElementById("sp").appendChild(o);
	this.obj  = o.style;
	this.x   = x;
	this.y   = y;
	this.x0  = x;
	this.y0  = y;
	this.dbg_counter = 0;
	this.anim = function () {
		with(this){
			dx = xm - x;
			dy = ym - y;
			d = Math.sqrt(dx * dx + dy * dy);
if (!(dbg_counter % 30)) {
//	showGlobals();
//	console.log("BEFORE:" + obj.left);
}
			obj.left = x = x - S / d * (dx / d) + (x0 - x) * VS;
			obj.top  = y = y - S / d * (dy / d) + (y0 - y) * VS;
if (!(dbg_counter % 30)) {
//	console.log("AFTER:" + obj.left);
}
			if(parent)parent.anim();
dbg_counter ++;
		}
	}
}

function run(){
	O.anim();
	timer = setTimeout("run()", 16);
}

function stop() {
	if (timer != null) {
		clearTimeout(timer);
	}
}


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;
}
onresize = resize;

function fontWidth(word){
	// tahoma 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;
}

onload = function(){

	////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	T = [
		"Coming soon in 2010: an all new and improved website!",
		"I'm aware that phrase is an oxymoron, but hey, let's",
		"go crazy with language! While I'm building this super-duper",
		"new website, here are some words that I like. Have fun! ",
		"====== ====== ====== ====== ====== ======",
		"play.with.me  play.with.me  play.with.me play.with.me",
		"play.with.me  play.with.me  play.with.me play.with.me",
		"",
		"",
		"",
		"play.with.me  play.with.me  play.with.me play.with.me",
		"play.with.me  play.with.me  play.with.me play.with.me",

		"====== ====== ====== ====== ====== ======",
		"obsequious, pernickety, extrapolate, quizzical, flash",
		"confabulate, perspicacious, aplomb, balustrade, crisp,",
		"pedantic, ennui, facetious, pig, discombobulate, glug,",
		"impervious, kerfuffle, lollop, officious, calamitous,",
		"plethora, scurrilous, sesquipedalian, plop, obnoxious."
	];

	// Replace
	var R = {"play.with.me": "<div style='color:#FFFF00'>play.with.me</div>"};

	/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

	resize();
	x = 0;
	y = 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 = (W - xt) / (Tx.length-1); else sP = 0;
		// insert word
		for(i in Tx){
			txt = Tx[i];
			if(txt) {
				O = new CObj(O, -(W/2)+x, -(H/2)+y, R[txt]!=undefined?R[txt]:txt);
				x += FX*(fontWidth(txt)+sP);
			}
		}
		y += 18;
		x = 0;
	}

	O = new CObj(O, -50, -20, "<div style='font-size:150%;font-weight:bold;'>welcome</div>");
	run();
}

