// configuration variables

var delay = 5000; // time in milliseconds each image is displayed before fade to next begins

var images = new Array();
images[0] = "images/bg_training.jpg"; // initial image
images[1] = "images/bg_tours.jpg"; // second image
images[2] = "images/bg_sales.jpg";
images[3] = "images/bg_gifts.jpg";
//images[4] = "images/bg_service.jpg";
//images[5] = "images/bg_simulator.jpg";
//images[6] = "images/bg_photography.jpg";
//images[7] = "images/bg_video.jpg";


// no changes necessary below this line

var index = 2;
var step = 100;

function preload()
{
  imageObj = new Image();
  
  for(i=0; i<images.length; i++) 
  {
    imageObj.src=images[i];
  }
}

function swap()
{
  var backgroundElement = document.getElementById("background");
  var foregroundElement = document.getElementById("foreground");

  foregroundElement.src = images[index];
  
  index = (index+1)%images.length;
  backgroundElement.style.backgroundImage = "url(" + images[index] + ")";
  backgroundElement.style.backgroundRepeat = "no-repeat";
  
  fade();
}

function fade()
{
  var backgroundElement = document.getElementById("background");
  var foregroundElement = document.getElementById("foreground");
  
  if (step>=0)
  {
    foregroundElement.style.filter  = "alpha(opacity=" + step + ")";
    foregroundElement.style.opacity = step/100;
    step--;
    
    setTimeout("fade()",10);
  }
  else
  {
    step=100;
    setTimeout("swap()",delay); 
  }
}

function startImageFader()
{
  preload();
  setTimeout("fade()",delay);
}