$(function() {
		
	/*CYCLE*/
	
	/*Sobreescribe funcion updateActivePagerLink para aņadir clase 'current' */
	$.fn.cycle.updateActivePagerLink = function(pager, currSlideIndex) { 
    	$(pager).find('li').removeClass('current') 
        	.filter('li:eq('+currSlideIndex+')').addClass('current');
	}; 
	
	
	/*Inicia cycle para rotator*/
	$('.caption').hide();
	var clicked_th = null;
	var clicked = false;
	
	$('#rotate').cycle({ 
		fx:     'fade',
		pager:  '#thumbs',   
		timeout: 7000,
		after: onAfter,
		before: onBefore,
		// callback fn that creates a thumbnail to use as pager anchor 
		pagerAnchorBuilder: function(idx, slide) { 		
		   return '#thumbs li:eq(' + idx + ') a'; 
		} 
	});
	
	function onBefore(currSlideElement) {
		
		$('#thumbs a').click(function(){
			clicked_th = $(this).attr('href').slice(1);		
			clicked = true;
		});
		 
    	var current_slide = currSlideElement.id;
		
		if(current_slide == clicked_th && clicked == true){					
			//don't hide caption
		} else {
			$('.caption').slideUp();
			clicked_th = null;
			clicked = false;
		}
		 
	}
	
	function onAfter() { 	
    	 $('.caption').slideDown();
	}	

	/*TABS*/
	
	/*Inicia tabs panel derecho*/
	$("#side-tabs").tinytabs();
	
});