
/***********************************************
* Bildwechsel
***********************************************/

var imgIndex = 0;
var repeatInterval = 3500;
var waiting = false;
var started = true;
 
function startFade() {
	 if((document.getElementById('frontispiece') != 'undefined') && (typeof document.getElementById('frontispieceimg') != 'undefined') && (typeof imgList != 'undefined')){
		imgObj = document.getElementById('frontispieceimg');
		imgWrap = document.getElementById('frontispiece');
		txtObj = document.getElementById('frontispiecetxt');
		// Hintergrundbild setzen:
		imgWrap.style.backgroundImage = 'url(' + imgObj.src + ')';
		fade();
	}
}

// <div id="frontispiecetxt">Einzigartig wohnen und Arbeiten<br /><span class="titel">RIEGELER Lofts</span><br /><a href="immobilien/wohnimmobilien/"><img src="/fileadmin/templates/images/link_clear.gif" class="linkicon" alt="mehr" height="11" width="15" /><span><strong>zum Projekt</strong></span></a></div>
function fade(step) {
	waiting = false;

	// wenn nichts uebergeben wurde, dann step auf 0 setzen:
	step = step || 0;

	// Bild-Deckkraft auf Null setzen und von 0% (step = 0) erhöhen auf 100% (step 100):
	imgObj.style.opacity = step/100;
	imgObj.style.filter = "alpha(opacity=" + step + ")"; // IE

	if(started == false){
		if(step <= 50) txtObj.style.opacity = 1 - (step/50);
		else txtObj.style.opacity = (step-50) / 50;
	}
	
	step = step + 2;
	
	if(started == false){
		//if (step == 48) txtObj.innerHTML = '';
		if (step == 50) txtObj.innerHTML = imgList[imgIndex][2]+'<br /><span class="titel">'+imgList[imgIndex][3]+'</span><br /><a href="'+imgList[imgIndex][1]+'"><img src="/fileadmin/templates/images/link_clear.gif" class="linkicon" alt="mehr" height="11" width="15" /><span><strong>zum Projekt</strong></span></a>';
	}
	
	if (step <= 100){
		 aktiv = window.setTimeout(function () { fade(step); }, 40);
	}
	else {
		started = false;
		
		// Hintergrundbild austauschen -> gleich wie Vordergrund
		imgWrap.style.backgroundImage = 'url(' + imgObj.src + ')';

		// Vordergrund transparent machen:
		imgObj.style.opacity = 0;
		imgObj.style.filter = "alpha(opacity=0)"; // IE

		// Vordergrund -> naechstes Bild:
		imgIndex++;
		waiting = true;
		if(imgIndex >= imgList.length)imgIndex = 0;
		imgObj.src = imgList[imgIndex][0];

		// nach Intervall-Ablauf mit Einblenden beginnen
		aktiv = window.setTimeout('fade()', repeatInterval);
		// kann mit Clear-Timeout abgebrochen werden.
	}
}


function fadeSwitch(mode){
	window.clearTimeout(aktiv);
	
	if (mode == 2){
		if(waiting == false) imgIndex++;
		if(imgIndex >= imgList.length)imgIndex = 0;
	}
	else{
		if(waiting == false) imgIndex--;
		else imgIndex = imgIndex - 2;
		if(imgIndex < 0)imgIndex = imgList.length - 1;
	}
	
	debug("imgIndex: "+imgIndex);
	started = true;
	imgObj.src = imgList[imgIndex][0];
	imgWrap.style.backgroundImage = 'url(' + imgObj.src + ')';
	txtObj.innerHTML = imgList[imgIndex][2]+'<br /><span class="titel">'+imgList[imgIndex][3]+'</span><br /><a href="'+imgList[imgIndex][1]+'"><img src="/fileadmin/templates/images/link_clear.gif" class="linkicon" alt="mehr" height="11" width="15" /><span><strong>zum Projekt</strong></span></a>';
	fade();
	return false;
}


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