if ( Object.isUndefined(Klean) ) { var Klean = { }; }

Klean.Overlay = Class.create({
	log: function(str) {
		site.log('[Overlay] '+str);
	},
	initialize: function(overlayId, options)
	{
		this.options = Object.extend({
			background:		'#ffffff',
			opacity:		0.75,
			observeResize:	true
		}, options || { });

		this.body = document.getElementsByTagName('body');
		this.body = $(this.body[0]);
		
		this.id = overlayId;
		this.overlay = null;

		this.height = 0;
		this.width = 0;
	},
	
	show: function()
	{
		if ( !this.overlay )
		{
			this.overlay = new Element('div', { id: this.id });
			this.overlay.setStyle({
				'display': 'none',
				'backgroundColor': this.options.background,
				'position': 'absolute'
			});	

			this.body.insert(this.overlay);
			
			this.setSize();
			this.overlay.setOpacity(this.options.opacity);
		}
		if (this.options.observeResize) {
			Event.observe(window, 'resize', this.onResize.bindAsEventListener(this));
		}
		this.overlay.show();
	},
	
	hide: function()
	{
		if ( this.overlay )
		{
			this.overlay.hide();
			if (this.options.observeResize) {
				Event.stopObserving(window, 'resize', this.onSesize.bindAsEventListener(this));
			}
		}
	},

	setSize: function(width,height)
	{
		if ((undefined===height) || (undefined===width)) {
			var vpDim = document.viewport.getDimensions();
			var bdDim = this.body.getDimensions();
			if (undefined===width) { width = vpDim.width; }
			if (undefined===height) { height = Math.max(vpDim.height, bdDim.height); }
		}

		this.overlay.setStyle({
			top:	'0',
			left:	'0',
			height:	'' + height + 'px',
			width:	'' + width + 'px'
		});

		// For external reference
		this.width = width;
		this.height = height;

	},
	
	onResize: function(e) {
		this.setSize.bind(this).defer();
	}
});
