﻿function cImageCollection() {
    this.aImages = new Array();
    this.idx = 0; // starts with 0 !

    this.addImage = function(src, alt, buz, w, h) {
        var o = new Image(w, h);
        o.src = src;
        o.alt = alt;
        o.title = buz;
        this.aImages.push(o);
    }

    this.prev = function() {
        if (this.aImages.length == 0)
            return;
        this.idx = (this.idx == 0) ? this.aImages.length - 1 : this.idx - 1;
        this.repaint();
    }

    this.next = function() {
        if (this.aImages.length == 0)
            return;
        this.idx = (this.idx == this.aImages.length - 1) ? 0 : this.idx + 1;
        this.repaint();
    }

    this.repaint = function() {

        var o = this.aImages[this.idx];
        if (!o) {
            alert("Objekt fehlt: this.aImages[" + this.idx + "]" + this.aImages.length);
            return;
        }
        var oImg = document.getElementById("newsimg");
        var oBuz = document.getElementById("buz");
        var oIdx = document.getElementById("index");

        oImg.src = o.src;
        oImg.width = o.width;
        oImg.height = o.height;
        var s = o.alt + o.title;
        oImg.alt = s.replace(/&quot;/g, '"');
        //oBuz.innerHTML = "<i><b>" + o.alt + "</b> " + o.title + "</i>";
        oBuz.innerHTML = "<i> " + o.title + "</i>";
        oIdx.innerHTML = (this.idx + 1) + "/" + this.aImages.length;
    }
}

var oImageCollection = new cImageCollection();
