var typeWindow = null;
var message = '';

var startDelay = 1;
var titleArr=Array();
var hrefArr=Array();
var currentHref='#';
var current =0;

function initTypewriter(titleText, hrefText, newSpeed)
{
typeWindow = document.getElementById('typeWindow');
typeWindow.href=hrefText;
currentHref=hrefText;
typeWindow.innerHTML = '';
message = titleText;
msgLength = message.length;
count = 0;
typing = setInterval('typeText();',  newSpeed);
}
function clickType() {
  document.location=currentHref;
}
function nextText() {
 current++;
 if (titleArr.length==current) {
  current=0;
 }
 setTimeout('initTypewriter("' + titleArr[current] + '", "' + hrefArr[current] + '", 120);', startDelay * 1000);
}


function typeText() {
  needprint = 1;

  if (count == msgLength) {
	clearInterval(typing);
	setTimeout('nextText()', 2000);
	return;
  }

  cursorChar = message.charAt(count);

  if (/&/.test(cursorChar)) {
	
	var amp = message.substring(count).match(/\&[^;]+;/);

	if (amp) {
	  typeWindow.innerHTML += amp[0];
	  count += amp[0].length;
	  needprint = 0;
	}
  }
  
  if (needprint==1) {
	typeWindow.innerHTML += cursorChar;
	count++;

  }

}

