var Popup = {
    loading: function()
    {
        this.setOverlaySize();
        Element.show('popup_overlay');
        Event.observe('popup_overlay', 'click', this.close);
        $('popup_frame').style.display = "block";
        this.setWindowPosition();
    },
        
    complete: function()
    {
        Element.scrollTo('popup_window');
        this.setWindowPosition();
        Element.show('popup_window');
    },
        
    close: function()
    {
        Element.hide('popup_window');
        Element.hide('popup_overlay');
        $('popup_frame').style.display = "none";
    },

    setOverlaySize: function()
    {
        if (window.innerHeight && window.scrollMaxY)
        {  
            yScroll = window.innerHeight + window.scrollMaxY;
        } 
        else if (document.body.scrollHeight > document.body.offsetHeight)
        { // all but Explorer Mac
            yScroll = document.body.scrollHeight;
        }
        else if(window.innerHeight > document.body.offsetHeight)
        {
            yScroll = window.innerHeight;
        }
        else
        { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
            yScroll = document.body.offsetHeight;
        }
        $("popup_overlay").style['height'] = yScroll +"px";
    },

    setWindowPosition: function()
    {
        var pagesize = this.getPageSize();  

        $("popup_window").style['width'] = 'auto';
        $("popup_window").style['height'] = 'auto';
 

        var dimensions = Element.getDimensions($("popup_window"));
        var width = dimensions.width;
        var height = dimensions.height;  

        $("popup_frame").style['width'] = dimensions.width + "px";
        $("popup_frame").style['height'] = dimensions.height + "px";        

        $("popup_window").style['left'] = ((pagesize[0] - width)/2) + "px";
        $("popup_window").style['top'] = ((pagesize[1] - height)/2) + "px";
        $("popup_frame").style['left'] = ((pagesize[0] - width)/2) + "px";
        $("popup_frame").style['top'] = ((pagesize[1] - height)/2) + "px";
    },

    getPageSize: function() {
        var de = document.documentElement;
        var w = window.innerWidth || self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
        var h = window.innerHeight || self.innerHeight || (de&&de.clientHeight) || document.body.clientHeight;

        arrayPageSize = new Array(w,h) 
        return arrayPageSize;
    }
}