/*
 * slideshow.js
 * PachamamaFarm.com
 * 
 * Contains list of image urls to be shown in slideshow.  Requires slideList.js.
 * 
 * Steve Clason, steve@steveclason.com
 * 
 * REVISIONS
 * 26 Feb 07, create date.
*/

// Don't change anything outside of the area indicated!

/*
This list is all that needs to change in order to add or delete slides, or to 
change their order in the slideshow.  The slides will appear in the order 
listed.
*/
var slideList = new Array(
  "01PachamamaFarm.jpg",
  "02PachamamaFarm.jpg",
  "03PachamamaFarm.jpg",
  "04PachamamaFarm.jpg",
  "04GPachamamaFarm.jpg",
  "05PachamamaFarm.jpg",
  "06PachamamaFarm.jpg",
  "07PachamamaFarm.jpg",
  "08PachamamaFarm.jpg",
  "09PachamamaFarm.jpg",
  "10PachamamaFarm.jpg",
  "11PachamamaFarm.jpg",
  "12PachamamaFarm.jpg",
  "13PachamamaFarm.jpg",
  "14PachamamaFarm.jpg",
  "15PachamamaFarm.jpg",
  "16PachamamaFarm.jpg",
  "17PachamamaFarm.jpg",
  "18PachamamaFarm.jpg",
  "19PachamamaFarm.jpg",
  "20PachamamaFarm.jpg",
  "21PachamamaFarm.jpg",
  "22PachamamaFarm.jpg",
  "23PachamamaFarm.jpg",
  "24PachamamaFarm.jpg",
  "25PachamamaFarm.jpg",
  "26PachamamaFarm.jpg",
  "27PachamamaFarm.jpg",
  "28PachamamaFarm.jpg",
  "29PachamamaFarm.jpg",
  "30PachamamaFarm.jpg",
  "31PachamamaFarm.jpg",
  "32PachamamaFarm.jpg",
  "33PachamamaFarm.jpg",
  "34PachamamaFarm.jpg",
  "35PachamamaFarm.jpg",
  "36PachamamaFarm.jpg"
  );
/*
 * DON"T CHANGE ANYTHING BELOW THIS UNLESS YOU KNOW WHAT YOU'RE DOING.
*/


// Checks to see if there is a div id="slideShow", if so loads the necessary
// JavaScript.

initialize = function(){
  if (document.getElementById('slideshow')) {
    var div = document.getElementById('slideshow');
    slideshow(slideList);
  }
}

slideshow = function(slideList){
  var currentSlide = 0;
  function Slide(){
    var element = document.createElement('img');
    element.src = "/slideshow/images/" + slideList[i];
    element.id = "slide" + i;
    // element.style.position = 'absolute';
    if (i == 0) {
      element.style.position = 'static';
      element.style.left = '0px';
    }
    else {
      element.style.position = 'absolute';
      element.style.left = '-9999px';
    }
    document.getElementById('slideshow').appendChild(element); 
  }

  function nextSlide() {
    document.getElementById("slide" + currentSlide).style.position = 'absolute';
    document.getElementById("slide" + currentSlide).style.left = '-9999px';
    document.getElementById("slide" + (currentSlide + 1)).style.position = 'static';
    document.getElementById("slide" + (currentSlide + 1)).style.left = '0px';
    currentSlide++;
    testCounter();
  }
  
  function prevSlide() {
    document.getElementById("slide" + currentSlide).style.position = 'absolute';
    document.getElementById("slide" + currentSlide).style.left = '-9999px';
    document.getElementById("slide" + (currentSlide - 1)).style.position = 'static';
    document.getElementById("slide" + (currentSlide - 1)).style.left = '0px';
    currentSlide--;
    testCounter(); 
  }
  
  function testCounter() {
    if (currentSlide < 1) {
      currentSlide = 0;
      document.getElementById('prevButton').style.display = 'none';
    } else if (currentSlide >= slideList.length-1){
      currentSlide = slideList.length-1;
      document.getElementById('nextButton').style.display = 'none';
    } else {
      document.getElementById('nextButton').style.display = '';
      document.getElementById('prevButton').style.display = '';
    }
  }
  function makeControls(){
    // Create the control panel.
    
    // Holds background only so we can mess with opacity.
    var slideControlBackground = document.createElement('div');
    slideControlBackground.id = 'slideControlBackground';
    
    var slideControl = document.createElement('div');
    slideControl.id = 'slideControl';
    // Make the buttons.
    nextButton = document.createElement('a');
    // IE doesn't support addEventListener.
    if (nextButton.addEventListener) {
      nextButton.addEventListener('click', nextSlide, false);
    } else if (nextButton.attachEvent) {
      nextButton.attachEvent('onclick', nextSlide);
    } else {
      nextButton.onclick = nextSlide();
    }
    nextButton.id = 'nextButton';
    nextButton.innerHTML = '&raquo;';
    nextButton.style.cursor = 'hand';
    slideControl.appendChild(nextButton);
    prevButton = document.createElement('a');
    if (prevButton.addEventListener) {
      prevButton.addEventListener('click', prevSlide, false);
    } else if (prevButton.attachEvent) {
        prevButton.attachEvent('onclick', prevSlide);
    } else {
      prevButton.onclick = prevSlide();
    }
    prevButton.id = 'prevButton';
    prevButton.style.display = 'none';
    prevButton.innerHTML = '&laquo;';
    prevButton.style.cursor = 'hand';
    slideControl.appendChild(prevButton);
    document.getElementById('slideshow').appendChild(slideControlBackground);
    document.getElementById('slideControlBackground').appendChild(slideControl);
    
  }
  
  for (i = 0; i < slideList.length; i++) {
    var slide = new Slide();
  }
  
  // The function needs to be initialized.
  makeControls();
}

