$(document).ready(function () {
	$('#destacado_video').hover(
		function(){	$('a',this).stop().animate({opacity:'0'},{queue:false,duration:520});}, 
		function(){ $('a',this).stop().animate({opacity:'1'},{queue:false,duration:500});
	});	
});
	
function cambiaSlide() {
    var $activo = $('#calendario_cursos div.activo');
    if ( $activo.length == 0 ) $activo = $('#calendario_cursos div:last');

    var $siguiente =  $activo.next().length ? $activo.next() : $('#calendario_cursos div:first'),
    $sibs  = $activo.siblings(),
    numeroAzar = Math.floor(Math.random() * $sibs.length ),
    $siguiente  = $( $sibs[ numeroAzar ] );

    $activo.addClass('ultimo-activo');
    $siguiente.css({opacity: 0.0}).addClass('activo').animate({opacity: 1.0}, 1500, function() { $activo.removeClass('activo ultimo-activo'); });
}

$(function () {
    $('#ngg-webslice .ngg-widget').simpleSpy();
});

(function ($) {
    
$.fn.simpleSpy = function (limit, interval) {
    limit = limit || 8;
    interval = interval || 5000;
    
    return this.each(function () {
        var $list = $(this),
            items = [],
            currentItem = limit,
            total = 0,
            height = $list.find('> a:first').height();
        $list.find('> a').each(function () {
            items.push('<a>' + $(this).html() + '</a>');
        });
        total = items.length;
        $list.wrap('<div class="tweets-fz" />').parent().css({ height : height * limit/3 });
        $list.find('> a').filter(':gt(' + (limit - 1) + ')').remove();
        function spy() {
            var $insert = $(items[currentItem]).css({
                height : 0,
                opacity : 0,
                display : 'none'
            }).prependTo($list);
                        
            $list.find('> a:last').animate({ opacity : 0}, 1000, function () {
                $insert.animate({ height : height }, 1000).animate({ opacity : 1 }, 1000);
                    $(this).remove();
            });
            currentItem++;
            if (currentItem >= total) {
                currentItem = 0;
            }
            
            setTimeout(spy, interval)
        }
        
        spy();
    });
};
    
})(jQuery);

$(function() {
    setInterval( "cambiaSlide()", 10000 );
});
