jQuery.fn.extend({
	changeColor: function(toggle) {
		if (toggle) {
			this.css({
				backgroundColor: '#FFF',
				color: '#93A5D3',
				borderColor: '#BCC7E4'
			});
		} else {
			this.css({
				backgroundColor: '#93A5D3',
				color: '#FFF',
				borderColor: '#BCC7E4'
			});
		}
		return this;
	}
});

// Guarda os id's das matérias do Box de Destaques
var articles = new Array();
var interval = '';
var i = 0;
var stop = false;
var ultimo = null;

function carregar(id, clicked) {
	if (clicked) stop = true;
	$.ajax({
		url: 'conteudo.php3',
		type: 'get',
		data: "id_article="+id,
		global: false,
		beforeSend: function() {
			$('img#carregador').show();
		},
		success: function(data) {
			$('img#carregador').hide();
			$('#conteudo_destaque').html(data);
		}
	});
	if (articles.length > 1) {
		if (ultimo == null) {
			ultimo = $('#'+id);
			ultimo.changeColor(true);
		} else {
			if (ultimo.attr('id') != id) {
				$('#'+id).changeColor(true);
				ultimo.changeColor(false);
				ultimo = $('#'+id);
			}
		}
	}
}

function carrosel() {
	if (!stop) {
		if (i >= articles.length) i = 0;
		carregar(articles[i], false);
		i++;
	}
	else clearInterval(interval);
}

/**
 * Adiciona o ID de uma matéria destaque ao Array de ID's.
 * id -> ID da matéria.
 */
function addId(id) {
	articles.push(id);
}