// when the DOM is ready...
$(document).ready(function () {
  // load the ticker
	TickerDiaEspecial();
}); 

function TickerDiaEspecial(){
	// put all list elements within #ticker-area into array
	$("#dia_especial").show();
	var tickerLIs = $("#dia_especial ul").children();
	var cadena="";
	var cadena_lower="";
	var indice;
	tickerItems = new Array();
	tickerTextos = new Array();

	tickerLIs.each(function(el) {
		//Busco el titulo
		cadena=jQuery(this).html();
		cadena_lower=cadena.toLowerCase();
		indice=cadena_lower.indexOf("</div>"); 
		indice--;
		cadena_lower=cadena_lower.substr(1, indice);
		cadena=cadena.substr(1, indice);
		indice=cadena_lower.indexOf('titulo_notiweb');

		if(document.all) 
			indice=indice + 15;
		else
			indice=indice + 16;

		tickerTextos.push(cadena.substr(indice, cadena.length));
		//Fin de buscar el titulo
		tickerItems.push( jQuery(this).html() );
	});

	i = 0;

	//si hay Items entonces haga la rotacion
	if(tickerItems.length)
		rotateTicker();

}

function rotateTicker()
{
	if( i == tickerItems.length ){
	  i = 0;
	}

	tickerHTML = tickerItems[i];
	tickerText = tickerTextos[i];
	c = 0;
	$('#dia_especial').html(tickerHTML);
//	alert(tickerText)
	$('#dia_especial #noticia #hora').hide();
	typetext();
	setTimeout( "rotateTicker()", 7000 );
	i++;
}

function typetext() 
{
	$('#dia_especial #noticia #titulo_notiweb').html( tickerText.substr(0, c++) + "&nbsp;" );

	if( c < tickerText.length + 1 )
	{
		setTimeout( "typetext()", 40 );
	}
	else 
	{
		c = 1;
		tickerText = "";
		$('#dia_especial #noticia #hora').fadeIn();
	}
}
