var timespan = 6; //Anzeigedauer in Sekunden

function switchImage()
{
	image = document.getElementById("img1").style.backgroundImage;
	while (image.substr(-7, 2) == document.getElementById("img1").style.backgroundImage.substr(-7, 2))
	{
		n = Math.floor(Math.random() * 20 + 1);
		image = "url(/content/rotation/rot" + (n < 10 ? "0" + n : n) + ".png)";
	}
	document.getElementById("img2").style.backgroundImage = image;
	window.setTimeout("blend(0)", timespan * 1000);
}

function blend(opacity)
{
	if (opacity < 100)
	{
		document.getElementById("img1").style.opacity = (100 - opacity) / 100;
		document.getElementById("img2").style.opacity = opacity / 100;
		window.setTimeout("blend(" + (opacity + 5) + ")", 50);
	}
	else
	{
		document.getElementById("img1").style.backgroundImage = 
			document.getElementById("img2").style.backgroundImage;
		document.getElementById("img1").style.opacity = "1.0";
		document.getElementById("img2").style.opacity = "0.0";
		switchImage()
	}
}

switchImage();