var text="";
var delay=50;
var currentChar=1;
var destination="[not defined]";

function type()
{
  if (document.getElementById)
  {
    var dest=document.getElementById(destination);
    if (dest)// && dest.innerHTML)
    {
    	if(text.substring(currentChar,currentChar+4)=="<br>")
    	{
    		currentChar = currentChar+4;
    	}
      dest.innerHTML=text.substr(0, currentChar);
      //dest.innerHTML+=text[currentChar-1];
      currentChar = currentChar+2;
      if (currentChar>text.length)
      {
        //currentChar=1;
        //setTimeout("type()", 5000);
      }
      else
      {
        setTimeout("type()", delay);
      }
    }
  }
}

function startTyping(textParam, delayParam, destinationParam)
{
  text=textParam;
  temptext = text;
  var i=0;
  var check = 35;
  var last = 0;
  var lines = 0;
  while(i<text.length)
  {
  	temptext = text.substring(0,i)
  	if(temptext.lastIndexOf(" ") > check)
  	{
  		text = text.substring(0,last) + "<br>" + text.substring(last+1,text.length);
  		lines ++;
  		check = check + 35;
  	}
  	
  	last = temptext.lastIndexOf(" ");
  	
  	i++;
  } 
  
  delay=delayParam;
  currentChar=1;
  destination=destinationParam;
  type();
}