if (window.addEventListener){  window.addEventListener('load',init,false); } else if (window.attachEvent){  window.attachEvent('onload',init);}

var n;
var l = document.FormularDiashow.Dia.length;//Gesamtzahl der Bilder
var d = l-1;//Gesamtzahl der Bilder
var i;
var r;
var b;

function init() {
i=setTimeout(rotieren,3000); // Startverzögerung in Millisekunden (3000 = 3 s)
return false;
}

//Überblendungsfunktion 
function so_xfade() {
	function setOpacity(obj) {
		if(obj.xOpacity>=0.99) {
			obj.xOpacity = 0.99;
			return false;
		}
		obj.style.opacity = obj.xOpacity;
		obj.style.MozOpacity = obj.xOpacity;
		obj.style.KhtmlOpacity = obj.xOpacity; 
		obj.style.filter = "alpha(opacity=" + (obj.xOpacity*100) + ")";
	}	
	clearTimeout(i);
	clearTimeout(b);
	var cOpacity = document.images.Bild.xOpacity;
	var nOpacity = document.images.Bildn.xOpacity;
	
	cOpacity-=0.03;//Abstufung ausblenden
	nOpacity+=0.03;//Abstufung einblenden
	
	document.images.Bild.xOpacity = cOpacity;
	document.images.Bildn.xOpacity = nOpacity;
	
	setOpacity(document.images.Bild); 
	setOpacity(document.images.Bildn);
	
	if(cOpacity<=0.03) {
		r=setTimeout(rotieren, 5000);//5sec Verzoegerung bis zum naechsten Bild
		cOpacity=0;
		return false;
	} else {
		clearTimeout(r);
		b=setTimeout(so_xfade,50);
		return false;
	}
	return false;
}

function rotieren() {
if (document.getElementById("AutomatikButton").innerHTML == "Stop") {
d = (d == l-1) ? 0 : d+1;
n = (d == l-1) ? 0 : d+1;
document.images.Bild.src = document.FormularDiashow.Dia[d].value;
document.images.Bildn.src = document.FormularDiashow.Dia[n].value;
document.images.Bild.xOpacity = 0.99;
document.images.Bildn.xOpacity = 0;
document.FormularDiashow.Dia.selectedIndex = n;
so_xfade();
   }
}

function erstes() {
d = l-1;
document.images.Bild.src = document.FormularDiashow.Dia[d].value;
document.images.Bildn.src = document.FormularDiashow.Dia[0].value;
document.FormularDiashow.Dia.selectedIndex = 0;
}
function letztes() {
d = l-2;
document.images.Bild.src = document.FormularDiashow.Dia[d].value;
document.images.Bildn.src = document.FormularDiashow.Dia[d+1].value;
document.FormularDiashow.Dia.selectedIndex = d+1;
}
function weiter() {
document.images.Bild.src = document.FormularDiashow.Dia[d].value;
d = (d == l-1) ? 0 : d+1;
document.images.Bildn.src = document.FormularDiashow.Dia[d].value;
document.FormularDiashow.Dia.selectedIndex = d;
}
function vorheriges() {
document.FormularDiashow.Dia.selectedIndex = d;
document.images.Bildn.src = document.FormularDiashow.Dia[d].value;
d = (d == 0) ? l-1 : d-1;
document.images.Bild.src = document.FormularDiashow.Dia[d].value;
}
function wechseln() {
d = document.FormularDiashow.Dia.selectedIndex-1;
d = (d < 0)?l-1:d;
n = (d == l-1) ? 0 : d+1;
document.images.Bild.src = document.FormularDiashow.Dia[d].value;
document.images.Bildn.src = document.FormularDiashow.Dia[n].value;
}
function automatisch() {
clearTimeout(i);
clearTimeout(b);
clearTimeout(r);
document.getElementById("AutomatikButton").innerHTML = (document.getElementById("AutomatikButton").innerHTML == "Start") ? "Stop" : "Start";
rotieren();
}
