
var slideshowRunning = false;
var slideshowButton = startSlideshowButton;
var slideshowSeconds = 8;
var startSlideshowButton = 'images/play.gif';
var pauseSlideshowButton = 'images/pause.gif';

function initSlideShow() {

  $('slideshowphoto').src = slideshowImages[currentIndex];

  // slideshow
  var slideshowSlider = new Control.Slider('handle2', 'track2', {
    onSlide: function(v) { void(0); },
	axis: 'horizontal',
	range: $R(5, 60),
	values: [5, 8, 10, 15, 30, 45, 60],
	sliderValue: slideshowSeconds,
	onChange: function(v) { slideshowSeconds = v; $('secs').innerHTML=v + 'sec';}
    });

  startSlideshow();
  if (currentIndex + 1 < numberImages)
    $('preload').src = slideshowImages[currentIndex + 1];
}

function prevPhoto() {
  stopSlideshow();

  if (currentIndex-- <= 0) currentIndex = numberImages;

  new Effect.Opacity('slideshowphoto', { from: 1.0, to: 0.0, duration: 1.0,
	afterFinish: function(){
	$('slideshowphoto').src = slideshowImages[currentIndex];
	new Effect.Opacity('slideshowphoto', { from: 0.0, to: 1.0, duration: 1.0, queue: 'end' }); }});

}

function nextPhoto() {
  stopSlideshow();

  transition();
}

function transition() {
  if (currentIndex++ >= numberImages) currentIndex = 0;

  new Effect.Opacity('slideshowphoto', { from: 1.0, to: 0.0, duration: 1.0,
	afterFinish: function(){
	$('slideshowphoto').src = slideshowImages[currentIndex];
	new Effect.Opacity('slideshowphoto', { from: 0.0, to: 1.0, duration: 1.0, queue: 'end' }); }});

  // preload the image
  if (currentIndex + 1 < numberImages) 
    $('preload').src = slideshowImages[currentIndex + 1];
}

function stopSlideshow() {
  slideshowRunning = false;
  $('slideshow').src = startSlideshowButton;
  slideshowButton = startSlideshowButton;
}

function startSlideshow() {
  if (slideshowRunning) {
    slideshowRunning = false;
    $('slideshow').src = startSlideshowButton;
    slideshowButton = startSlideshowButton;
  }
  else {
    slideshowRunning = true;
    $('slideshow').src = pauseSlideshowButton;
    slideshowButton = pauseSlideshowButton;
    setTimeout('slideshowTick()',slideshowSeconds * 1000);
  }
}

function slideshowTick() {
  if (slideshowRunning) {
    transition();
    setTimeout('slideshowTick()',slideshowSeconds * 1000);
  }
}

