// when the div is ready...
$('#tickerarea').ready(function () {
  // load the ticker
	//only call function if ticker is actually placed on page
  if ($("#tickerarea ul").children().length > 0){
    createTicker();
    $('#tickerarea').show();
  }
});

function createTicker(){
	// put all list elements within #ticker-area into array
	var tickerLIs = $("#tickerarea ul").children();
	tickerItems = new Array();
	tickerLIs.each(function(el) {
		tickerItems.push( jQuery(this).html() );
	});
	i = 0;
	rotateTicker();
}

function rotateTicker(){
  if ( i == tickerItems.length ) {
	  i = 0;
	}
  var thisSplit = tickerItems[i].split("|");
  tickerTime = thisSplit[1];
  atickerText = thisSplit[0]+thisSplit[2];
  atickerText = tickerItems[i];
	c = 0;
	atypetext();
	setTimeout( "rotateTicker()", 5000 );
	i++;
}

var isInTag = false;
function atypetext() {

	var thisChar = atickerText.substr(c, 1);
	if ( thisChar == '<' ){ isInTag = true; }
	if ( thisChar == '>' ){ isInTag = false; }
	$('#tickerarea').html(atickerText.substr(0, c++));
	if (c < atickerText.length+1)
		if ( isInTag ){
			atypetext();
		}else{
			setTimeout("atypetext()", 28);
		}
	else {
		c = 1;
		atickerText = "";
	}
}

