incremento_foco = 0;
incremento_destaque = 0;
total = 0;

/* proxima mensagem */
function next_quentinhas() {
	var total = $('#navQuentinhas > li').length - 1;
	if(total > 0) {
		incremento_foco++;
		
		if(incremento_foco > total) {
			incremento_foco--;
			previous_quentinhas();
		}
		else {
			$('#navQuentinhas > li').hide();
			$("#navQuentinhas > li:eq("+incremento_foco+")").fadeIn('slow');
			setTimeout("next_quentinhas()", 2000);
		}
	}

}

/* mensagem anterior */
function previous_quentinhas() {
	incremento_foco--;
	
	if(incremento_foco < 0) {
		incremento_foco++;
		next_quentinhas();
	}
	else {
		$('#navQuentinhas > li').hide();
		$("#navQuentinhas > li:eq("+incremento_foco+")").fadeIn('slow');
		setTimeout("previous_quentinhas()", 2000);
	}
}

/* proxima imagem */
function next_destaque() {
	if(total > 0) {
		if(incremento_destaque >= total) {
			previous_destaque();
		}
		else {
			$('#proximo').trigger('click');
			foobar = setTimeout("next_destaque()", 5000);
		}
	}
}

/* imagem anterior */
function previous_destaque() {
	if(incremento_destaque <= 0) {
		next_destaque();
	}
	else {
		$('#voltar').trigger('click');
		foobar = setTimeout("previous_destaque()", 5000);
	}
}

$(document).ready(function() {

	/* navQuentinhas */
	$('#navQuentinhas > li:eq(0)').show();
	setTimeout("next_quentinhas()", 2000);

	total = Math.ceil($('#navDestaque > li').length / 4) - 1;

	if(total > 0) {
		$('#noticia_destaque_control').show();
		foobar = setTimeout("next_destaque()", 5000);
	}

	$('#proximo').click(function(){
		if(incremento_destaque < total) {
			$('#navDestaque').animate({'left': '-=937px'}, 'slow', 'easeInOutBack');
			clearTimeout(foobar);
			incremento_destaque++;
		}
	});
	
	$('#voltar').click(function(){
		if(incremento_destaque > 0) {
			$('#navDestaque').animate({'left': '+=937px'}, 'slow', 'easeInOutBack');
			clearTimeout(foobar);
			incremento_destaque--;
		}
	});

	$('#enquete_resultado').click(function(){
		$.ajax({
			type: "POST",
			url: "ajax_enquete_resultado.php",
			cache: false,
			beforeSend: function() {
				$('#enquete_container_alvo').html('');
				$('#enquete_loader').show();
			},
			success: function(data){
				$('#enquete_loader').hide();
				$('#enquete_container_alvo').html(data);
			},
			error: function(){
				alert('Ops!');
			}
		});
	});
	
	$('#enquete_votar').click(function(){
		
		var opcao_cod = 0;
		$('.enquete_opcoes').each(function(incremento, objeto) {
			if($(objeto).find('input[type=radio]').attr('checked') == true) {
				opcao_cod = $(objeto).find('input:checked').attr('value');
			}
		});

		if(opcao_cod == 0) {
			alert('Escolha uma opção para votar!');
			return false;
		}

		$.ajax({
			type: "POST",
			url: "ajax_enquete_voto.php",
			cache: false,
			data: {opcao_cod: opcao_cod},
			dataType: 'json',
			beforeSend: function() {
				$('#loader_votar').show();
			},
			success: function(data){
				$('#loader_votar').hide();
				$('#enquete_loader').hide();

				if(data.status == 'permitido') {
					$('#enquete_container_alvo').html(data.conteudo);
				}
				else {
					alert('Ops! Você ja votou!');
				}
			},
			error: function(){
				alert('Ops!');
			}
		});
	});
	
	$('#navVideos > li').hover(function(){
		$(this).find('span').stop().fadeTo('slow', .6);
		$(this).find('p').stop().fadeTo('slow', .6);
	}, function(){
		$(this).find('span').stop().fadeTo('slow', 0);
		$(this).find('p').stop().fadeTo('slow', 0);
	});
});

