var Layer = new Class({

    initialize: function() {
        this.window = $(window);
        this.layer = $(arguments[0]);
        this.layer.setStyles({
            'position': 'absolute',
            'z-index': 999
        });
        this.layer_wrapper = this.layer.getElements('.layerWrapper')[0];
        this.layer.getElements('.closeLayer').each(function(e) {
            e.addEvent('click', this.hide.bind(this));
        }.bind(this));
        this.layer_fx = new Fx.Tween(this.layer, {
            'property': 'opacity',
            'duration': 500
        });

        this.overlay = $('overlay');
        if (this.overlay == null) {
            var size = this.window.getScrollSize();
            this.overlay = new Element('div', {
                'styles': {
                    'background-color': '#000',
                    'display': 'none',
                    'height': size.y,
                    'left': 0,
                    'position': 'absolute',
                    'top': 0,
                    'width': size.x,
                    'z-index': 998
                }
            });
            $(document.body).grab(this.overlay);
        }
        this.overlay_fx = new Fx.Tween(this.overlay, {
            'property': 'opacity',
            'duration': 500
        });
    },

    show: function() {
        var scroll = this.window.getScroll();
        var size = this.window.getSize();
        this.overlay.setStyles({
            'display': 'block',
            'opacity': 0
        });
        this.overlay_fx.start(0.5);
        this.layer.setStyles({
            'display': 'block',
            'opacity': 0,
            'left': scroll.x,
            'top': scroll.y,
            'width': size.x,
            'height': size.y
        });
        this.layer_wrapper.setStyle('margin-top', this.window.getHeight() / 2 - this.layer_wrapper.getSize().y / 2);
        this.layer_fx.start(1);
    },

    hide: function() {
        this.layer.setStyle('display', 'none');
        this.overlay.setStyle('display', 'none');
    }

});

