jQuery.noConflict();
var agendaAtual = 0;
var agendaInterval;

jQuery(document).ready(
	function(){
		cliqueAgenda();
		agendaInterval = window.setInterval(rotateAgenda, 5000);
	}
);

function cliqueAgenda(){

	jQuery(".compromisso .prev").click(function(e){
		e.preventDefault();

		var id = jQuery(this).parent().parent().attr('id');

		var idx = parseInt(id.replace(/[^0-9]/g, ''));
		var next = parseInt(idx + 1);
		
		if(next >= 5) next = 0;

		jQuery("#compromisso_"+idx).hide();
		jQuery("#compromisso_"+next).fadeIn();
		window.clearInterval(agendaInterval);
		agendaInterval = window.setInterval(rotateAgenda, 5000);

	});

	jQuery(".compromisso .next").click(function(e){
		e.preventDefault();

		var id = jQuery(this).parent().parent().attr('id');

		var idx = parseInt(id.replace(/[^0-9]/g, ''));
		var next = parseInt(idx - 1);

		if(next < 0) next = 4;

		jQuery("#compromisso_"+idx).hide();
		jQuery("#compromisso_"+next).fadeIn();
		window.clearInterval(agendaInterval);
		agendaInterval = window.setInterval(rotateAgenda, 5000);

	});
}

function rotateAgenda(){
	
	next = agendaAtual + 1;
	if(next >= 5) next = 0;

	jQuery("#compromisso_"+agendaAtual).hide();
	jQuery("#compromisso_"+next).fadeIn();

	agendaAtual++;
	
}


