/////////////////////
// Jeffrey Added scripts

showSlide = function(slidenum) {
	showPlay()
	clearTimeout(myTimer);
	for (var i = 0; i < slides.length; i++) {
      var slide = slides[(0 + i) % slides.length];
      slide.style.zIndex = slides.length - i;
    }
	slides[slidenum].style.zIndex = slides.length + 1
	current = slidenum
}

nextSlide = function(){
	showPlay()
	if (current < slides.length){
		current = current +1
	} else{
		current = 1
	}
	showSlide(current)
}

prevSlide = function(){
	showPlay()
	if (current > 1){
		current = current - 1
	} else{
		current = slides.length
	}
	showSlide(current)
}

startSlide = function(){
	clearTimeout(myTimer);
	new Slideshow('slideshow', 2000, current)
	showStop()
}


function showStop() { 
	//startSlide();

	if (document.getElementById) { // DOM3 = IE5, NS6 
		document.getElementById('playSlideshow').style.display = 'none';
		document.getElementById('stopSlideshow').style.display = 'block'; 
	} else { 
	if (document.layers) { // Netscape 4 
		document.playSlideshow.display = 'none'; 
		document.stopSlideshow.display = 'block'; 
	} else { // IE 4 
		document.all.playSlideshow.style.display = 'none';
		document.all.stopSlideshow.style.display = 'block'; 
		} 
	} 
}

function showPlay() {
	clearTimeout(myTimer);

	if (document.getElementById) { // DOM3 = IE5, NS6 
		document.getElementById('playSlideshow').style.display = 'block';
		document.getElementById('stopSlideshow').style.display = 'none';
	} else { 
	if (document.layers) { // Netscape 4 
		document.playSlideshow.visibility = 'block';
		document.stopSlideshow.visibility = 'none';
	} else { // IE 4
		document.all.playSlideshow.style.display = 'block';
		document.all.stopSlideshow.style.display = 'none';
		} 
	} 
}




//////////////////////////////////////////

/*Copyright (c) 2006 - R.W. van 't Veer*/

function Slideshow(slideshow, timeout, slidenum) {
  slides = [];
  var nl = $(slideshow).getElementsByTagName('div');
  for (var i = 0; i < nl.length; i++) {
    if (Element.hasClassName(nl[i], 'slide')) {
      slides.push(nl[i]);
    }
  }
  this.timeout = timeout;
  current = slidenum;
	/*
  for (var i = slidenum; i < slides.length; i++) {
    slides[i].style.zIndex = slides.length - i;
  }
  */
  
   for (var i = 0; i < slides.length; i++) {
      var slide = slides[(current + i) % slides.length];
      slide.style.zIndex = slides.length - i;
    }
 
  Element.show(slideshow);
  myTimer = setTimeout((function(){this.next();}).bind(this), this.timeout + 850);
}

Slideshow.prototype = {
  next: function() {
    for (var i = 0; i < slides.length; i++) {
      var slide = slides[(current + i) % slides.length];
      slide.style.zIndex = slides.length - i;
    }

    Effect.Fade(slides[current], {
      afterFinish: function(effect) {
        effect.element.style.zIndex = 0;
        Element.show(effect.element);
        Element.setOpacity(effect.element, 1);
      }
    });
    
    current = (current + 1) % slides.length;
    myTimer = setTimeout((function(){this.next();}).bind(this), this.timeout + 850);
  }
}
