/*
ConnectorModalBox v0.01 - The lightbox wannabe
by Victor Sumner (http://www.wecreate.com)
Inspired by the original Lightbox v2 by Lokesh Dhakar And Slimbox by Christophe Beyls.
*/

var ModalBox = {

    boxOpen: false,
    box: false,

    init:function( name, options ){
        this.options = $extend({
            initialWidth: 540,
            initialHeight: 600
        }, options || {});
        if( $(name) ){
            this.box = $(name);
        } else {
            alert(name + ' couldn\'t be found!');
        }

        if( this.box && !this.boxOpen ){
            this.overlay = new Element('div', {'id': 'lbOverlay'}).injectInside(document.body);
            this.center = new Element('div', {'id': 'lbCenter', 'styles': {'zindex': '1001','width': this.options.initialWidth, 'height': this.options.initialHeight, 'marginLeft': -(this.options.initialWidth/2), 'display': 'none'}}).injectInside(document.body);
            this.image = new Element('div', {'id': 'lbImage'}).injectInside(this.center);
            this.tempBox = new Element('div', {'id': 'lbContents'}).setHTML(this.box.innerHTML);
            this.tempBox.injectInside(this.image);
            $(name).empty();
            new Element('div', {'styles': {'clear': 'both'}}).injectInside(this.image);
        }
        return this;
    },

    show:function(){
        return this.open();
    },

    open: function(){
        if (this.boxOpen) return;
        this.position();
        this.boxOpen = true;
        //this.setup(true);
        this.top = window.getScrollTop() + (window.getHeight() / 15);
        this.center.setStyles({top: this.top, display: ''});
        return false;
    },

    position: function(){
        /** connectorlocal specific **/
        this.overlay.setStyles({'zindex': '1000','top': '0', 'height': ( $('container4').offsetHeight + 40)});
        /** dynamic **/
        //this.overlay.setStyles({'zindex': '1000','top': window.getScrollTop(), 'height': window.getHeight()});
    },

    close: function(){
        if (!this.boxOpen) return;
        this.boxOpen = false;
        this.overlay.remove();
        this.center.remove();
        return false;
    }

}