$(function () {

    function timeout () {
        var old = $('.animation > *.active');
        old.each(function() {
            var next = $(this).next();
            if (next.size() == 0)
                next = $(this).prevAll('*:first-child');
            $(this).fadeOut(500);
            next.fadeIn(500);
            $(this).removeClass('active');
            next.addClass('active');
        });
        setTimeout(function () {
            timeout();
        }, 5000);
    }

    $('.animation > *:not(.active)').css({
        display: 'block',
        zIndex: 1
    });

    $('.animation > *.active').css({
        display: 'block',
        zIndex: 2
    });

    setTimeout(function () {
        timeout();
    }, 5000);

    setTimeout(function () {
        $('.animation > *:not(.active)').css({
            display: 'none',
            zIndex: 2
        });
    }, 1000);

});
