/**
 * @author David Walsh
 * @see http://davidwalsh.name/mootools-slideshow
 */
window.addEvent('domready', function() {

    if ($('slideshow-container')) {

        var showDuration = 5000;
        var container = $('slideshow-container');
        var images = container.getElements('img');
        var currentIndex = 0;
        var interval;

        // opacity and fade
        images.each(function(img, i){
            if (i > 0) {
                img.set('opacity', 0);
            }
        });

        function show() {
            images[currentIndex].fade('out');
            currentIndex = currentIndex < images.length - 1
                         ? currentIndex + 1
                         : 0;
            images[currentIndex].fade('in');
        };

        // start once the page is finished loading
        window.addEvent('load', function() {
            interval = show.periodical(showDuration);
        });
    }
});

