(function () {// when the DOM is ready...
	var ticker_i = 0;
	var tickerText = '';
	$(document).ready(function () {
	  // load the ticker 
	  if ($('#ticker-area ul').length)
		createTicker();

	}); 
	
	function createTicker(){
		// put all list elements within #ticker-area into array
		var tickerLIs = $("#ticker-area ul").children('li');

		tickerItems = new Array();
		tickerLIs.each(function(el) {
			tickerItems.push( jQuery(this).html() );
		});
		ticker_i = 0;
		$("#ticker-area").click (function () {
			if ($(tickerItems[ticker_i]).attr('href'))
			{
				location.href = $(tickerItems[ticker_i]).attr('href');
			}
		});
		rotateTicker();
	}
	
	function rotateTicker(){
		if( ticker_i == tickerItems.length ){
		  ticker_i = 0;
		}
		tickerText = tickerItems[ticker_i];
		c = 0;
		typetext();
		setTimeout( rotateTicker, 7000 ); 
		ticker_i++;
	}
	
	var isInTag = false;
	function typetext() {
		var thisChar = tickerText.substr(c, 1);
		if( thisChar == '<' ){ isInTag = true; }
		if( thisChar == '>' ){ isInTag = false; }
		$('#ticker-area').html("&nbsp;" + tickerText.substr(0, c++));
		if(c < tickerText.length+1)
			if( isInTag ){
				typetext();
			}else{
				setTimeout(typetext, 15);
			}
		else {
			c = 1;
			tickerText = "";
		}	
	}
})();