(function() {
    var Y = NB.Lib;
    
    NB.MarsPress.ArticleImageZoom = function(config) {
        NB.MarsPress.ArticleImageZoom.superclass.constructor.apply(this, arguments);

        this.size = config.size;
        this.src = config.src;

        this.button = Y.DOM.byId(this.get("buttonId"));
        if(this.button == null)
        {
            return;
        }

        this.image = Y.DOM.byId(this.get("imageId"));
        this.image.style.cursor = "pointer";
        Y.on("click", this.onClick, this.image, this);


        Y.on("click", this.onClick, this.button, this);


        this.layer = null;

        this.preload = document.createElement("div");
        this.preload.innerHTML = '<img src="' + this.src + '" />';
    };
    
    NB.MarsPress.ArticleImageZoom.NAME = "imageZoom";
    NB.MarsPress.ArticleImageZoom.ATTRS = {
        buttonId : {
            value : ""
        },
        imageId : {
            value : ""
        },
        src : {
            value : ""
        },
        size : {
            value : []
        }
    };

    Y.extend(NB.MarsPress.ArticleImageZoom, Y.Base, {
        getLayer : function() {
            if(this.layer === null)
            {
                this.layer = new NB.UI.Layer();
                this.layer.render("#page");
            }

            return this.layer;
        },
        onClick : function(e) {
            e.halt();
            var layer = this.getLayer();
            layer.set("width", this.size[0] + 10);
            layer.set("content", [
                 '<div class="layer-padding">',
                 '<img src="' + this.src + '" width="' + this.size[0] + '" height="' + this.size[1] + '" title="'+this.image.title+'" />',
                 '</div>'
              ].join("")
            );
            layer.show({
                from: this.image,
                xy : Y.DOM.getXY(this.image.parentNode)
            });
        }
    });
    

})();
