
importPackage( 'corelib/services/web/javascript/jwt/InternalFrame.js' );

/**
 * <p>
 *     This class displays a light box container that appears on top of other page elements.
 * </p>
 * <p>
 *     Supported events are <code>onBoxOpened</code> and <code>onBoxClosed</code>
 * </p>
 * 
 * @author Dominique Liard
 * @since 0.3.7
 */
var LightBox = Component.extendClass( {

	initialize: function ( decorated ) {
		Component.prototype.initialize.call( this );
		this._decorated = arguments.length == 0 ? true : decorated;
		this.htmlTag.className = "JwtLightBox";
		if ( navigator.isInternetExplorer ) {
			this.htmlTag.style.filter = "alpha(opacity = 50)";
		}
		this.setVisible( false );

		if ( this._decorated ) {
			this._contentPane = new InternalFrame();
			this._contentPane._lightBox = this;
			addEventHandler( this._contentPane, "onWindowClosed", function( event ) {
				this._lightBox.setVisible( false );
			});
		} else {
			this._contentPane = new Container();
		}
		this._contentPane.htmlTag.className = "JwtLightBoxContentPane";
		
		this.injectInDocument( document.body );
		this._contentPane.injectInDocument( document.body );
		this._contentPane.setLocationRelativeTo( document.body );
	},


	isDecorated : function() {
		return this._decorated;
	},

	
	/**
	 * @since 0.4.0
	 */
	setTitle : function( newTitle ) {
		if ( this._decorated ) {
			this._contentPane.setTitle( newTitle );
		}
	},
	
	
	/**
	 * @since 0.4.0
	 */
	setSize : function( width, height ) {
		this._contentPane.setSize( width, height );
	},
	
	/**
	 * @since 0.4.0
	 */
	getContentPane : function( component ) {
		if ( this._decorated ) {
			return this._contentPane.getContentPane( component );
		} else {
			return this._contentPane;
		}
	},

	
	setVisible : function( /* boolean */ status ) {
		Component.prototype.setVisible.call( this, status );
		if ( this._contentPane == null ) return;
		
		if ( this._decorated == false ) this._contentPane.setVisible( status );
		this._contentPane.setLocationRelativeTo( document.body );
	}

});
