/* ***************************** */
/* Methods of the DiaShow object */
/* ***************************** */

function diashow_add_dia(pictureSrc) {
    newImage = new Image();
    newImage.src = pictureSrc;
    this.bussy = true;
    this.pictures[this.pictureCount] = newImage;
    this.pictureCount = this.pictures.length;
    this.bussy = false;
}

function diashow_set_delay(newDelay) {
    this.delay = newDelay;
}

function diashow_get_id_string() {
    return this.idString;
}

function diashow_run_diashow() {
    if (document.images && this.bussy == false) {
        this.currentPicture = 0;
        this.image.src = this.pictures[this.currentPicture].src;
        setTimeout(this.timeoutCommand, this.delay);
    }
}

function diashow_next_picture() {
    if (document.images && this.bussy == false) {
        this.currentPicture++;
        if (this.currentPicture >= this.pictureCount) {
            this.currentPicture = 0;
        }
        this.image.src = this.pictures[this.currentPicture].src;
        setTimeout(this.timeoutCommand, this.delay);
    }
}

function DiaShow(idString, theImage) {
    this.image = theImage;
    this.idString = idString;
    this.timeoutCommand = "diashowTimeoutEvent(\"" + idString + "\")";
    this.pictures = new Array();
    this.pictureCount = 0;
    this.currentPicture = 0;
    this.delay = 2000;
    this.bussy = new Boolean(false);
}
DiaShow.prototype.addDia = diashow_add_dia;
DiaShow.prototype.setDelay = diashow_set_delay;
DiaShow.prototype.getIdString = diashow_get_id_string;
DiaShow.prototype.run = diashow_run_diashow;
DiaShow.prototype.nextPicture = diashow_next_picture;

/* ************************************ */
/* Methods of the DiaShowControl object */
/* ************************************ */

function diashowcontrol_add_diashow(diaShow) {
    var idString;
    idString = diaShow.getIdString();
    this.diaShows[idString] = diaShow;
    this.diaShowCount = this.diaShows.length;
}

function diashowcontrol_get_diashow(idString) {
    return this.diaShows[idString];
}

function DiaShowControl() {
    this.diaShows = new Array();
    this.diaShowCount = 0;
}
DiaShowControl.prototype.addDiaShow = diashowcontrol_add_diashow;
DiaShowControl.prototype.getDiaShow = diashowcontrol_get_diashow;

/* ************** */
/* Required stuff */
/* ************** */

theDiaShowControl = new DiaShowControl();


function diashowTimeoutEvent(idString) {
    var theDiaShow;
    theDiaShow = theDiaShowControl.getDiaShow(idString);
    if (theDiaShow) {
        theDiaShow.nextPicture();
    }
}
