

var images = new Array( 'images/head.png',

                        'images/2.png',

            'images/3.png')



var nextImage = 1;

var imageWidth = 900;

var imageHeight = 210;

var imageTimeout = 7000;



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 += 3;

    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); }, 50);

      }

  }



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);



function addLoadEvent(func) 

  {

    var oldonload = window.onload;

    if (typeof window.onload != 'function') 

      {

        window.onload = func;

      }

      else 

      {

        window.onload = function() 

          {

            if (oldonload) 

              {

                 oldonload();

              }

            func();

          }

      } 

  }




