var tf_SHADOW = 
{
	shadowID: 'shadow',
	visibled: false,
	zIndex: 1000,
	
	show: function(fn)
	{
		if(!this.visibled)
		{
			var bodyObj = tf_DOM.$_tag('body')[0];
			
			var cObj = tf_DOM.$(this.shadowID);
			if(!cObj)
			{
				cObj = tf_DOM.CE('div', this.shadowID);
				tf_DOM.AE(cObj, bodyObj);
			}
			
			cObj.style.position = 'absolute';
			cObj.style.zIndex = this.zIndex;
			cObj.style.left   = '0px';
			cObj.style.top = '0px';
			
			var wh = tf_DOM.get_WH(bodyObj);
			cObj.style.width = wh[0] + 'px';
			cObj.style.height = wh[1] + 'px';
			
			cObj.style.backgroundColor = '#000';
			//cObj.style.cssText = '';
			
			var obj = this;
			tf_DOM.SAE(cObj, '', 0, 60, 10, 50, function(){ obj.visibled = true; if(typeof fn == 'function') fn(); });
		}
	},
	
	hide: function(fn)
	{
		var cObj = tf_DOM.$(this.shadowID);
		if(cObj)
		{
			var obj = this;
			tf_DOM.HAE(cObj, '', 60, 0, 10, 50, function(){ tf_DOM.RE(cObj); obj.visibled = false; if(typeof fn == 'function') fn(); });
		}
	},
	
	init: function()
	{
		var obj = this;
		tf_DOM.addEvent(document, 'click', function(){ if(obj.visibled) obj.hide(); }, false);
	}
};

//tf_SHADOW.init();


var tf_POPUP = 
{
	popupID: 'popup',
	popupWidth: 600,
	popupHeight: 400,
	visibled: false,
	clicked: false,
	zIndex: 1001,
	
	show: function(fn)
	{
		if(!this.visibled)
		{
			var bodyObj = tf_DOM.$_tag('body')[0];
		
			var cObj = tf_DOM.$(this.popupID);
			if(!cObj)
			{
				cObj = tf_DOM.CE('div', this.popupID);
				tf_DOM.AE(cObj, bodyObj);
			}
			
			cObj.className = 'popup';
			
			cObj.style.position = 'absolute';
			cObj.style.zIndex = this.zIndex;
			
			var center = tf_DOM.get_WCenter([this.popupWidth, this.popupHeight]);
			cObj.style.left   = center[0] + 'px';//'100px';
			cObj.style.top = center[1] + 'px';//'300px';
			
			cObj.style.width = this.popupWidth + 'px';
			cObj.style.height = this.popupHeight + 'px';
			
			cObj.style.backgroundColor = '#fff';
			cObj.style.display = 'none';
			
			var obj = this;
			tf_SHADOW.show(function(){ cObj.onclick = function(){ obj.clicked = true; }; cObj.style.display = 'block'; obj.visibled = true; if(typeof fn == 'function') fn(); });
		}
		
	},
	
	hide: function()
	{
		var cObj = tf_DOM.$(this.popupID);
		if(cObj)
		{
			this.visibled = false;
			tf_DOM.RE(cObj);
			tf_SHADOW.hide();
		}
	},
	
	init: function(width, height)
	{
		this.popupWidth = width ? width : this.popupWidth;
		this.popupHeight = height ? height : this.popupHeight;
		
		//var obj = this;
		//tf_DOM.addEvent(document, 'click', function(){ if(!obj.clicked) if(obj.visibled) obj.hide(); obj.clicked = false; }, false);
	}
};

tf_DOM.addEvent(document, 'click', function(){ if(!tf_POPUP.clicked) if(tf_POPUP.visibled) tf_POPUP.hide(); tf_POPUP.clicked = false; }, false);

//tf_POPUP.init();
