var imgIndex = 1;
var imgNames;
var repeatInterval = 2500;
var imgObj;
 

function startfade() {
	 if((document.getElementById('startImgWrapper') != 'undefined') && (typeof document.getElementById('img1') != 'undefined') && (typeof imgNames == 'undefined')  && (typeof imgList != 'undefined')){
		imgObj = document.getElementById('img1');
		imgNames = imgList.split(',');
		imgWrap = document.getElementById('startImgWrapper');
		imgWrap.style.backgroundImage = 'url(' + imgNames[0] + ')';
		// debug("H: "+imgNames[0]);
		resetOpacity();
		imgIndex++;
		if(imgIndex >= imgNames.length)imgIndex = 0;
		//window.setTimeout('fade()', repeatInterval);
		//debug(repeatIntervals[intervalIndex] + " index: " + intervalIndex);
		window.setTimeout('fade()', repeatInterval);
	}
}


function fade(step) {
	imgWrap = document.getElementById('startImgWrapper');

	step = step || 0;

	imgObj.style.opacity = step/100;
	imgObj.style.filter = "alpha(opacity=" + step + ")"; // IE

	step = step + 2;
	//if(step == 1)debug("step1");
	//if(step == 100)debug("step100");

	if (step <= 100) {
		window.setTimeout(function () { fade(step); }, 40);
	}
	else {
		//folgende if-abfrage sorgt dafuer, dass es nicht loopt
		//if(imgIndex != 0){
			
			imgWrap.style.backgroundImage = 'url(' + imgObj.src + ')';
			//debug("bild-deckkraft = 100; H: "+imgObj.src);
			//window.setTimeout('resetOpacity()', 500);
			resetOpacity();
			imgIndex++;
			if(imgIndex >= imgNames.length)imgIndex = 0;
			//window.setTimeout('fade()', repeatInterval);
		
			window.setTimeout('fade()', repeatInterval);
			//window.setTimeout('fade()', repeatInterval);
		//}
	}
}


function resetOpacity(){
	imgObj.style.opacity = 0;
	imgObj.style.filter = "alpha(opacity=0)"; // IE
	// debug("reset  ... B-Deckkraft = 0");
	imgObj.src = imgNames[imgIndex];
	// debug("b: "+imgNames[imgIndex]);
}


function debug(m){
	if(typeof console != 'undefined') console.log(m);
}


