jQuery.fn.flashNews = function (options) {
	// Define os parametros do plugin.
	var defaults = {
		// Tempo para troca.
		tempo: 3000,
		
		// Vlocidade da troca.
		velocidade: 'slow',
		
		// Classe da aba da notícia ativa.
		active: 'active'
	}
	$.extend(defaults, options);
	
	// Inicia escondendo todos os slides.
	$(this).children("div").hide();
	
	// Exibe o apenas o primeiro slide.
	var activeFlashNews = $(this).children("div:first");
	var activeCountNews = $(this).children("ul").children('li:first');
	activeCountNews.addClass(defaults.active);
	activeFlashNews.show();

	// Define como é a animação.
	function animarFlashNews (){
		activeFlashNews.animate({opacity: 1.0}, defaults.tempo, function () {
				 		activeFlashNews.fadeOut(defaults.velocidade, function () {
				 				// Obtem a próxima notícia cuidando do efeito circle.
								if ( $( activeFlashNews.next('div') ).html() != null) 
									activeFlashNews = $( activeFlashNews.next('div') );
								else 
									activeFlashNews = activeFlashNews.parent().children("div:first");
								
								activeFlashNews.fadeIn(defaults.velocidade, animarFlashNews);
								
								// Troca o contador ativo.
								activeCountNews.removeClass(defaults.active);
								if ( $( activeCountNews.next('li') ).html() != null )
									activeCountNews = activeCountNews.next('li');
								else
									activeCountNews = activeCountNews.parent().children("li:first");
								
								activeCountNews.addClass(defaults.active);
							}
						);
			}
		);
	}
	animarFlashNews();
	
	$(this).children("ul").children("li").children("a").bind("click", function (e){
		$(this).parent().parent().children('li.' + defaults.active).removeClass(defaults.active);
		$(this).parent('li').addClass(defaults.active);
		
		// Obtem qual a DIV deve ser exibida pelo href do link.
		// Obs.: as referencias nos links devem começar de 0.
		var ActivateFlashNews = $(this).attr("href");
		ActivateFlashNews = ActivateFlashNews.replace('#', '');
		
		// Para a animação e realiza a troca ativando a animação novamente.
		activeFlashNews.stop();
		activeFlashNews.fadeOut(defaults.velocidade, function () {
			activeFlashNews = $(this).parent().children("div:eq(" + ActivateFlashNews + ")");
			activeFlashNews.fadeIn(defaults.velocidade, animarFlashNews);
		});
		
		return false;
	});
	
}
