/*======================================================================*\
|| #################################################################### ||
|| #  				  Imperial Bulletin Board v1.x                    # ||
|| # ---------------------------------------------------------------- # ||
|| #  For license, version and changelog questions or concerns,       # ||
|| #  navigate to the docs/ folder or visit the forums at the		  # ||
|| #  website, http://www.imperialbb.com/forums. with your questions. # ||
|| # ---------------------------------------------------------------- # ||
|| # Name: js_msgbox.js                                               # ||
|| # ---------------------------------------------------------------- # ||
|| #                "Copyright(c) 2007 The iBB Group"                 # ||
|| # ---------------------------------------------------------------- # ||
|| #################################################################### ||
\*======================================================================*/

function ibb_msg_box ( )
{
	var message			= '';
	var transparentDiv  = '';
	var contentDiv		= '';
	var shadowDiv		= '';
	var iframe			= '';
	var width			= '';
	var height			= '';
	var messageBoxCss	= '';
	var shadowOffset	= '';
	this.message 		= '';
	this.width 			= 400;
	this.height 		= false;
	this.messageBoxCss  = false;
	this.shadowOffset 	= 5;

	this.set_content = function ( content )	
	{
		this.message = content;
	};
	
	this.set_msgbox_class = function ( classname ) 
	{
		this.messageBoxCss = classname;
	};

	this.set_size = function ( w, h )
	{
		this.width  = IBB.general.ifelse ( !w, false, w );
		this.height = IBB.general.ifelse ( !h, false, h );
	};

	this.set_url = function ( x )
	{
		
	};

	this.display_content = function ( )
	{
		if ( !this.contentDiv )
		{
			this.init_divs ( );
		}
		if ( this.transparentDiv ) 
		{
			IBB.general.show_stuff ( this.transparentDiv );
		}
		IBB.general.show_stuff ( this.contentDiv );
		if ( this.shadowDiv ) 
		{
			IBB.general.show_stuff ( this.shadowDiv );
		}
		if ( IBB.is_ie ) 
		{
			IBB.general.show_stuff ( this.iframe );
		}
		this.contentDiv.innerHTML = this.message;
		this.resize_divs ( );
		var obj = this;
		setTimeout ( 'obj.resize_divs ( )', 150 );
	};

	this.close_content = function ( )
	{
		IBB.general.hide_stuff ( this.contentDiv );
		if ( this.shadowDiv ) 
		{
			IBB.general.hide_stuff ( this.shadowDiv );
		}
		if ( this.transparentDiv )
		{
			IBB.general.hide_stuff ( this.transparentDiv );
		}
		if ( IBB.is_ie )
		{
			IBB.general.hide_stuff ( this.iframe );
		}
	};

	this.init_divs = function ( )
	{
		if ( !( this.transparentDiv = $ ( 'message_transparent' ) ) || !( this.contentDiv = $ ( 'message_content' ) ) ) 
		{
throw ( 'Boo');
			return false;
		}
		this.shadowDiv = $ ( 'message_shadow' );
		if ( IBB.is_ie ) 
		{
			this.iframe = $ ( 'message_iframe' );
		}
		var obj = this;
		IBB.dom.add_event ( window, 'scroll', 			
			function ( e )
			{
				obj.resize_divs ( )
			}
		);
		IBB.dom.add_event ( window, 'resize', 			
			function ( e )
			{
				obj.resize_divs ( )
			}
		);
	};

	this.resize_divs = function ( )
	{
		if ( !this.transparentDiv ) 
		{
			return false;
		}
		var dE 					  = document.documentElement;
		var dB 					  = document.body;
		this.contentDiv.className = IBB.general.ifelse ( !this.messageBoxCss, 'message_content', this.messageBoxCss );
		var st = IBB.general.fetch_scroll_y ( );
		var sl = IBB.general.fetch_scroll_x ( );
		window.scrollTo ( sl, st );
		setTimeout ( 'window.scrollTo ( '+sl+', '+st+' );', 10 );
		this.transparentDiv.style.top  = st+'px';
		this.transparentDiv.style.left = sl+'px';
		var bodyWidth = IBB.general.fetch_body_width ( );
		var bodyHeigh = IBB.general.fetch_body_height ( );
		this.transparentDiv.style.width  = bodyWidth+'px';
		this.transparentDiv.style.height = bodyHeight+'px';
		if ( this.width )
		{
			this.contentDiv.style.width = this.width+'px';
		}
		if ( this.height ) 
		{
			this.contentDiv.style.height = this.height+'px';
		}
		var divWidth 				= this.contentDiv.offsetWidth;
		var divHeight 				= this.contentDiv.offsetHeight;
		var contentLeft 			= Math.ceil ( ( bodyWidth-divWidth )/2 );
		var contentTop 				= ( Math.ceil ( ( bodyHeight-divHeight)/2 )+st );
		this.contentDiv.style.left 	= contentLeft+'px';
		this.contentDiv.style.top 	= contentTop+'px';
		if ( IBB.is_ie )
		{
			this.iframe.style.left 	 = contentLeft+'px';
			this.iframe.style.top 	 = contentTop+'px';
			this.iframe.style.width  = divWidth+'px';
			this.iframe.style.height = divHeight+'px';
		}
		if ( this.shadowDiv )
		{
			this.shadowDiv.style.left 	= ( contentLeft+this.shadowOffset )+'px';
			this.shadowDiv.style.top 	= ( contentTop+this.shadowOffset )+'px';
			this.shadowDiv.style.width 	= divWidth+'px';
			this.shadowDiv.style.height = divHeight+'px';
		}
	};
};
var msgbox = new ibb_msg_box ( );

function ibb_msg_display ( )
{
	if ( typeof ( this.msgbox ) !== 'object' )
	{
		this.msgbox = new ibb_msg_box ( );
	}
	else
	{
		this.msgbox = msgbox;
	};

	this.display_msg = function ( msg, id, classname, width, height )
	{
		if ( msg ) 
		{
			content = msg;
		}
		else if ( ( id && ( content = $ ( id ) ) ) || ( content && content.innerHTML ) )
		{
			content = content.innerHTML;
		}
		else 
		{
			return false;
		}
		this.msgbox.set_content ( content );
		this.msgbox.set_url ( false );
		this.msgbox.set_msgbox_class ( classname );
		this.msgbox.set_size ( width, height );
		this.msgbox.display_content ( );
	};

	this.close_msg = function ( ) 
	{ 
		this.msgbox.close_content ( ); 
	};
};
IBB.namespace ( 'msgbox' );
IBB.msgbox = new ibb_msg_display ( );

/*======================================================================*\
|| #################################################################### ||
|| #                "Copyright(c) 2007 The iBB Group"                 # ||
|| #################################################################### ||
\*======================================================================*/