// constants
var MINIMUM_PAUSE = 25;
var MAX_VARIABLE_PAUSE = 100;

// globals
var text = "";
var turboControl = '\
	<table width="100%">\
	<tr><td></td>\
	<td id="turbo" align="right">\
	  [<a href="#turbo" name="turbo" onClick="turbo();"><blink>&dArr;</blink></a>]\
	</td></tr>\
</table>\
';

var typedDiv = '<div id="typed"></div>';

var characterCount = 0;
var turboOn = "false";

function storeText() {
	text = document.body.innerHTML;
	document.body.innerHTML = turboControl + typedDiv;
}

function type() {
	// stop when completely typed
	if (characterCount > text.length) {
		return;
	}
	
	// skip past tags
	if (text[characterCount] == '<') {
		while (text[characterCount] != '>' && characterCount <= text.length) {
			characterCount++;
		}
	}

	// stop when completely typed
	if (characterCount > text.length) {
		return;
	}

	// get all text typed so far
	newValue = text.substring(0, characterCount);
	characterCount++;

	if (characterCount < text.length) {
		document.getElementById("typed").innerHTML = newValue;
	}
	else {
		document.body.innerHTML = newValue;
	}
	
	// random delay
	timeout = Math.floor(MINIMUM_PAUSE + Math.random() * MAX_VARIABLE_PAUSE);
	setTimeout("type()", timeout);
}

function turbo() {
	characterCount = text.length;
	turboControl = "";
}

function main() {
	storeText(); 
	type();
}