
var Class = {
   create: function() {
     return function() {
return this;
     }
   }
 } 	
var overlayClass = Class.create();
overlayClass.prototype = {
	
	alertId			: 'alternative_address_box',
	backgroundId	: 'sc_frm',
	overlay			: null,
	coef 			: 1,
	
	setPosition : function()
	{
//		eval('$( \'#'+this:backgroundId+'\' ).css( { width : screen.availWidth + "px", height : screen.availHeight + "px" } ); ');
		$( '#' + this.backgroundId ).css( { width : screen.availWidth + 'px', height : screen.availHeight + 'px', position : 'fixed' } );
//		return;
		var left = parseInt( $( 'body' ).css().width() / 2 ) - parseInt( $( '#' + this.alertId ).css().width() / 2 );
		var top = parseInt( screen.availHeight / 2 ) - parseInt( $( '#' + this.alertId ).css().height() * this.coef );
		if( top < 0 ) top = 0;
		
//				alert( $( 'body' ).css().height() );
		$( '#' + this.alertId ).css( { left :  left + 'px', top : top + 'px', display : 'block', position : 'fixed' } );
		
	},
	
	show : function( width )
	{
		if( !( !width ) )
		{
			$( '#' + this.alertId ).css( { width : width + 'px' } );
		}
		this.setPosition();
		
//		this.overlay.load();
		
		$( '#' + this.backgroundId ).show();
		$( '#' + this.alertId ).show();
		this._reposition();
//		this.overlay.onLoad = function(){ 
//			$( '#backOv' ).css( { display : 'none' } ); 
//			$( '#overlay' ).css( { background : '#2c2c2c url(/_images/bg_overlay.jpg) repeat top left' } ); 
//		}
	},
	
	init : function(backgroundId,alertId)
	{
		this.alertId = alertId;
		this.backgroundId = backgroundId;
		this._maintainPosition();
	},
	
	close : function()
	{
//		this.overlay.close();
				$( '#' + this.backgroundId ).hide();
				$( '#' + this.alertId ).hide();
		
	},
	
	_reposition: function() {
//			alert(this.alertId);
//			alert($(window).height()/2);
//			alert($("#"+ this.alertId ).outerHeight()/2);
//			alert($.alerts.verticalOffset);
			
			var top = (($(window).height() / 2) - ($("#"+ this.alertId ).outerHeight() / 2));
			var left = (($(window).width() / 2) - ($("#"+ this.alertId ).outerWidth() / 2));
			if( top < 0 ) top = 0;
			if( left < 0 ) left = 0;
//			alert(top);
			// IE6 fix
			if( $.browser.msie && parseInt($.browser.version) <= 6 ) top = top + $(window).scrollTop();
			$("#"+ this.alertId ).css({
				top: top + 'px',
				left: left + 'px'
			});
			$("#"+ this.backgroundId).height( $(document).height() );
		},
		
		_maintainPosition: function() {
			
						$(window).bind('resize', function() {
							overlayClass.prototype._reposition();
						});
				
		}
}

var tAlert = new overlayClass();
