function idgFader (paramParent, paramWidth, paramHeight) {

  if (!paramWidth) paramWidth=600;
  if (!paramHeight) paramHeight=200;
  this.intAnimationWidth=paramWidth;
  this.intAnimationHeight=paramHeight;
  
  this.arrImages=[];  // arrImages: [0: Object, 1: Visibility]
  
  this.intActAnimationImage=0;
  this.intLastImage=-1;
  this.ptrAnimationInterval=0;
  
  this.viewport=document.createElement ("div");
  this.viewport.className='idgFaderAnimation';
  this.viewport.style.width=paramWidth+'px';
  this.viewport.style.height=paramHeight;
  document.getElementById (paramParent).appendChild (this.viewport);
  
}


idgFader.prototype.fnAddImage = function (paramImage) {

  var objImage=new Image ();
  objImage.src=paramImage;
  objImage.className='idgFaderAnimation_Pic';
  this.viewport.appendChild (objImage);
  
  this.arrImages.push ([objImage, 0]);
  
  this.ptrLoadImageInterval=window.setInterval (this.fnLoadImageInterval.bind(this), 40);
  
}

idgFader.prototype.fnRefreshImage = function () {

  this.arrImages[this.intActAnimationImage][0].style.MozOpacity=this.arrImages[this.intActAnimationImage][1];
  this.arrImages[this.intActAnimationImage][0].style.filter="alpha(opacity="+this.arrImages[this.intActAnimationImage][1]*100+")";
}

idgFader.prototype.fnLoadImageInterval = function () {

  var intLoadState=0;

  for (var dummy=0; dummy<this.arrImages.length; dummy++) {
    if (this.arrImages[dummy][0].complete) intLoadState++;
  }
  
  if (intLoadState==this.arrImages.length) {
    window.clearInterval (this.ptrLoadImageInterval); 
    if (intLoadState>1 && !this.ptrAnimationInterval) this.ptrAnimationInterval=window.setInterval (this.fnAnimationInterval.bind(this), 40);    
  }
}


idgFader.prototype.fnAnimationInterval = function () {

  var constFadeFactor=0.02;


  if (!this.arrImages[this.intActAnimationImage][1]) {
    this.arrImages[this.intActAnimationImage][0].style.zIndex=2;
    this.arrImages[this.intActAnimationImage][0].style.visibility='visible';
  } 
  this.arrImages[this.intActAnimationImage][1]+=constFadeFactor;    
  this.fnRefreshImage ();
  
  if (this.arrImages[this.intActAnimationImage][1]>=1.2) {
    this.arrImages[this.intActAnimationImage][0].style.zIndex=1;
    if (this.intLastImage>-1) {
      this.arrImages[this.intLastImage][0].style.zIndex=0;
      this.arrImages[this.intLastImage][0].style.visibiliy='hidden';
      this.arrImages[this.intLastImage][1]=0;
    }
    this.intLastImage=this.intActAnimationImage;
    this.intActAnimationImage=(this.intActAnimationImage+1)%this.arrImages.length;
    
  } 

}




// ******************************************************************************
// *** Hilfs-Funktionen *********************************************************
// ******************************************************************************

function $A (iterable) {
	var result = [];
	for (var i = 0; i < iterable.length; i++) {
		result.push(iterable[i]);
	}
	return result;
}

Function.prototype.bindAsEventListener = function (object) {
	// Die Funktion nimmt einen Parameter entgegen, der
	// das Objekt darstellt, in dessen Kontext die gewünschte Funktion
	// ausgeführt werden soll.

	// Speichere die gegenwärtige Funktion in »method«.
	var method = this;

	// Notiere eine Function-Expression, die als Closure wirkt
	var wrapper = function (event) {

		// Die Closure schließt »method« und »object« ein.
		// Rufe die Methode im Kontext des Objektes »object« auf und
		// reiche das Event-Objekt durch.
		method.call(object, event || window.event);
	};

	// Gib die Wrapper-Funktion zurück.
	return wrapper;
};

Function.prototype.bind = function () {

	// Speichere die gegenwärtige Funktion in »method«.
	var method = this;

	// Die Funktion nimmt eine beliebige Anzahl von Parametern entgegen,
	// auf die über den »arguments«-Pseudoarray zugegriffen wird.
	// Wandle »arguments« mit einer Helferfunktion in einen echten Array um.
	var args = $A(arguments);

	// Nehme den ersten Parameter als das Objekt, in dessen Kontext
	// die Funktion ausgeführt werden soll. Speichere die verbleibenden
	// Parameter in »args«.
	var object = args.shift();

	// Notiere eine Function-Expression, die als Closure wirkt
	var wrapper = function () {

		// Die Closure schließt »method«, »object« und »args« ein.
		// Rufe die Funktion im Kontext des Objektes »object« auf, reiche
		// die Parameter weiter und gebe den Rückgabewert zurück.
		return method.apply(object, args);

	};
	// Gib die Wrapper-Funktion zurück.
	return wrapper;

};


