var theInterval = 5;
var theFadeSpeed = 50;
var theWidth = 519;
var theHeight = 255;

var ie = (document.all) ? true : false;

function setOpacity(obj, amount) {
  if (ie) {obj.style.filter = 'alpha(opacity:' + amount + ')';}
  else {obj.style.opacity = amount / 100;}
}

function processFade() {
  currentOpacity = currentOpacity + theIncrement;
  setOpacity(theImage, currentOpacity);
  if (currentOpacity >= 0 && currentOpacity <= 100) {setTimeout("processFade()", theFadeSpeed);}
  else {
    currentIndex++;
    if (currentIndex == arrImages.length) {currentIndex = 0;}
    nextIndex = currentIndex + 1;
    if (nextIndex == arrImages.length) {nextIndex = 0;}

    theIncrement = theIncrement * -1;

    if (whichImage == 'image') {
      theImage.src = arrImages[nextIndex];
      whichImage = 'div';
    }
    else {
      theDiv.style.background = 'url(' + arrImages[nextIndex] + ')';
      whichImage = 'image';
    }

    setTimeout("processFade()", theInterval);
  }
}

var theDirection = 'out';
var whichImage = 'image';
var currentIndex = 0;
var nextIndex = 1;
var currentOpacity = 100;
var theIncrement = -10;
var theDiv = document.getElementById('theDiv');
var theImage = document.getElementById('theImage');
theInterval = theInterval * 1000;

var arrImages = [
  "images/template/church2.jpg",
  "images/template/pastor.jpg",
  "images/template/music.jpg"
];

theImage.src = arrImages[currentIndex];
theDiv.style.background = 'url(' + arrImages[currentIndex + 1] + ')';

setTimeout("processFade()", theInterval);

var img_preload = new Array();
for (i=0;i<arrImages.length;i++) {
  img_preload[i] = new Image();
  img_preload[i].src = arrImages[i];
}
