MeinBild = 0;
Bild1=1;
Bild2=6;
Bild3=11;

function fade (element, from, to, current) {
  t=45;
  
  if (typeof current == 'undefined') {
    current = from;
  }
  if (typeof element.style.opacity != 'undefined') {
    element.style.opacity = current;
  }
  else if (typeof element.style.filter != 'undefined') {
    element.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=' + (current * 100) + ')';
  }
  if (from > to) {
    current -= 0.025;
    current = Math.round(current * 100) / 100;
    if (current >= to) {
      setTimeout(function () { fade(element, from, to, current); }, t);
    }
  }
  else {
    current += 0.025;
    current = Math.round(current * 100) / 100;
    if (current <= to) {
      setTimeout(function () { fade(element, from, to, current); }, (t+30));
    }
  }
  
}



StarteBildlauf = function(t, bild) {
	Bildwechsel(bild);
	setTimeout(function () { StarteBildlauf(t, bild); }, t, bild);
}

Tauschen = function(bild, pfadalt) {
	
	if (bild.id=="blendbild1") {
		von = 1;
		index = 0;
		MeinBild = Bild1;
	}
	
	if (bild.id=="blendbild2") {
		von = 6;
		index = 1;
		MeinBild = Bild2;
	}
	
	if (bild.id=="blendbild3") {
		von = 11;
		index = 2;
		MeinBild = Bild3;
	}
	
	
	do {
		pfad = von + 4*(Math.random());
		pfad = Math.round(pfad);
	} while (pfad==MeinBild);
	
	
	if (bild.id=="blendbild1") Bild1 = pfad;
	if (bild.id=="blendbild2") Bild2 = pfad;
	if (bild.id=="blendbild3") Bild3 = pfad;
	
	
	
	
	if (pfad<10) pfad = "0" + pfad;
	pfad = "bilder/bildblende/" + pfad + ".jpg";

	if (pfad==pfadalt) {
		Tauschen(bild, pfadalt);
		return;
	}else {
		bild.src = pfad;
	}

	
}


Bildwechsel = function(bild) {

fade(bild, 1, 0);

setTimeout(function () { Tauschen(bild, bild.src); }, 3000);

setTimeout(function () { fade(bild, 0, 1); }, 3000);

}

