


window.addEventListener?window.addEventListener("load",so_init,false):window.attachEvent("onload",so_init);

var d=document, wdh=6, imgs = new Array(), bilder = new Array(), zInterval = null, current=0, bildnr=0, zahl=0, pause=false;

function so_init() {


  if(!d.getElementById || !d.createElement)return;




  var bereich = document.getElementById("startpage");
   bilder = bereich.getElementsByTagName("img");
  for(i=0;i<bilder.length;i++)
   {
    bilder[i].xOpacity = .99;
    bilder[i].style.display = "block";
   }

  imgs = d.getElementById("imageContainer").getElementsByTagName("img");
  for(i=1;i<imgs.length;i++) imgs[i].xOpacity = 0;
  imgs[0].style.display = "block";
  imgs[0].xOpacity = .99;

  setTimeout(so_xfade,500);


}




function so_xfade() {


  cOpacity = imgs[current].xOpacity;
  nIndex = imgs[current+1]?current+1:0;

  nOpacity = imgs[nIndex].xOpacity;

  cOpacity-=.05;

if(zahl>=wdh) {
  nOpacity-=.05;
 imgs[nIndex].style.display = "none";
 }
 else
 {
   nOpacity+=.05;
   imgs[nIndex].style.display = "block";
 }




  imgs[current].xOpacity = cOpacity;
  imgs[nIndex].xOpacity = nOpacity;

  setOpacity(imgs[current]);
  setOpacity(imgs[nIndex]);








  if(cOpacity<=0 && zahl<wdh) {
    imgs[current].style.display = "none";
    current = nIndex;
    zahl+=1;
    setTimeout(so_xfade,1000); }

  if(cOpacity>0 && zahl<wdh) {

     setTimeout(so_xfade,70); }

  if(cOpacity<=0 && zahl>=wdh) {
    imgs[current].style.display = "none";
    current = nIndex;
    setTimeout(all_fade,1); }

  if(cOpacity>0 && zahl>=wdh) {
    for(i=1;i<imgs.length;i++)
    {imgs[i].xOpacity = 0;
     imgs[i].style.display = "none";
    }
    current = nIndex;
    setTimeout(all_fade,1);}


  function setOpacity(obj) {
    if(obj.xOpacity>.99) {
      obj.xOpacity = .99;
      return;
    }
    obj.style.opacity = obj.xOpacity;
    obj.style.MozOpacity = obj.xOpacity;
    obj.style.filter = "alpha(opacity=" + (obj.xOpacity*100) + ")";
  }

}

function all_fade() {
cOpacity = bilder[bildnr].xOpacity;
nIndex2 = bilder[bildnr+1]?bildnr+1:0;
nOpacity = bilder[nIndex2].xOpacity;

  cOpacity-=.1;
  nOpacity-=.1;


  bilder[bildnr].xOpacity = cOpacity;
  bilder[nIndex2].xOpacity = nOpacity;

  setOpacity2(bilder[bildnr]);
  setOpacity2(bilder[nIndex2]);

  if(cOpacity<=0) {
    bilder[bildnr].style.display = "none";
     bildnr = nIndex2;
    setTimeout(all_fade,1);
  } else {
    bildnr = nIndex2;
    setTimeout(all_fade,1);
  }

  function setOpacity2(obj) {
    if(obj.xOpacity<0) {
      obj.xOpacity = 0;
      return;
    }
    obj.style.opacity = obj.xOpacity;
    obj.style.MozOpacity = obj.xOpacity;
    obj.style.filter = "alpha(opacity=" + (obj.xOpacity*100) + ")";
  }
 }

