// Zeit bis zum nächsten Bildwechsel in Sekunden*1000
switchtime = 5*1000;

// Zeit bei der ausgefadet werden soll
fadetime = 4*1000;

setTimeout("hide()", fadetime);
// funktionen zum fade in/out
function opacity(id, opacStart, opacEnd, millisec) {
	//speed for each frame
	var speed = Math.round(millisec / 100);
	var timer = 0;

	//determine the direction for the blending, if start and end are the same nothing happens
	if(opacStart > opacEnd) {
		for(i = opacStart; i >= opacEnd; i--) {
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	} else if(opacStart < opacEnd) {
		for(i = opacStart; i <= opacEnd; i++)
			{
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	}
}
function hide ( )
{
	opacity("picswitch", 100, 0, 1000);
}
function changeOpac(opacity, id) {
	var object = document.getElementById(id).style;
	document.getElementById(id).style.display = "block";
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")";
}

// KIWI.Picswitch
var Timeout = 1;
var number = 3; // anzahl bilder
var baseurl = "http://www.kiwicore.com/images/headbilder/"; // verzeichnis in dem die 3 home bilder liegen

function showSeconds ( )
{
	// Das jetzige Bild in Variable last laden.
	last 				= 	document.getElementById('picswitch').src;
	// Random festlegen
	today				=	new Date();
	jran				=	today.getTime();
	ia					=	9301;
	ic					=	49297;
	im					=	233280;
	jran 				=	(jran*ia+ic) % im;
	
	var random_number = Math.ceil( (jran/(im*1.0)) * number);

	if (last == baseurl + 'home_' + random_number + '.jpg')
	{
		if (last == baseurl + 'home_' + 1 + '.jpg')
		{
			document.getElementById('picswitch').src = baseurl + 'home_2.jpg';
		}
		if (last == baseurl + 'home_' + 2 + '.jpg')
		{
			document.getElementById('picswitch').src = baseurl + 'home_3.jpg';
		}
		if (last == baseurl + 'home_' + 3 + '.jpg')
		{
			document.getElementById('picswitch').src = baseurl + 'home_1.jpg';
		}
	}
	else
	{
		document.getElementById('picswitch').src = baseurl + 'home_' + random_number + '.jpg';
	}
	
	setTimeout("hide()", fadetime);
	opacity('picswitch', 0, 100, 1000);
}
setInterval("showSeconds()", switchtime);
