// when the DOM is ready...
$(document).ready(function () {

	$("#ticker-area ul").hide();

  	// load the ticker
	setTimeout( "createTicker()", 4000 );

}); 

var iTickerCount = 0;
var iTickerChar = 0;
var tickerText = "";

function createTicker(){
	$("#ticker-area ul").show();

	// put all list elements within #ticker-area into array
	var tickerLIs = $("#ticker-area ul").children();
	tickerItems = new Array();
	tickerLIs.each(function(el) {
		tickerItems.push( jQuery(this).html() );
	});
	iTickerCount = 0;
	rotateTicker();
}

function rotateTicker(){
	if( iTickerCount == tickerItems.length ){
	  iTickerCount = 0;
	}
  	tickerText = tickerItems[iTickerCount];
	iTickerChar = 0;
	typetext();
	setTimeout( "rotateTicker()", 14000 );
	iTickerCount++;
}

var isInTag = false;
function typetext() {	
	var thisChar = tickerText.substr(iTickerChar, 1);
	if( thisChar == '<' ){ isInTag = true; }
	if( thisChar == '>' ){ isInTag = false; }
	$('#ticker-area').html(tickerText.substr(0, iTickerChar++) + "_");
	if(iTickerChar < tickerText.length+1)
		if( isInTag ){
			typetext();
		}else{
			setTimeout("typetext()", 50);
		}
	else {
		iTickerChar = 1;
		tickerText = "";
		var sTempStr = $('#ticker-area').html()
		$('#ticker-area').html(sTempStr.substr(0, sTempStr.length-1));
	}	
}

