var stopTicker = false;
var tickerText = ""

function restartTicker() {
	stopTicker = false;
	rotateTicker();
}

function rotateTicker(){
	if (tickerText == "")
  	tickerText = $('#code').html();
	c = 0;
	typetext();
}

var isInTag = false;
var isNewLine = false;

function typetext() {	
	if (! stopTicker) {
		// prende il primo carattere
		var thisChar = tickerText.substr(c, 1);
		// decide se è in un tag
		if( thisChar == '<' ){ isInTag = true; }
		if( thisChar == '>' ){ isInTag = false; }
		// Riempie l'html aggiungendo sempre un carattere
		$('#code').html("&nbsp;" + tickerText.substr(0, c++) + (c & 1 ? '_' : ''));
	
		// se non ha raggiunto la fine della riga ricorre
		if(c < tickerText.length+1)
			if( isInTag )
				typetext();
			else {
				var rand_no = 0
				rand_no = Math.ceil(100*Math.random())
				setTimeout("typetext()", 30+rand_no);
			}
		// altrimenti ricomincia uscendo e tornando alla funzione rotateTicker()
		else {
			$('#code').html("&nbsp;" + tickerText.substr(0, c));
			c = 1;
			tickerText = "";
		}
	} else {
		$('#code').html(tickerText);
	}
}

