// 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?
// bitRandom:		Soll die Diashow in Zufallsreihenfolge laufen?
// strRedirectURL:	Am ende der Diashow oder bei Klick wird hierher gesprungen
// intStartPict:	Startbild
//


function zufall() {
    return (Math.random() - Math.random());
}


function diashow(intSystemId, intPicCount, intSpeed, intDuration, bitLoop, bitRandom, 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.bitRandom = bitRandom;
    this.strRedirectURL = strRedirectURL;
    this.intStartPict = intStartPict;
    this.intPicShown = 1;
     this.intPicNext = 2;
     this.intFirst = true;
    this.intStart = true;
    this.Zahlen = new Array();

    for (this.i = 0; this.i < this.intPicCount; this.i++) {
        this.Zahlen[this.i] = new Object();
        this.Zahlen[this.i] = this.i + 1;
    }

    if (this.bitRandom == true) {
        for (this.i = 0; this.i < this.intPicCount; this.i++) {
            this.Zahlen[this.i] = new Object();
            this.Zahlen[this.i] = this.i + 1;
        }
        this.Zahlen.sort(zufall);
    }

    if (this.intStartPict > 0) {
        if (this.intFirst == true) {
            this.intPictTemp = this.Zahlen[0];
            this.Zahlen[0] = this.intStartPict;
            for (this.i = 1; this.i < this.intPicCount; this.i++) {
                if (this.Zahlen[this.i] == this.intStartPict) {
                    this.Zahlen[this.i] = this.intPictTemp;
                }
            }
            this.intFirst = false;
        }
    }

    if (this.intStart == true)
    {
        Effect.Appear('diashow_' + this.intSystemId + '_' + this.Zahlen[0], {
            duration: 0
        });
        this.intStart = false;
    }



     this.show_next_pic = function(objInterval)
    {
         Effect.Fade('diashow_' + this.intSystemId + '_' + this.Zahlen[this.intPicShown - 1], {
            duration: this.floatDuration
        });


         Effect.Appear('diashow_' + this.intSystemId + '_' + this.Zahlen[this.intPicNext - 1], {
            duration: this.floatDuration
        });

         this.intPicShown = this.intPicNext;
        this.intPicNext = this.intPicNext + 1;

         if (this.intPicNext > this.intPicCount)
        {
             if (this.bitLoop)
            {
                this.intPicNext = 1;
            }
            else
            {
                 objInterval.stop();

                 if (this.strRedirectURL != '')
                {
                    new PeriodicalExecuter(this.goto_url.bind(this), this.floatSpeed);
                }
            }
        }
    }

     this.goto_url = function()
    {
        if (this.strRedirectURL != '')
        {
            window.location.href = this.strRedirectURL;
        }
    }

     if (strRedirectURL != '')
    {
         Event.observe($('diashow_' + this.intSystemId), 'click', this.goto_url.bind(this), true);

         $('diashow_' + this.intSystemId).style.cursor = 'pointer';
    }

     new PeriodicalExecuter(this.show_next_pic.bind(this), this.floatSpeed);

}
// diashow()
