var globalAutoFade		= false;
var globalAutoFadeDelay	= 5000;
var globalAutoFadeTimer	= null;
var globalFadeDelay		= 1300;

function initFader (doAutoFade)
{
	$("div[id^=fader_]").each (function (i) {
		if (i == 0 && $.browser.msie) {
			$(this).css ('opacity', 0.999);			
		}
										 
		if (i > 0) {
			$(this).css ('opacity', 0);
		}

		$("#fader_next_" + i).bind ('click', i, function (e) {															 
			fader (e.data, 'next');																	 
		});
		
		$("#fader_prev_" + i).bind ('click', i, function (e) {															 
			fader (e.data, 'prev');																	 
		});		
	});
	
	globalAutoFade = doAutoFade;
	
	if (globalAutoFade) {
		globalAutoFadeTimer = setTimeout ("fader (0, 'next')", globalAutoFadeDelay);
	}
}

function fader (id, type)
{
	// Timeout löschen?
	if (globalAutoFade) {
		clearTimeout (globalAutoFadeTimer);		
	}	
	
	// Nächste ID ermitteln
	if (type == 'next') {
		var nextId = id + 1;
	} else {
		var nextId = id - 1;		
	}

	if ($("#fader_" + nextId).length == 0) {
		nextId = 0;		
	}
	
	// Aktuelles Element ausblenden
	$("#fader_" + id).animate ({opacity: 0.0}, globalFadeDelay, '', function () {
		$(this).hide ();
	});
	
	// Neues Element einblenden
	$("#fader_" + nextId).show ();
	$("#fader_" + nextId).animate ({opacity: 1.0}, globalFadeDelay);	
	
	// Neuen Timeout setzen?
	if (globalAutoFade) {
		globalAutoFadeTimer = setTimeout ("fader (" + nextId + ", 'next')", globalAutoFadeDelay);		
	}
}