current = 0;
loaded = [];

rotate = function() {
    if ($top.css("opacity") == "1") {
        if (loaded[(current + 1) % images.length]) {
            current = ++current % images.length;
            $("img#bottom").attr("src", $top.attr("src"));
            $top.stop();
            $top.css({opacity:0}).attr("src", '/images/slides/'+images[current])
                .animate({opacity:1}, 1200);
        }
    }
}
preload = function() {
    if (document.images) {
        img  = new Image(730,355);
        loaded[(current + 1) % images.length] = false;
        $(img).load(function() {
            loaded[(current + 1) % images.length] = true;
        });
        img.src = '/images/slides/'+images[(current + 1) % images.length];
    }
    if (current+1 == images.length) {
        window.clearInterval(preloadId);
    }
}

$(document).ready(function() {
    $top = $("#top");
    window.setInterval(rotate, 3500)
    window.setTimeout(function() {
        preload();
        preloadId = window.setInterval(preload, 3000);
    }, 500)
});
