var iMaxOverlay = new Object;

iMaxOverlay.WIDGET_NAME = 'IOL_Popup';
iMaxOverlay.CONT_NAME = iMaxOverlay.WIDGET_NAME + '_Container';
iMaxOverlay.BOX_NAME = iMaxOverlay.WIDGET_NAME + '_Box';
iMaxOverlay.BoxObject = '';
iMaxOverlay.ContObject = '';

iMaxOverlay.CloseTimeoutID = 0;
iMaxOverlay.DelayTimeoutID = 0;
iMaxOverlay.TimeToClose = 10; // seconds
iMaxOverlay.TimeTilDelayed = 5; // seconds


iMaxOverlay.SetHTML = function(html) {
	this.ClearTimeouts();
	this.Box().html(html);
}

iMaxOverlay.AppendHTML = function(html) {
	this.Box().append(html);
}

iMaxOverlay.GetOverlay = function() {
	$('body').css('z-index', 0);

	$('body').append('<div id="' + this.CONT_NAME + '"><div id="' + this.BOX_NAME + '"></div></div>');
	this.ContObject = $('#' + this.CONT_NAME);

	this.ContObject.css({
		'background-image': "url('/Maps/Icons/disabled.png')",
		'background-position': '0 0',
		'background-repeat': 'repeat',
		'background-attachment': 'scroll',
		'height':		'100%',
		'left':			'0',
		'top':			'0',
		'width':			'100%',
		'z-index':		'1000',
			 'position':		'fixed',
			 'display': 'none'
	});


	this.BoxObject = $('#' + this.BOX_NAME);

	this.BoxObject.css({
		'width':						'50%',
		'height':					'200px',
		'min-width':				'200px',
		'min-height':				'200px',
		'white-space':				'nowrap',
		'display':					'table',

		'position':					'absolute',
		'left':						'25%',
		'top':						'100px',
		'z-index':					1001,

		'background-color':		'#eeeeee',
		'border':					'2px solid white',
		'padding':					'5px',
		'text-align':				'center'
	});

	this.ContObject.fadeIn('normal');

	this.DisplayLoading();

	return true;
}

iMaxOverlay.CloseTimeout = function() {
	 this.ClearTimeouts();
	 this.CloseTimeoutID = window.setTimeout("iMaxOverlay.Close();", this.TimeToClose * 1000);
}

iMaxOverlay.DelayTimeout = function() {
	 this.ClearTimeouts();
	 this.DelayTimeoutID = window.setTimeout("iMaxOverlay.LoadingDelayed();", this.TimeTilDelayed * 1000);
}

iMaxOverlay.ClearTimeouts = function() {
	 if( this.CloseTimeoutID ) {
		  window.clearTimeout(this.CloseTimeoutID);
		  this.CloseTimeoutID = 0;
	 }

	 if( this.DelayTimeoutID ) {
		  window.clearTimeout(this.DelayTimeoutID);
		  this.DelayTimeoutID = 0;
	 }
}

iMaxOverlay.LoadingDelayed = function() {
	 this.SetHTML('<div class="sl" align="center">Popup screen timed out.<br />This will close automatically in 10 seconds.<br /><a href="javascript:iMaxOverlay.Close();">Click here to close popup</a><script>iMaxOverlay.CloseTimeout();</script>');
}

iMaxOverlay.DisplayLoading = function() {
	 this.SetHTML('<div class="sl" align="center"><br /><br />Loading...<br /><img src="/images/progress.gif" /></div><script>iMaxOverlay.DelayTimeout();</script>');
}

iMaxOverlay.Container = function() {
	return this.ContObject;
}

iMaxOverlay.Box = function() {
	return this.BoxObject;
}

iMaxOverlay.ContainerName = function() {
	return this.CONT_NAME;
}

iMaxOverlay.BoxName = function() {
	return this.BOX_NAME;
}

iMaxOverlay.Close = function() {
	 this.ContObject.fadeOut('normal');
	 window.setTimeout('iMaxOverlay.ContObject.remove();', 500);
}

