
function ModalBox() {


    this.getContainer = function() {

        if( $('modalbox' ) == null ) {
            var d = document.createElement('div');
            d.className = 'modal';
            d.setAttribute('id', 'modalbox');
            d.style.width = 'auto';
            d.style.height = 'auto';
            d.style.display = 'none';
            d.style.position = 'fixed';
            d.style.zIndex =  1000;
            d.style.left = 0;
            d.style.top = 0;

            document.body.appendChild( d );
        }

        return $('modalbox');
    }

    this.makeOverlay = function() {
        if ( $('overlay') ) {
            $('overlay').setStyle( {
                'width':  document.body.offsetWidth + 'px',
                'height':  document.body.offsetHeight + 'px'
            } );
            Effect.Appear( $('overlay'), {
                duration: 0.3,
                from: 0.0,
                to: 0.25
            } );

        }
    }

    this.makePosition = function() {
        
        var g = this.getContainer();

        var wh = 0;
        var ww = 0;
        if ( Prototype.Browser.IE == true ) {
            wh = parseInt(screen.availHeight);
            ww = parseInt(screen.availWidth);
        }
        else {
            wh = parseInt(window.innerHeight);
            ww = parseInt(window.innerWidth);
        }

        var gh = parseInt( g.getHeight() );
        var gw = parseInt( g.getWidth() );

        var x  = parseInt( (ww-gw) / 2 );
        var y  = parseInt( (wh-gh) / 2 );

        g.setStyle({
            top: y + 'px',
            left: x + 'px'
        });
    }

    this.displayContainer = function() {
        this.getContainer().setStyle({
            display     : 'block'
        });
        
    }

    this.showText = function( text ) {
        this.makeOverlay();
        this.getContainer().update(text);

        this.makePosition();
        this.displayContainer();

    }

    this.close = function() {
         $('modalbox' ).setStyle({display:'none'});
    }

     $('overlay').observe( 'click', function() {
         $('modalbox' ).setStyle({display:'none'});
     });
}


ModalBox.show = function(text) {
    var mb = new ModalBox();
    mb.showText( text );
}




Event.observe(window, 'load', function() {
    var modal = new Control.Modal('/static/notLogged',{
        overlayOpacity: 0.25,
        className: 'modal',
        fade: false  ,
        closeOnClick: true
    });
    $$('a.profil').each(function(elem) {
        elem.writeAttribute('onclick','');
        Event.observe(elem, 'click', function(event) {
            modal.open();
            event.stop();
        });
    });
}); 




