function theRotator() 
{
    //Set the opacity of all images to 0
    $('#main-slideshow img').css({
        opacity: 0.0
    });
    //Get the first image and display it (gets set to full opacity)
    $('#main-slideshow img:first').css({
        opacity: 0.0
    })
    .addClass('show')
    .animate({
        opacity: 1.0
    }, 2500);
    $('#ribbon-content span:eq('+$('#main-slideshow img:first').index()+')').removeClass('slide-count').addClass('slide-count-active');
    //Call the rotator function to run the slideshow, 6000 = change to next image after 6 seconds
    rotateInterval = setInterval('rotate()',4500);
//$('.slide-img').fadeIn(1000);
}
function rotate() 
{

    //Get the first image
    var current = $('#main-slideshow img.show')? $('#main-slideshow img.show') : $('#main-slideshow img:first');
    var currIndex = current.index();
    //console.log('current',current.index());
    //Get next image, when it reaches the end, rotate it back to the first image
    var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('#main-slideshow img:first') :current.next()) : $('#main-slideshow img:first'));
    var nextIndex=next.index();
    var nextData = next.data('serie');
    if(window.console){
        console.log(nextData);
    }
    //console.log('next',next.index());
    //console.log($('#ribbon-content span').index(nextIndex));
    //Set the fade in effect for the next image, the show class has higher z-index
    next.css({
        opacity: 0.0
    })
    .addClass('show')
    .animate({
        opacity: 1.0
    }, 1000);
    //Hide the current image
    current.animate({
        opacity: 0.0
    }, 1000)
    .removeClass('show');
    /*$('.pblancobloc').fadeOut('fast', function(){
        $('this').empty().text(nextData).fadeIn('fast');
    });*/
    $('.pblancobloc').text(nextData);
    
    $('#ribbon-content span:eq('+nextIndex+')').removeClass('slide-count').addClass('slide-count-active');
    $('#ribbon-content span:eq('+currIndex+')').removeClass('slide-count-active').addClass('slide-count');
}

$(document).ready(function()
{
    //$('.tour-place').hide();
	$('#main-slideshow img').css("opacity","0");
    $('#ribbon-content').html('');
    var _slideCount = $('#main-slideshow img').length;
    //console.log ('longitud', _slideCount);
    for(var $_i=1; $_i<=_slideCount; $_i++)
    {
        $('#ribbon-content').append('<span class="slide-count">'+$_i+'</span>');
    }
    
    $('#ribbon-content span').css('cursor','pointer');
    $('#ribbon-content span').click(function(e){
        
        var idx =$(e.target).index();
        $('#main-slideshow img.show').removeClass('show').css({
            opacity: 0.0
        });
        rotateInterval =window.clearInterval(rotateInterval);
        $('#main-slideshow img:eq('+idx+')').addClass('show').css({
            opacity: 1.0
        });
        $('#ribbon-content span.slide-count-active').removeClass('slide-count-active').addClass('slide-count');
        $('#ribbon-content span:eq('+idx+')').removeClass('slide-count').addClass('slide-count-active');
        rotateInterval = setInterval('rotate()',4500);
    });
	
	$('#galeriasom a').fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	800, 
		'speedOut'		:	400, 
		'overlayShow'	:	false
	});
	
	$('#galeriapoble a').fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	800, 
		'speedOut'		:	400, 
		'overlayShow'	:	false
	});
    
});
$(window).load(function() {
    theRotator();
}); 



