var jvpopup = new Class({
    options:{
        mid:1,
        popupwidth:300,
        popupheight:200,
        distance:20,
        duration:200,
        transition:'linear',
        effect:''
    },
    initialize:function(options){
        this.setOptions(options);
    },
    getMask:function(){
        if(!this.mask){
            this.mask = new Element('div',{
                styles:{
                    'position':'fixed',
                    'width':'100%',
                    'height':'100%',
                    'top':'0',
                    'left':'0',
                    'opacity':'0.8',
                    'z-index':'998',
                    'background':'black'
                }
            }).inject($$('body')[0]);
        }else{
            this.mask.setStyle('display','block');
        }
        return this.mask;
    },
    getPopup:function(){
        var This = this;
        
        var mask = this.getMask();
        mask.addEvent('click',function(){
            this.setStyle('display','none');
            This.getMooEffect('hide');
        });
        if(!this.popup){
            this.popup = $('jvl_popup'+this.options.mid).injectBefore(mask);
            
        }else{
            
        }
        var coorpop = this.popup.getCoordinates();
        this.popup.setStyles({
            'z-index':'999',
            'position':'fixed',
            //'top':'50%',
            'left':'50%',
            'display':'block',
            'visibility':'visible',
            'opacity':'0',
            'background':'white',
            'width':this.options.popupwidth + 'px',
            'height':this.options.popupheight + 'px',
            'margin-top':- coorpop.height / 2,
            'margin-left':- coorpop.width / 2
            
        });
        
        
        this.getMooEffect('show');
        //SqueezeBox.fromElement(this.popup);
        
    },
    getMooEffect:function(status){
        var This = this;
        var coorpop = this.popup.getCoordinates();
        var topos = (screen.height - coorpop.height)/2;
        var mytransition = 'Fx.Transitions.' + This.options.transition;
        if(This.options.transition!='linear'){
            mytransition += '.'+This.options.effect;
        }
        if(Fx.Styles){
            this.fx = new Fx.Styles(this.popup,{transition: eval(mytransition),duration:This.options.duration});
        }else{
            this.fx = new Fx.Morph(this.popup,{transition: eval(mytransition),duration:This.options.duration});
        }
        
        if(status=='show'){
            this.fx.start({
                'opacity':[0,1],
                'top':[topos - This.options.distance,topos]
            });
        }else if(status=='hide'){
            this.fx.start({
                'opacity':[1,0],
                'top':[topos,topos - This.options.distance]
            });
        }
        
    }
});
jvpopup.implement(new Options);
