

function Picture(id,url,title,legend)
{
	this.id = id;
	this.url = url;
	this.title = title;
	this.legend = legend;
}



/*

Diese Klasse verhält sich ähnlich wie die bekannte Lightbox.
Für Beispielcode scrolle ganz nach unten.

*/

var mooImageSwitcher = new Class({
    Implements: Options,
    options: {
        cssprefix: 'box',       // css prefix für verschiedene css klassen (bsp: .box_headline)
        rel: 'imagebox',        // es werden alle bilder angezeigt die rel=imagebox definiert haben. name kann hier angepasst werden.
        imageresizeurl: null,   // url zu unserem image-resize-service. wenn angegeben wird bild damit zugeschnitten und die optimale grösse für den bildschirm gesucht.
        cutHorizontal: 100,     // beim zuschneiden des bildes wird der angegebene wert abgezogen in der horizontalen
        cutVertical: 100,       // beim zuschneiden des bildes wird der angegebene wert abgezogen in der vertikalen
        imageloadingurl: 'grafik/mooImageBox/loading.gif'     // pfad des ladebalken bildes       

    },

    /* constructor */
    initialize: function(options) {
            this.arr = new Array();
            this.aktindex = 0;
            this.imageId = "containerimg";
            this.legendId = "commentdiv";
            this.titleId = "titlediv";
            this.statusId = "statusdiv";
            this.intervalID = "";
    },


    /* add new picture */
    add: function(id, url, title, legend) {

        var pic = new Picture(id, url, title, legend);
        this.arr[this.arr.length] = pic;
    },


    first: function() {
        this.aktindex = 0;
        this.setImage();
    },

    previous: function() {

        this.aktindex--;

        if (this.aktindex < 0)
            this.aktindex = this.arr.length - 1;
        this.setImage();
    },

    next: function() {

        this.aktindex++;

        if (this.aktindex >= this.arr.length)
            this.aktindex = 0;

        this.setImage();
    },

    last: function() {
        this.aktindex = this.arr.length - 1;
        this.setImage();
    },

    setImage: function() {

        var img = $(this.imageId);
        var legend = $(this.legendId);
        var title = $(this.titleId);
        var status = $(this.statusId);

        var pic = this.arr[this.aktindex];

        if (pic == null)
            return;

        if (pic.legend == null || pic.legend == "")
            pic.legend = pic.title;

        //if(img != null) img.src = pic.url;

        if (legend != null) legend.innerHTML = pic.legend;
        if (title != null) title.innerHTML = pic.title;
        if (status != null) status.innerHTML = (this.aktindex + 1) + " / " + this.arr.length;

        if (onImageSet)
            onImageSet(pic.id, this.aktindex);
    },

    setImageByIndex: function(index) {
        this.aktindex = index;
        this.setImage();
    },

    setImageById: function(picid) {
        for (var i = 0; i < this.arr.length; i++) {
            if (this.arr[i].id == picid)
                this.aktindex = i;
        }
        this.setImage();
    },

    getImageById: function(picid) {
        for (var i = 0; i < this.arr.length; i++) {
            if (this.arr[i].id == picid)
                return this.arr[i];
        }
        return null;
    },

    play: function(switcherVarName, ms) {
        window.clearInterval(this.intervalID);
        this.intervalID = window.setInterval(switcherVarName + ".next()", ms);
    },

    stop: function() {
        window.clearInterval(this.intervalID);
    }

});



