// after the page loads ...
window.onresize = onresizeInit;

function onresizeInit() {
  imageXY = findPos('home_photo');
  for(i=0; i<the_images.length; i=i+1) {
    document.getElementById(the_images[i]).style.left = imageXY[0] + 'px';
    document.getElementById(the_images[i]).style.top  = imageXY[1] + 'px';
  }
}

var imageXY;
// ... we'll start the fader
function photoInit() {
  imageXY = findPos('home_photo');
  for(i=0; i<the_images.length; i=i+1) {
    setOpacity(the_images[i],'0');
    document.getElementById(the_images[i]).style.left = imageXY[0] + 'px';
    document.getElementById(the_images[i]).style.top  = imageXY[1] + 'px';
  }
  setTimeout('fader(0)',timeBetweenFades)
  onresizeInit();
  setOpacity(the_images[0],'100');
}

// the following array is an array of id's.
// each id represents a div
// the fader loops through these items.
var the_images = new Array ('home_photo1','home_photo2','home_photo3','home_photo4');

// global variables with default values
var fadeSpeed = 15;
var fadeSteps = 4;
var fadeInDelay = 1;
var timeBetweenFades = 6500;
var theArray = the_images;
var length = eval(theArray).length;
      
// 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;
  fadeOut(eval(theArray)[i]);
  fadeIn(eval(theArray)[j]);
  //setTimeout('fadeIn(eval(theArray)[' + j + ']);',fadeSpeed * fadeInDelay)
  setTimeout('fader(' + j + ')',timeBetweenFades)
}

function fadeIn(imgN) {
  var timer = 0;
  for(i=-80; i<=100; i=i+fadeSteps) {
    if (i < 0) k = 0;
    else k = i;
    setTimeout('setOpacity(\'' + imgN + '\',' + k + ')',(timer * fadeSpeed));
    timer++;
  }
}

function fadeOut(imgN) {
  var timer = 0;
  for(i=100; i>=-80; i=i-fadeSteps) {
    if (i < 0) k = 0;
    else k = i;
    setTimeout('setOpacity(\'' + imgN + '\',' + k + ')',(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 + ")";
}
