var overlayClass = jQuery.Class.create({
	init : function( sVariable, backgroundId, alertId )
	{
		this.sVariable = sVariable;
		document.body.appendChild( document.getElementById( alertId ) );
		document.body.appendChild( document.getElementById( backgroundId ) );
		this.oBg = jQuery( '#' + backgroundId );
		this.oAlert = jQuery( '#' + alertId );
		this.oContent = jQuery( '#' + alertId + '_content' );
		
		this.sPosition = '';
		this.sSource = '';
		this.sSourceDiv = '';
		this.bShowed = false;
		
		this.sPosition = this.oAlert.css( 'position' );
		if( this.sPosition != 'fixed' && this.sPosition != 'absolute' )
		{
			this.oAlert.css( { 'position' : 'absolute' } );
			this.sPosition = 'absolute';
		}
		this._maintainPosition();
		this.setPosition();
	},
	
	
	setPosition : function()
	{
		if( !overlayClass.bShowed ) return;
		
		var left = 0, top = 0;
		left = parseInt( jQuery( 'body' ).width() / 2 ) - parseInt( this.oAlert.width() / 2 );
		top = parseInt( jQuery( window ).height() / 2 ) - parseInt( this.oAlert.height() / 1.5 );
		left = ( left < 0 ? 0 : left );
		top = ( top < 0 ? 0 : top );
		
		if( this.sPosition == 'absolute' || ( jQuery.browser.msie && parseInt( jQuery.browser.version ) <= 6  ) ) top = top + jQuery( window ).scrollTop();
//		 screen.availHeight
		
		this.oAlert.css( { left :  left + 'px', top : top + 'px' } );
	},
	
	open : function( sSourceDiv, iWidth )
	{
		if( overlayClass.bShowed ) return;
		overlayClass.bShowed = true;
		
		overlayClass.sSourceDiv = sSourceDiv;
		this.oContent.html( jQuery( "#" + sSourceDiv ).html() );
		jQuery( "#" + sSourceDiv ).html( '' );
				
		if( !( !iWidth ) ) this.oAlert.css( { width : iWidth + 'px' } );
		
		this.oBg.show();
		this.oAlert.show();
		
		this.setPosition();
	},
	
	close : function()
	{
		if( !overlayClass.bShowed ) return;
		overlayClass.bShowed = false;

		jQuery( '#' + overlayClass.sSourceDiv ).html( this.oContent.html() );
		
		this.sSource = '';
		this.oBg.hide();
		this.oAlert.hide();
	},
	
	_maintainPosition : function() {
		eval( "jQuery( window ).bind( 'resize', function() { " + this.sVariable + ".setPosition(); } );" );
		eval( "jQuery( window ).bind( 'scroll', function() { " + this.sVariable + ".setPosition(); } );" );
	}
} );
