
// Diashow auf Basis von Scriptaculous.

// intSystemId:		Eindeutige ID zur Identifizierung der entsprechenden DIV's
// intPicCount:		Anzahl der vorhandenen Elemente
// intSpeed:		Darstellungsdauer eines Elementes in Millisekunden
// intDuration:		Dauer einer Überblendung in Millisekunden
// bitLoop:			Soll die Diashow als Endlosschleife laufen?
// strRedirectURL:	Am ende der Diashow oder bei Klick wird hierher gesprungen
//

function GetRandom( min, max ) {
  if( min > max ) {
  return( -1 );
  }
   if( min == max ) {
   return( min );
  }
  var r = parseInt( Math.random() * ( max+1 ) );
  return( r + min <= max ? r + min : r );
}


function diashow(intSystemId, intPicCount, intSpeed, intDuration, bitLoop, strRedirectURL, intStartPict)
	{
	this.intSystemId = intSystemId;
	this.intPicCount = intPicCount;
	this.floatSpeed = parseFloat(intSpeed + intDuration) / 1000.0;	// Speed in Sekunden umrechnen
	this.floatDuration = parseFloat(intDuration) / 1000.0;			// Duration in Sekunden umrechnen
	this.bitLoop = bitLoop;
	this.strRedirectURL = strRedirectURL;
	this.intStartPict = intStartPict;
	this.intPicShown = 1;											// Das aktuell dargestellte Bild
	this.intPicNext = 2;											// Das als nächstes darzustellende Bild
	

		this.intPicNext = GetRandom( 1, this.intPicCount );
		Effect.Appear('diashow_' + this.intSystemId + '_' + this.intPicNext, {duration: 3});
		this.intStartPict = 1;
	

	
	// Zeigt das nächste Bild der Diashow an
	this.show_next_pic = function(objInterval)
		{

		// Die Werte für aktuelles und nächstes Bild neu setzen
		this.intPicShown = this.intPicNext;
		this.intPicNext = GetRandom( 1, this.intPicCount )
		
	if( this.intPicShown != this.intPicNext ) {

		// Das aktuelle Bild ausblenden
		Effect.Fade('diashow_' + this.intSystemId + '_' + this.intPicShown, {duration: this.floatDuration});


		// Das nächste Bild einblenden
		Effect.Appear('diashow_' + this.intSystemId + '_' + this.intPicNext, {duration: this.floatDuration});
		
		}
	 }


	// Das Intervall starten, welches für die Überblendungen sorgt
	new PeriodicalExecuter(this.show_next_pic.bind(this), this.floatSpeed);
	
	} // diashow()
