function imageGallery($img_name){
    this.$img_name          = $img_name;
    this.$image_gal         = new Array();
    this.$img_count         = 0;
    this.$img_current       = 0;
    this.$first_time        = true;
    this.$image_src         = new Array();
    this.$image_src_full    = new Array();
    this.$imageCache        = new Array();


    this.addImage = function addImage($src, $src_full) {
        this.$image_src[this.$img_count] = $src;
        this.$image_src_full[this.$img_count] = $src_full;
        this.$img_count++;
    }

    this.imageNext = function imageNext() {
        if(++this.$img_current >= this.$img_count) {
            this.$img_current = 0;
        }
        this.imageChange();
    }
	
    this.imageSet = function imageSet($img_nr) {
        this.$img_current = $img_nr;
        this.imageChange();
        if(this.$first_time) {
            this.$first_time = false;
            this.imageChange();
        }
    }
	
    this.imageChange = function imageChange(){

        if (this.$image_gal[this.$img_current] === undefined) {
            this.$image_gal[this.$img_current] = new Asset.image(this.$image_src[this.$img_current], {
                onload: function () {
                    this.imageShow();
                }.bind(this)
            });
        }
        else {
            this.imageShow();
        }
    }

    this.imageShow = function imageShow() {
        cimg = this.$image_gal[this.$img_current];
        imgh = cimg.height;
        imgw = cimg.width;


        $slt = document.getElementById(this.$img_name);
        $slt.style.backgroundImage = "url(" + cimg.src + ")";
        $slt.style.backgroundPosition = ((250 - imgw) / 2) + "px " + ((200 - imgh) / 2) + "px";
        if (imgh == 200 || imgw == 250) {
            $slt.style.cursor = "pointer";
        }
        else {
            $slt.style.cursor = "default";
        }
    }

    // sitos funkcijos seip nereikia ji padaryta konkreciai www.minus.lt
    this.getCurrent = function getCurrent(){
        return this.$img_current;
    }


    this.displayPreview = function displayPreview() {
        if (this.$imageCache[this.$img_current] === undefined) {
            this.$imageCache[this.$img_current] = new Asset.image(this.$image_src_full[this.$img_current], {
                onload: function() {
                    this.imageDialog();
                }.bind(this)
            });
        }
        else {
            this.imageDialog();
        }
    }


    this.imageDialog = function imageDialog() {
        var imageDialogRenderer = new RendererImage({
            'src': this.$imageCache[this.$img_current].src,
            'cache' : this.$imageCache
        })

        imageDialogRenderer.options.src = this.$imageCache[this.$img_current].src;
        var imageDialog = new Dialog({
            'title': "Nuotrauka",
            'renderer': imageDialogRenderer,
            'id': 'imageDialog',
            'top': "13%"
        });

        if (this.$imageCache[this.$img_current].height > 240 || this.$imageCache[this.$img_current].width > 300) {
            imageDialog.open();
        }
    }
}

