$(function(){
    $('.schedule .event .photo').hide();

    var photos = [];
    var current_photo = false;
    var fadeSpeed = 400;
    var slideshowSpeed = 5000;
    var slideshowTimer = false;

    function showPhoto(id) {
        if (id != current_photo) {
            if (current_photo) {
                $('.photo', document.getElementById(current_photo)).fadeOut(fadeSpeed);
                current_photo = false;
            }
            $('.photo', document.getElementById(id)).fadeIn(fadeSpeed);
            current_photo = id;
        }
    }

    function nextPhoto() {
        for (var i=0, len=photos.length; i < len; i++) {
            if (photos[i] == current_photo && i < len-1) return photos[i+1];
        }
        return photos[0];
    }

    function showNextPhoto() {
        showPhoto(nextPhoto());
        slideshowTimer = setTimeout(showNextPhoto, slideshowSpeed);
    }

    function startSlideshow() {
        if (current_photo) slideshowTimer = setTimeout(showNextPhoto, slideshowSpeed);
        else showNextPhoto();
    }

    function stopSlideshow() {
        if (slideshowTimer) clearTimeout(slideshowTimer);
    }

    $('.schedule .event').each(function(){
        photos.push(this.id); 
        $(this).mouseover(function(){ stopSlideshow(); showPhoto(this.id); });
        $(this).mouseout(startSlideshow);
    });

    $('body').removeClass('no-script');
    startSlideshow();



    // Marquee

    $('#banner').smoothDivScroll({
        autoScroll: 'always',
        autoScrollSpeed: 1,
        autoScrollDirection: 'endlessloop' }).addClass('scrolling');

});
