window.addEvent('domready', function() {

  if ($defined('flash_images') && flash_images.length > 1) {
    // This stolen from davidwalsh.name
    /* Pre load */
    var image_holder      = $('flash-image_holder');
    var progressTemplate  = 'Loading image {x} of '+flash_images.length;
    var updateProgress    = function(num) {
      progress.set('text', progressTemplate.replace('{x}', num));
    } // end updateProgress
    var progress          = $('flash-progress');
    updateProgress('text','0');

    var loader  = new Asset.images(flash_images, {
      onProgress: function(c, index) {
        updateProgress('text', index+1);
      }, // end onProgress
      onComplete: function() {
        var slides  = [];
        // Put images into page
        flash_images.each(function(im) {
          slides.push(new Element('img', {
            src:  im,
            alt:  'Les Sorbiers image',
            styles: {
              opacity:  0
            }
          }).inject(image_holder)); // end slides.push

        }); // end loop flash_images
        var showInterval  = 5000;
        var index         = 1;
        progress.set('text', 'Images loaded');
        (function() {
          slides[index].tween('opacity', 1);
        }).delay(1000);
        var start = function() {
          (function() {
            $('flash-image_noscript').fade(0);
            slides[index].fade(0);
            ++index;
            if (!slides[index]) {
              index = 0;
            }
            slides[index].fade(1);
          }).periodical(showInterval);
        };

        start();
      } // end onComplete
    }); // end loader
  } // end if flash images
});