var Modal = new Class({
    initialize: function(options){
        if($type(options.element) != 'object')
            options.element = $(options.element); 
        this.options = $merge({
        	//id: 'modal',
            backgroundColor: '#fff',
            startOpacity: 0,
            zIndex: 0,
            duration: 80,
            fps: 200,
            onComplete: Class.empty,
            endOpacity: 1.0
        }, options);
        this.element = options.element;
        this.isWindow = (this.element == window) ? true : false;
        if(!this.isWindow){
            var size = this.element.getSize();
            //var pos = this.element.getPosition();
            this.left = this.element.offsetLeft;
            this.top = this.element.offsetTop;
            this.width = size.size.x;
            this.height = size.size.y;
        }
        this.parentEl = this.isWindow ? document.body : this.element.getParent(); 
        this.overlay = new Element('div', {
        	//id: this.options.id,
            styles: {
                width: this.isWindow ? window.getWidth() : this.width,
                height: this.isWindow ? window.getScrollHeight() : this.height,
                backgroundColor: this.options.backgroundColor,
                left: this.isWindow ? 0 : this.left,
                top: this.isWindow ? 0 : this.top,          
                opacity: this.options.startOpacity,
                mozOpacity: this.options.startOpacity,
                filter: 'alpha(opacity=' + (100 - parseInt(this.options.startOpacity * 100)) + ')',
                position: 'absolute',
                zIndex: this.options.zIndex         
            }
        });
        this.fx = new Fx.Style(this.overlay, 'opacity', 
            {
                duration: this.options.duration, 
                fps: this.options.fps,
                onComplete: this.options.onComplete
            }
        );      
    },
    set: function(){
        var overlay = this.overlay;
        overlay.injectInside(this.parentEl);
        if(this.isWindow)
            window.addEvent('resize', function() {
                overlay.setStyles({
                    width: window.getWidth(),
                    height: window.getScrollHeight()
                });
            });
        this.fx.start(0, this.options.endOpacity); 
        
    },
    reset: function(){
        this.fx.start(this.options.endOpacity, 0);
    },
    remove: function(){
        this.overlay.remove();
    }
});





