var STARTED_SHOWING_TEXT = false;

function showText(text) {
	document.getElementById('text').firstChild.nodeValue= '[' + text + ']';
	// stop onload showing of text when there is mouse over or mouse out event
	STARTED_SHOWING_TEXT = true;
}

function bodyOnLoad(text) {
	// create initial node
	document.getElementById('text').appendChild(document.createTextNode('\u00A0'));
	
	var nextTimer = blinkCursor(2, 500, 300);

	nextTimer = spellWord("\u00A0" + text, nextTimer, 100);
	nextTimer = blinkCursor(5, nextTimer, 300, "\u00A0" + text);
	
	setTimeout("onLoadShowText('[" + text + "]')", nextTimer + 500);

}

// blinks cursor starting at currentTimer, numTimes number of times with
// delay interval and optional static text prefix
function blinkCursor(numTimes, currentTimer, delay, prefix) {
	var timer = currentTimer;
	
	if(!prefix){
		prefix = "";
	}
	
	for(i = 0; i < numTimes; i++){
		var val = "onLoadShowText('" + prefix + "_')";
		setTimeout(val, timer);
		timer += delay;
		val = "onLoadShowText('" + prefix + "\u00A0')";
		setTimeout(val, timer);
		timer += delay;
	}
	
	return timer;
}

// displays characters of a word starting at currentTimer with delay interval between characters
function spellWord(word, currentTimer, delay) {
	timer = currentTimer;
	
	for(i = 0; i <= word.length; i++){
		var val = "onLoadShowText('" + word.substring(0, i) + "_')";
		setTimeout(val, timer);
		timer += delay;
	}
	
	return timer;
}

// shows the text unless the there was mouse over or mouse out event
function onLoadShowText(text){
	if(!STARTED_SHOWING_TEXT){
		document.getElementById('text').firstChild.nodeValue = text;
	}	
}
