  function startSlideshow() {

    if($('slideshow')) {

        $('slideshow').PE =
        new PeriodicalExecuter(function () {
            var index = $('slideshow').getAttribute('current_index') || 0;
            var images = $$('#slideshow img');
            var nextIndex = ((1+parseInt(index)) >= images.length) ? 0 : (1+ parseInt(index));

            $('slideshow').setAttribute('current_index', nextIndex);

            new Effect.Parallel([
              new Effect.Fade(images[index], {sync:true,transition:Effect.Transitions.linear}),
              new Effect.Appear(images[nextIndex], {sync:true,transition:Effect.Transitions.linear})
            ], { duration:1, beforeStart : function(obj) {
                    if($('caption')) $('caption').innerHTML = images[nextIndex].alt.replace("|","<br/>");

                }});
          }, 5);

      }
  }

  function slideshowNext() {

    if($('slideshow') && $('slideshow').PE) {

        $('slideshow').PE.stop();

        var index = $('slideshow').getAttribute('current_index') || 0;
        var images = $$('#slideshow img');
        var nextIndex = ((1+parseInt(index)) >= images.length) ? 0 : (1+ parseInt(index));

        $('slideshow').setAttribute('current_index', nextIndex);

        new Effect.Parallel([
          new Effect.Fade(images[index], {sync:true,transition:Effect.Transitions.linear}),
          new Effect.Appear(images[nextIndex], {sync:true,transition:Effect.Transitions.linear})
        ], { duration:1, beforeStart : function(obj) {
                if($('caption')) $('caption').innerHTML = images[nextIndex].alt.replace("|","<br/>");

            }});

    }
    return false;
  }

  function slideshowPrev() {

    if($('slideshow') && $('slideshow').PE) {

        $('slideshow').PE.stop();

        var index = $('slideshow').getAttribute('current_index') || 0;
        var images = $$('#slideshow img');
        var prevIndex = ((parseInt(index)-1) >= 0 ) ? (parseInt(index)-1) : (images.length-1);

        $('slideshow').setAttribute('current_index', prevIndex);

        new Effect.Parallel([
          new Effect.Fade(images[index], {sync:true,transition:Effect.Transitions.linear}),
          new Effect.Appear(images[prevIndex], {sync:true,transition:Effect.Transitions.linear})
        ], { duration:1, beforeStart : function(obj) {
                if($('caption')) $('caption').innerHTML = images[prevIndex].alt.replace("|","<br/>");

            }});

    }
    return false;
  }
