/*******

	***	NewsTicker by Charles Cavalcante ***
	*** http://www.mediagroup.com.br     ***
	
*****/
		
function NewsTicker(nome)
{
	this.atual = this.primeira = this.novo = this.ultima = $("#noticia-item:first", $("#" + nome + " div"));
	
	while(this.ultima.next().html())
	{
		this.ultima = this.ultima.next();
	}
	
	this.delay = 5000;
	this.timeout = null;
	this.locked = true;
	this.anima();
}

NewsTicker.prototype.anima = function(novo)
{ 
	var caller = this;
	
	if(!novo)
	{
		this.atual.animate({ top: "5px" }, 300, function(){ caller.locked = false; });
	}
	else
	{
		caller.locked = true;
		// desce atual
		this.atual.animate
		(
			{ top: "80px" }, // acao
			300, // tempo
			"linear", // tipo de animação
			function() // callback
			{
				// sobe a proxima
				novo.animate({ top: "5px" }, 300, function(){ caller.locked = false; });
			}
		);
		this.atual = novo;
	}
};

NewsTicker.prototype.proxima = function() 
{ 
	if(!this.locked)
	{
		if(this.novo.is(":last-child")) this.novo = this.primeira;
		else this.novo = this.atual.next();

		this.anima(this.novo);
	}
};

NewsTicker.prototype.anterior = function()
{
	if(!this.locked)
	{
		if(this.novo.is(":first-child")) this.novo = this.ultima;
		else this.novo = this.atual.prev();
	
		if(this.novo.attr("id")=="noticia-item") this.anima(this.novo);
		else this.anterior();
	}
};
