// JavaScript 2007, KasH.

var arrNamen = ['Karel', 'Gerard', 'Kasper', 'Jan'];
var strWinnaar = 'Han van Baarsen';
var strNaam = '';

var intFontSize = 72;
var intOpacity = 100;

var bCancel = false;
var bBezig = false;

var oNaam = null;
var oDiv = null;

(function() {
	var html = '<div id="winnaarDiv" style="margin:5px 0px 5px 0px;height:30px;font-size:18px;overflow:hidden;display:none;padding:15px;border:1px solid #999999;background:#FFFFCC;color:#333333;">';
	document.write(html + '<span id="spanNaam" style="color:#FFFFCC">' + (strNaam = arrNamen[Math.floor(Math.random() * arrNamen.length)]) + '<\/span><\/div>');
})();

function Start() {
	if(bBezig) {
		bCancel = true;
	} else {
		oDiv = document.getElementById('winnaarDiv');
		oNaam = document.getElementById('spanNaam');
		if(oDiv != null && oNaam != null) {
			oDiv.style.display = '';
			bCancel = false;
			bBezig = true;
			
			oNaam.style.position = 'absolute';
			oNaam.tx = oNaam.offsetLeft;
			oNaam.x = oNaam.tx + 350;
			setTimeout('Stap1();', 250);
		}
	}
}

function Reset() {
	oDiv.style.filter = oDiv.style.opacity = oDiv.style.textAlign = oDiv.style.fontWeight = '';
	oDiv.style.color = '#333333';
	oDiv.style.fontSize = '18px';
	oDiv.style.display = 'none';
	oDiv.style.height = '30px';
	oDiv.innerHTML = '<span id="spanNaam" style="color:#FFFFCC">' + (strNaam = arrNamen[Math.floor(Math.random() * arrNamen.length)]) + '<\/span>';
	bCancel = bBezig = false;
	oDiv = oNaam = null;
	intFontSize = 72;
	intOpacity = 100;
}

function Stap1() {
	if(!bCancel) {
		oNaam.style.color = '#333333';
		Animator1();
	} else {
		Reset();
	}
}

function Stap2() {
	if(!bCancel) {
		oDiv.innerHTML += ' ...?!?';
		setTimeout('Animator2();', 750);
	} else {
		Reset();
	}
}

function Stap3() {
	if(!bCancel) {
		oDiv.innerHTML = '';
		oDiv.style.fontSize = intFontSize.toString() + 'px';
		oDiv.style.textAlign = 'center';
		oDiv.style.color = '#FFFFCC';
		oDiv.innerHTML = strWinnaar + '&nbsp;&nbsp;&nbsp;';
		Animator3();
	} else {
		Reset();
	}
}

function Animator1() {
	if(!bCancel) {
		oNaam.x -= 5;
		if(oNaam.x <= oNaam.tx) {
			oNaam.style.left = oNaam.tx.toString() + 'px';
			oNaam.style.position = '';
			setTimeout('Stap2();', 250);
		} else {
			oNaam.style.left = oNaam.x.toString() + 'px';
			setTimeout('Animator1();', 50);
		}
	} else {
		Reset();
	}
}

function Animator2() {
	if(!bCancel) {
		oDiv.innerHTML = '<s style="color:#990000">' + strNaam + '<\/s> <b>...?!?<\/b>';
		setTimeout('Stap3();', 1250);
	} else {
		Reset();
	}
}


function Animator3() {
	if(!bCancel) {
		intFontSize -= 2;
		oDiv.style.fontSize = intFontSize.toString() + 'px';
		oDiv.style.fontWeight = 'bold';
		oDiv.style.color = '#333333';
		if(intFontSize > 24) {
			setTimeout('Animator3();', 50);
		} else {
			setTimeout('oDiv.innerHTML = oDiv.innerHTML.replace(/&.+$/g, "") + " !!";', 250);
			var color = '#000000';
			for(var time = 500, teller = 0; teller < 5; teller++, time += 250) {
				color = color == '#990000' ? '#333333' : '#990000';
				setTimeout('oDiv.style.color = "' + color + '";', time);
			}
			setTimeout('Fadeout();', time + 1250);
		}
	} else {
		Reset();
	}
}

function Fadeout() {
	intOpacity -= 10;
	oDiv.style.filter = 'alpha(opacity=' + intOpacity.toString() + ')';
	oDiv.style.opacity = (intOpacity / 100).toString();
	setTimeout((intOpacity == 0 ? 'Reset();' : 'Fadeout();'), 100);
}
