/*
	(c) 2007-2008 | http://olegrorovin.spb.ru/
	Author - Oleg Korovin (mail@olegrorovin.spb.ru)
*/

var Veil = {

	elLayer		: null,
	bMiddle		: false,

 /******************************************************************************/
	show			: function(sLayer,bMiddle){
		var oThis = this;
		oThis.elLayer = $(sLayer);
		oThis.bMiddle = bMiddle || 0;

		if(!oThis.elLayer) return;

		oThis._show();
	},

 /******************************************************************************/
	hide			: function(e){
		var oThis = this;
		winPopup.close(e);
	},


 /******************************************************************************/
	_show	: function(event){
		var
			oThis = this,
			elLayer = oThis.elLayer;

		winPopup.show(
			event,
			_layerShow,
			_layerHide
		);

		function _layerShow(){
			elLayer.style.top = '0';
			Styles.show(elLayer);
			oThis.setSize();
			Styles.vis(elLayer);
		};
		function _layerHide(){
			Styles.hide(elLayer);
			Styles.invis(elLayer);
			$$('body')[0].style.height = '';
			elLayer.style.height = '';
		};
	},


 /******************************************************************************/
	setSize	: function(){
		var
			oThis = this,
			elLayer = oThis.elLayer;

		elLayer.style.height = 'auto';
		elLayer.style.overflow = 'visible';

		if(oThis.bMiddle) oThis.middle();

		var iHeight = Math.max(document.documentElement.scrollHeight,elLayer.offsetHeight);
		elLayer.style.height = iHeight + 'px';
		$$('body')[0].style.height = iHeight + 'px';
		elLayer.style.overflow = 'hidden';
	},


 /***************************************/
	middle	: function(){
		var elContent = this.elLayer.firstChild;
		elContent.style.marginTop = scrollTop() + Math.round( Math.max(document.documentElement.clientHeight - elContent.offsetHeight,0) / 2) + 'px';
	},


 /***************************************/
	content	: function(sHTML){
		var elContent = this.elLayer.firstChild;
		elContent.innerHTML = sHTML;
		if(this.bMiddle) this.middle();
		this.setSize();
	},


 /***************************************/
	loader	: function(bLoader){
		this.elLayer.style.cursor = bLoader ? 'wait' : '';
	}

};



