/**
* SimplePopupWindow
*
* Constructor for a SimplePopupWindow
*
* The popup window is a composite of four WidgetSegments, a header, a body, a control bar, and a trailer, all within a single window widget
* segment.  
*
* @param id
* @param name
* @param style_set
*	 -style_set_spw_container
*		-_sw
*		-_sw_container
*	 -style_set_spw_header
*		-_smdmubw_out
*		-_smdmubw_out_container
*		-_smdmubw_over
*		-_smdmubw_over_container
*	 -style_set_spw_body
*		-_sw
*		-_sw_container
*	 -style_set_spw_control_bar
*		-_sw
*		-_sw_container
*		-_twl_table
*		-_twl_table_body
*		-_twl_row
*		-_twl_cell
*	 -style_set_spw_footer
*		-_sw
*		-_sw_container
* @param start_height
* @param start_width
* @param hf_height
* @param closable Boolean value denoting whether or not the popup window should be build with a close button.
* @param resizable Boolean value denoting whether or not the popup window should be built with a resize button.  NOT IMPLEMENTED
* @param hight_is_min Determines whether the height value is absolue or if it is the minimum height
**/
function SimplePopupWindow ( 
	id ,
	name , 
	style_set , 
	start_height , 
	start_width ,
	hf_height ,
	closable , 
	resizable ,
	height_is_min
) { 

	this.style_set = style_set; 

	this.name = name;
	this.closable = closable;

	this.start_height = start_height;
	this.start_width = start_width;

	//create and style the various pieces of the popup window
	this.container = new SimpleWidgetFactory( this.style_set + "_spw_container" ).build();
	this.header = new SimpleMouseDownMouseUpButtonWidgetFactory( this.style_set + "_spw_header" ).build();
	this.body = new SimpleWidgetFactory( this.style_set + "_spw_body" ).build();
	this.control_widget = new SimpleWidgetFactory( this.style_set + "_spw_control_bar" ).build();
	this.control_bar = new TabularWidgetLayoutFactory( this.style_set + "_spw_control_bar", 5 ).build();
	this.footer = new SimpleWidgetFactory( this.style_set + "_spw_footer" ).build();

	//set heights of header, footer, and body
	this.header.setWidgetHeight( hf_height );
	this.footer.setWidgetHeight( hf_height );

	//calculate the body height as the start_height - 2x the hf_height
	var body_height = parseInt( start_height ) - ( 2* parseInt( hf_height ) );

	if ( height_is_min )
		this.body.setWidgetStyle( "minHeight", body_height );
	else
		this.body.setWidgetHeight( body_height );

	//set widths
	this.container.setWidgetWidth( start_width );

	this.container.addContentNode( this.header.getWidgetDOM() );
	this.container.addContentNode( this.body.getWidgetDOM() );

	//add a status widget
	this.status_widget = new StatusWidget( "status" );

	this.control_widget.addContentNode( this.status_widget.getWidgetDOM() );

	this.control_widget.addContentNode( this.control_bar.getDOM() );

	this.container.addContentNode( this.control_widget.getWidgetDOM() );
	this.container.addContentNode( this.footer.getWidgetDOM() );

	//set the starting position
	this.container.setWidgetStyle( "position", "absolute" );
	this.container.setWidgetStyle( "left" , 10 );
	this.container.setWidgetStyle( "top" , 10 );

}

new SimplePopupWindow( null, null, null, 200, 200, 15, null, null, null );

/**
* SimplePopupWindow.addControlButton
*
* Add a control button to the control_bar of the PopupWindow
*
* @param button The control button to add
**/
SimplePopupWindow.prototype.addControlButton = function( button ) {

	this.control_bar.addWidget( button );

}

/**
* PopupWindow.getDOM
* 
* @return The DOM object associated with the PopupWindow object
**/
SimplePopupWindow.prototype.getDOM = function() { 

	return this.container.getWidgetDOM();

}

/**
* SimplePopupWindow.clearStatus
*
* Clear the status widget
**/
SimplePopupWindow.prototype.clearStatus = function() { 

	this.status_widget.hideWidget();

}

/**
* SimplePopupWindow.setStatusToWorking
*
* Populates the status field with a working image and message
*
* @param msg
**/
SimplePopupWindow.prototype.setStatusToWorking = function ( msg ) { 

	this.status_widget.setStatus( "working", msg );

}

/**
* SimplePopupWindow.setStatusToFailed
*
* Populates the status field with a failed image and message
*
* @param msg
**/
SimplePopupWindow.prototype.setStatusToFailed = function ( msg ) { 

	this.status_widget.setStatus( "failure", msg );

}

/**
* SimplePopupWindow.setPosition
*
* @param top
* @param left
**/
SimplePopupWindow.prototype.setPosition = function( top, left ) { 

	this.container.setWidgetStyle( "left", left );
	this.container.setWidgetStyle( "top", top );

}

/**
* SimplePopupWindowFactory
*
* A factory for simple popup windows
*
* @param id
* @param name
* @param popup_style_set
* 	 -
* @param start_height
* @param start_width
* @param hf_height The height of the header and footer of the popup window
* @param closable Boolean
* @param resizable Boolean (not implemented)
* @param height_is_min Boolean determines whether to treat starting height as absolute height or min height
**/
function SimplePopupWindowFactory ( 
	id ,
	name , 
	popup_style_set , 
	start_height , 
	start_width ,
	hf_height ,
	closable , 
	resizable ,
	height_is_min
) {

	this.id = id;
	this.name = name;
	this.popup_style_set = popup_style_set;
	this.start_height = start_height || 200;
	this.start_width = start_width || 200;
	this.hf_height = hf_height || 15;
	this.closable = closable;
	this.resizable = resizable;
	this.height_is_min = height_is_min

}

new SimplePopupWindowFactory();

SimplePopupWindowFactory.prototype.build = function() { 

	return new SimplePopupWindow( 
		this.id ,
		this.name ,
		this.popup_style_set ,
		this.start_height ,
		this.start_width ,
		this.hf_height ,
		this.closable ,
		this.resizable ,
		this.height_is_min 
	);

}
	











