/*********************************************************************************************
* Module: bmalloc.js
* Date: July 21, 07
* Author: Bmalloc Studio
* Purpose: An extention js library based on Prototype && Script Aculo
* Requirment: Must have Prototype && Script Aculo pre-included.
* Documentation: http://www.bmalloc.com/wiki/
* Modified History: Null
*********************************************************************************************/

Popup = Class.create(); 
Popup.prototype = {
    initialize: function(){
        this.div = 'popup';
        this.effect = Effect.Appear;
        this.close_effect = Effect.Fade;
        this.default_opt = {
            width: 300,
            height: 300,
            leftOffset: 0,
            topOffset: -100 //A good esitimate of the height of a client brower
        };
        this.opt = null;
    },
    
    //get current document screen height
    getPageHeight: function(){
        var yScrolltop;
        if (self.pageYOffset) {
            yScrolltop = self.pageYOffset;
        } else if (document.documentElement && document.documentElement.scrollTop){    // Explorer 6 Strict
            yScrolltop = document.documentElement.scrollTop;
        }else if (document.body) {// all other Explorers
            yScrolltop = document.body.scrollTop;
        }
        return yScrolltop;
    },
    
    //set default style
    setStyle: function(){
        var pageHeight = this.getPageHeight() + screen.height/2 - this.opt.height/2;
        var left_pos = screen.width/2 - this.opt.width/2;
        $(this.div).setStyle({
          height: this.opt.height + 'px',
          width: this.opt.width + 'px',
          left: left_pos + this.opt.leftOffset + 'px',
          top: pageHeight + this.opt.topOffset + 'px'
        });
    },
    
    createPopup: function(){
        //set popup style
        this.setStyle();
        new this.effect(this.div, this.opt);
    },
    
    closePopup: function(){
        new this.close_effect(this.div, this.opt);
    }
};

Popup.Static = Class.create();

Popup.Static.prototype = Object.extend(new Popup(),{
    initialize: function(div, effect, opt) {
        if(div) this.div = div;
        if(effect) this.effect = effect;
        this.opt = $H(this.default_opt).merge(opt);  
        this.createPopup();
    } 
});

Popup.Close = Class.create();
Popup.Close.prototype = Object.extend(new Popup(),{
    initialize: function(div, effect, opt) {
        if(div) this.div = div;
        if(effect) this.close_effect = effect; 
        this.opt = $H(this.default_opt).merge(opt);
        this.closePopup();
    }
});