	$(document).ready(function() {
	
	//rotation speed and timer
		var speed = 9999;
		var run = setInterval('rotate()', speed);	
		var stop = clearInterval('rotate()', speed);
		
		//grab the width and calculate left value
		var item_width = $('#agenda').outerWidth(); 
		var left_value = item_width * (-1); 
			
		//move the last item before first item, just in case user click prev button
		var contUf = 0;
		$(".estadoUf").each(function () {
				contUf++;
		})
		
		if(contUf > 1){
				$('.estadoUf:first, .estadoUf2:first').before($('.estadoUf:last, .estadoUf2:last'));		
		}
		
		//set the default item to the correct position 
		$('#agenda').css({'left' : left_value});
		
		
		jQuery('#prev1').click(function() {
				if(contUf > 1){
				jQuery('#agenda').fadeOut('slow', function() {
					//move the last item and put it as first item
					jQuery('.estadoUf:first, .estadoUf2:first').before(jQuery('.estadoUf:last, .estadoUf2:last'));
					jQuery('#agenda').fadeIn('slow');
					setButtonText();
		
				});
		
			
					
				}
				//cancel the link behavior
			return false;
		}); 
		
		//if user clicked on next button
		jQuery('#next1').click(function() {
				if(contUf > 1){
				jQuery('#agenda').fadeOut('slow', function() {
					//move the last item and put it as first item
					jQuery('.estadoUf:last, .estadoUf2:last').after(jQuery('.estadoUf:first, .estadoUf2:first'));
					jQuery('#agenda').fadeIn('slow');
					setButtonText();
					
			});
				}
		
			//cancel the link behavior
			return false; 
		
		});     
	
	 
	});  
	
	
	function rotate() {
		jQuery('#next1').click();
	}
	
	function stop() {
		jQuery('#next1').click(stop);
	}
	
	function setButtonText()
	{
		jQuery('#prev1').attr('title',jQuery('.estadoUf:last .title').html());
		jQuery('#next1').attr('title',jQuery('.estadoUf:nth-child(2) .title').html());
	}
	

