$(document).ready(function () {
    if ($('#slideshow').length) {
        interval = setInterval(slideshow, 3500);
    }
    if ($('#gallery').length) {
        $('#gallery').twirlie();
    }
});

function slideshow() {
    var $active = $('#slideshow IMG.active');
    if ($active.length == 0) {
        $active = $('#slideshow IMG:last');
    }
    if ($active.next().length) {
        $next = $active.next();
        $active.addClass('last-active');
        $next.css({
            opacity: 0.0
        }).addClass('active').animate({
            opacity: 1.0
        }, 700, function () {
            $active.removeClass('active last-active');
        });
    } else {
        clearInterval(interval);
    }
}
