/**
* Alert Window Js
*
* @version 1.0
*
*/

AlertWindowJs = new Class({

    options:
    {
        windowClass: 'divAlert',
        distantaDeSus: 300,
        closeTimeDelay: 3000,
        autoHide: true,
        mesaj: 'OK',
        butonInchide: true,
        buttonText: 'Închide'
    },

    initialize: function( options )
    {
        this.setOptions( options );

        var scrollatDeSus = ( window.ie ) ? document.body.scrollTop : window.getScrollTop();

        var thatAlertWnd = this;
        this.alertDiv = new Element( 'div',
            {
                'class': thatAlertWnd.options.windowClass
            }
        );

        this.alertDiv.setStyle( 'margin-top', ( scrollatDeSus + this.options.distantaDeSus ) );
        this.alertDiv.set( 'html', '<p>' + this.options.mesaj + '</p>' );
        this.alertDiv.injectTop( document.body );

        if ( this.options.butonInchide )
        {
            var newBt = new Element( 'input',
                {
                    'type': 'button',
                    'value': thatAlertWnd.options.buttonText,
                    'events': {
                        'click': function()
                            {
                                thatAlertWnd.closeAlert();
                            }
                    }
                }
            );
            newBt.inject( this.alertDiv );
        }
    },

    openAlert: function()
    {
        this.alertDiv.setStyle( 'display', 'block' );
        if ( this.options.autoHide )
        {
            var thatAlertWnd = this;
            ( function(){ thatAlertWnd.closeAlert(); } ).delay( this.options.closeTimeDelay );
        }
    },

    closeAlert: function()
    {
        this.alertDiv.setStyle( 'display', 'none' );
        this.alertDiv.destroy();
    },

    setOptions: function()
    {
        this.options = $merge.apply( null, [this.options].extend( arguments ) );
        if ( this.addEvent )
        {
            for ( var option in this.options )
            {
                if ( $type( this.options[option] == 'function' ) && ( /^on[A-Z]/ ).test( option ) ) this.addEvent( option, this.options[option] );
            }
        }
        return this;
    }

});
