// global variables with default values
var fadeSpeed = 35;
var timeBetweenFades = 7500;
      
// the fader function directs all the fading
// this function calls itself over and over again
function fader(theImg) {
  i = theImg;
  if (i == length - 1) j = 0;
  else j = i + 1;
  if (j == length - 1) k = 0;
  else k = j + 1;
  currentImg = j;
  fadeOut(eval(theArray)[i]);
  fadeIn(eval(theArray)[j]);
  setTimeout('fader(' + j + ')',timeBetweenFades)
}

function fadeIn(imgN) {
  var timer = 0;
  for(i=0; i<=100; i=i+4) {
    setTimeout('setOpacity(\'' + imgN + '\',' + i + ')',(timer * fadeSpeed));
    timer++;
  }
}

function fadeOut(imgN) {
  var timer = 0;
  for(i=100; i>=0; i=i-4) {
    setTimeout('setOpacity(\'' + imgN + '\',' + i + ')',(timer * fadeSpeed));
    timer++;
  }
}

function setOpacity(objectId,objectOpacity) {
  var object = document.getElementById(objectId).style; 
  object.opacity = (objectOpacity / 100);
  object.MozOpacity = (objectOpacity / 100);
  object.KhtmlOpacity = (objectOpacity / 100);
  object.filter = "alpha(opacity=" + objectOpacity + ")";
}
