// Constantes de ordenação.
var POR_ORDEM_ALFABETICA = 0;
var POR_AREA_TEMATICA = 1;
var POR_AREA_GEOGRAFICA = 2;

jQuery.fn.extend({
	// Aplica efeito de zebra nas linhas de uma tabela.
	zebra: function() {
		var i = 0;
		this.each(function() {
			if ((i % 2) == 0) {
				$(this).addClass('zebraIn');
			} else {
				$(this).addClass('zebraOut');
			}
			i++;
		});
		return this;
	},
	// Preenche um campo de texto com uma dica.
	textTip: function(tip) {
		this.val(tip);
		this.click(function() {
			$(this).val('');
		}).blur(function() {
			if ($(this).val() == '') $(this).val(tip);
		});
		return this;
	}
});

$(function(){
	// Inicializa o newsticker.
	$('ul#news_lista').liScroll({travelocity: 0.03});
	// Inicializa o relógio.
	getHora();
	setInterval(getHora, 1000);
	// Inicializa o textTip do campo de busca.
	$('input#input_busca').textTip('Pesquisar por...');
});

// Recupera o horário atual em horas e minutos.
function getHora() {
	var date = new Date();
	var hora = date.getHours();
	var minuto = date.getMinutes();
	if (hora < 10) hora = '0' + hora;
	if (minuto < 10) minuto = '0' + minuto;
	$('#relogio a').html(hora + ':' + minuto);
}

// Recuperar e ordenar os projetos
function getProjetos(order) {
	$.getJSON('../action/processa_projetos.php', {order: order}, function(data) {
		var tr = '';
		$.each(data, function(i, projeto) {
			var classe = 'zebraOut';
			if ((i % 2 == 0)) classe = 'zebraIn';
			tr += '<tr class="'+ classe +'">';
			tr += '<td class="td_projeto"><a href="viewDoaProj01.php?cod='+ projeto.cod_projeto +'">' + projeto.nome + '</a>';
			tr += '<p>' + projeto.organizacao + '</p>';
			tr += '</td>';
			tr += '<td class="td_localizacao">' + projeto.cidade + '</td>';
			tr += '<td class="td_tema">' + projeto.tematica + '</td>';
			tr += '<td class="td_ai">' + projeto.acoes_iniciais + '</td>';
			tr += '<td class="td_ad">' + projeto.acoes_disponiveis + '</td>';
			tr += '<td class="td_botao"><a href="viewDoaProj01.php?cod='+ projeto.cod_projeto +'"><img src="../images/tabela_btn_invista.png" alt="" /></a></td>';
			tr += '</tr>';
		});
		$('#projetos_dados #dados table').html(tr);
	});
}