// tuneable parameters
var swapImageLongTimeout = 3000;
var swapImageMedTimeout = 2000;
var swapImageShortTimeout = 70;
var swapImageTimeout = 150;
var swapImageStepIncrement = 5;
var swapImageLastImage = 2;
var swapImageElementId = "slide";

// shouldn't need to change below here.
//var imageIdx = (Math.floor(Math.random()*swapImageLastImage));
var imageIdx = 0;
var step = swapImageStepIncrement;
var fadein = true;


function setOpacity(display, opacity) 
   {
      // IE/Win
      var ieopacity = opacity*100.0;
      display.style.filter = "alpha(opacity:"+ieopacity+")";
    
      // Safari<1.2, Konqueror
      display.style.KHTMLOpacity = opacity;
    
      // Older Mozilla and Firefox
      display.style.MozOpacity = opacity;
     
      // Safari 1.2, newer Firefox and Mozilla, CSS3
      display.style.opacity = opacity;
}

function swapimage() {
      var element = document.getElementById(swapImageElementId);

      opacity = (fadein) ? 1-(step/100)+0.02 : (step/100)-0.02;
      opacity = (opacity > 0.99) ? 0.99 : opacity;
      setOpacity(element, opacity);

      if(opacity < 0.01) {
         fadein = false;
         timeout = swapImageTimeout;
         imageIdx = (imageIdx < swapImageLastImage) ? imageIdx+1 : 0;
         var filename = 'images/slides/slide'+imageIdx+'.jpg';
         element.src=filename;
         step = swapImageStepIncrement;
      } else if(opacity >= 0.98) {
         fadein = true;
         timeout = swapImageLongTimeout;
         step = swapImageStepIncrement;
      } else {
         timeout = swapImageShortTimeout;
         step += swapImageStepIncrement;
      }
      setTimeout("swapimage()", timeout);
}
