var decode = new Array();
var newText;
var delay = 50;
var currentChar = 1;
var destination;
var text = "Lorem ipsum dolor sit <strong>amet, consectetur</strong> adipiscing elit.";
var p; // this is for the letter timer
var tt = new Array();

function resetTimer() {
	tt = new Array();
}

function clearTimers() {
	for (var i= 0;i < tt.length; i++) {
		clearTimeout(tt[i]);
	}
	resetTimeouts();
}

function rstring(string_length) {
	//var chars = "0123456789ABCDEFGHIKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
	//var chars = "ABCDEFGHIKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
	var chars = "-[]_:=*%$#.:,\|/@!{}^+";
	var randomstring = "";
	for (var i = 0; i < string_length; i++) {
		var rchar = Math.floor(Math.random() * chars.length);
		randomstring += chars.substring(rchar,rchar+1);
	}
	return randomstring;
}

function type()
{  
	var dest = $(destination);
	var result;
	if (dest)
	{
		
		if(currentChar < (text.length / 4)) {
			dest.html(text.substr(0, currentChar) + rstring(8) );
		}
		else if(currentChar < (text.length / 3)) {
			dest.html(text.substr(0, currentChar) + rstring(6) );
		}
		else if(currentChar < (text.length / 2)) {
			dest.html(text.substr(0, currentChar) + rstring(4) );
		}
		else {
			dest.html(text.substr(0, currentChar) + rstring(2) );
		}
		currentChar++
		
		if (currentChar > text.length) {
			dest.html(text);
			currentChar = 1;
			clearTimers();
		}
		else {
			tt.push(setTimeout("type()", delay));
		}
	}
}

function startTyping(textParam, delayParam, destinationParam)
{
	text = textParam;
	delay = delayParam;
	currentChar = 1;
	destination = destinationParam;
	type();
}
