function MiniPic (contener, miniatures) {
    this.con = contener;
    this.mini = miniatures;
    this.aA = [];
    this.aMini = [];
}

MiniPic.prototype.$ = function (oid) {
    if (typeof oid == "object") {
        return oid;
    }
    oid = document.getElementById(oid);
    if (oid) {
        return oid;
    } else {
        return null;
    }
};

MiniPic.prototype.inicjalize = function () {
    var self = this, aA = [], n = 0, i = 0, ln;
    this.con = this.$(this.con);
    this.mini = this.$(this.mini);
    aA = this.con.getElementsByTagName('a');

    for (i = 0, ln = aA.length; i < ln; i++) {
        if (typeof aA[i].rel != 'undefined' && aA[i].rel.match(new RegExp('lightbox'))) {
            self.aA[n] = aA[i];
            if (i > 0) {
                self.changeToImg(aA[i]);
            }
            n++;
        }
    }

    this.aMini = this.mini.getElementsByTagName('a');
    
    for (i = 0, ln = this.aMini.length; i < ln; i++) {
        this.aMini[i].number = i;
        this.aMini[i].onclick = function () {
            return self.change(this);
        }
    }
}

MiniPic.prototype.changeToImg = function (link) {
    var data = link.innerHTML, img = document.createElement('img');
    link.innerHTML = '';
    data = eval('(' + data + ')');
    for (var k in data) {
        img.setAttribute(k, data[k]);
    }
    link.appendChild(img);
}

MiniPic.prototype.change = function (ob) {
    var nr = ob.number, type = 'block';
    if (typeof this.aA[nr] == 'undefined') {
        return false;
    }
    for (var i = 0, ln = this.aA.length; i < ln; i++) {
        if (this.aA[i].style.display != 'none') {
            type = this.aA[i].style.display;
            this.aA[i].style.display = 'none';
            break;
        }
    }
    this.aA[nr].style.display = type;
    return false;
}



