var text = "content of text here";
var delay = 50;
var startPos = 0;
var currentChar = 0;
var destination = "[not defined]";
var cursor = "_";
var blink = false;
var in_tag = 0;
var in_amp = 0;
var curPos = 0;

function type() {
 if (document.getElementById) {
  var dest = document.getElementById(destination);
  if (text.substr(currentChar, 1) == '<' && !in_amp) {
   in_tag = currentChar;
  }
  if (text.substr(currentChar, 1) == '&' && !in_tag) {
   in_amp = currentChar;
  }
  if (in_tag && text.substr(currentChar, 1) == '>') {
   in_tag = 0;
  }
  if (in_amp && text.substr(currentChar, 1) == ';') {
   in_amp = 0;
  }
  if (dest) {
   if (in_tag) {
    curPos = in_tag;
   } else if (in_amp) {
    curPos = in_amp;
   } else {
    curPos = currentChar;
   }
   if (blink) {
    dest.innerHTML = text.substr(startPos, curPos-startPos) + cursor;
   } else {
    dest.innerHTML = text.substr(startPos, curPos-startPos);
   }
  }
  blink = !blink;
  if (currentChar>text.length) {
   startPos = 0;
   currentChar = 1;
   setTimeout("type()", 2000);
  } else if (text.substr(currentChar, 1) == '\n') {
   startPos = currentChar+1;
   setTimeout("type()", 3000);
  } else {
   if (in_tag || in_amp) {
    setTimeout("type()", 1);
   } else {
    setTimeout("type()", delay);
   }
  }
  currentChar++;
 }
}

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