$(document).ready(function() {
    var stack = [];

    // preload images into an array
    for (var i = 3; i < 51; i++) {
        var img = new Image(703,315);
        img.src = '../img/serenissima_' + i + '.jpg';
        $(img).bind('load', function() {
            stack.push(this);
        });
    }

    $('.cert').fancybox();
    $('.slideshow').cycle({
        fx: 'fade',
    //	timeout:  2000,
        before: onBefore
    });

    // add images to slideshow
    function onBefore(curr, next, opts) {
        if (opts.addSlide) // <-- important!
            while(stack.length)
                opts.addSlide(stack.pop());
    };
});
