function fade(step,idx,idxAlt) {
  var imgs = document.getElementById("animation").getElementsByTagName("img");

  step = step || 0;

  if (idx > 0) {
    imgs[idx].style.opacity = step/100;
    imgs[idx].style.filter = "alpha(opacity=" + step + ")";
  } else {
    imgs[idxAlt].style.opacity = (100-step)/100;
    imgs[idxAlt].style.filter = "alpha(opacity=" + (100 - step) + ")";
  }

  step = step + 1;

  if (step <= 100) {
    window.setTimeout(function () { fade(step,idx,idxAlt); }, 1);
  } else {
    if (idxAlt > 0) {
      imgs[idxAlt].style.opacity = 0;
      imgs[idxAlt].style.filter = "alpha(opacity=0)";
    }
    if ( idx < (imgs.length - 1) ) {
      idx = idx + 1;
    } else {
      idx = 0;
    }
    if ( idxAlt < (imgs.length - 1) ) {
      idxAlt = idxAlt + 1;
    } else {
      idxAlt = 0;
    }
    window.setTimeout(function () { fade(0,idx,idxAlt); }, 8000);
  }
}


function init() {
  var imgs = document.getElementById("animation").getElementsByTagName("img");
  var idx = 1;
  var idxAlt = 0;
  imgs[idxAlt].style.opacity = 1;
  imgs[idxAlt].style.filter = "alpha(opacity=100)";
  window.setTimeout(function () { fade(0,idx,idxAlt); }, 2000);
};
