function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  }
  else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

var images = new Array(
    'images/image01.jpg',
    'images/image02.jpg',
    'images/image03.jpg',
    'images/image04.jpg');

    var imageWidth = 790;
    var imageHeight = 118;
    var imageTimeout = 3000;
    var nextImage = 1;
    
    function setOpacity(el, opacity) {

      opacity /= 100;

      el.style.opacity = opacity;
      el.style.MozOpacity = opacity;
      el.style.filter = "alpha(opacity=" + (opacity*100) + ")";

    }
    
    function fadeImage(el, currentOpacity) {

      currentOpacity += 5;

      if (currentOpacity > 100) {
        setOpacity(el, 100);
        var prevEl = el.previousSibling ? el.previousSibling : el.parentNode.lastChild;
        prevEl.style.visibility = 'hidden';
        el.style.zIndex = 1;
        window.setTimeout(startFading, imageTimeout);
      }
      else {
        setOpacity(el, currentOpacity);
        window.setTimeout(function() { fadeImage(el, currentOpacity); }, 100);
      }

    }
    
    function startFading() {

      var el = document.getElementById('fading_image_container').childNodes[nextImage];

      el.style.visibility = 'visible';
      el.style.zIndex = 2;
      setOpacity(el, 0);
      fadeImage(el,0);

      nextImage = (nextImage < images.length-1) ? nextImage + 1 : 0;

    }
    
    function pageLoad() {

      var el = document.getElementById('fading_image_container');
      while (el.firstChild) { el.removeChild(el.firstChild); }

      el.style.width = imageWidth + 'px';
      el.style.height = imageHeight + 'px';

      for(var i=0; i<images.length; i++) {

        var t = document.createElement('IMG');
        t.setAttribute('src',images[i]);
        t.setAttribute('width',imageWidth);
        t.setAttribute('height',imageHeight);
        t.style.position = 'absolute';
        t.style.visibility = 'hidden';
        el.appendChild(t);

      }

      el.firstChild.style.visibility = 'visible';

      window.setTimeout(startFading, imageTimeout);

    }
addLoadEvent(pageLoad);
