BlackScreen = function() {
	var _self = this;
	var width;
	var height;
	var url;
	var urlAdvertising;
	var title;
	var minHeight;
	var viewMinHeight;
	
	this.show = function(_title, _width, _height, _url, _minHeight, _viewMinHeight){
		title = _title;
		width = _width; 
		height = _height;
		url = _url;		
		if (_minHeight === undefined || _minHeight === null){
			_minHeight = null; 
		}
		minHeight = _minHeight;
		
		viewMinHeight = false;
		if (_viewMinHeight != undefined && _viewMinHeight != null && _viewMinHeight){
			viewMinHeight = true;
		}		
		
		createBackground();
	};
	this.close = function(){
		var obj;
		if ($Dom.inDocument('blackscreen')){
			$Util.removeChildren('blackscreen');
			obj = $Dom.get('blackscreen');
			document.body.removeChild(obj);
		}
		if ($Dom.inDocument('containerBlackScreen')){
			$Util.removeChildren('containerBlackScreen');
			obj = $Dom.get('containerBlackScreen');
			document.body.removeChild(obj);
		}
		obj = null;
		$Event.removeListener(window, 'resize', updateWindow);
		if ($Util.IsIE6()){
			$Event.removeListener(window, 'scroll', positionFixedIE6);
		}
		$Event.removeListener('advertisingBlackScreen', 'click', viewAdvertising);
	};
	this.setTitle = function(_title){
		$Dom.get('titleBlackScreen').innerHTML = _title;
	};
	this.setAdvertising = function(url){
		if (url !== null && url !== undefined && url.length > 0){
			urlAdvertising = url;
			showAdvertising();
		}
	};
	var showAdvertising = function(){
		$Dom.setStyle('advertisingBlackScreen','display','block');
		$Dom.setStyle('advertisingBlackScreen','visibility','visible');
	};
	var updateWindow = function(e){
		
		var widthScreen = YAHOO.util.Dom.getViewportWidth();
		var heightScreen = YAHOO.util.Dom.getViewportHeight();
		var top = parseInt((heightScreen - height) / 2);
		var left = parseInt((widthScreen - width) / 2);
		
		$Dom.setStyle('blackscreen', 'width', widthScreen + 'px');
		$Dom.setStyle('blackscreen', 'height', heightScreen + 'px');
		
		$Dom.setStyle('containerBlackScreen', 'width', widthScreen + 'px');
		$Dom.setStyle('containerBlackScreen', 'height', heightScreen + 'px');
		
		$Dom.setStyle('frameBlackScreen', 'top', top + 'px');
		$Dom.setStyle('frameBlackScreen', 'left', left + 'px');
			
	};
	
	var positionFixedIE6 = function(e){
		$Dom.setStyle('blackscreen', 'top', YAHOO.util.Dom.getDocumentScrollTop() + 'px');
		$Dom.setStyle('containerBlackScreen', 'top', YAHOO.util.Dom.getDocumentScrollTop() + 'px');
	};
	
	var viewAdvertising = function(){
		$Util.showUrl(urlAdvertising);
	};
	
	this.viewMinHeight = function(){
		if (minHeight === null){
			return;
		}
		updateHeight(minHeight);					
	};
	this.viewNormalHeight = function(){		
		updateHeight(height);					
	};
	
	var updateHeight = function(_height){
		$Dom.setStyle("frameBlackScreen", "height", _height + "px");
		$Dom.setStyle("dataBlackScreen", "height", (_height - 16) + "px");
		$Dom.setStyle("iBlackScreen", "height", (_height - 47) + "px");
		
	}
	
	
	var createBackground = function(){
		var widthScreen = YAHOO.util.Dom.getViewportWidth();
		var heightScreen = YAHOO.util.Dom.getViewportHeight();
		var top = parseInt((heightScreen - height) / 2);
		var left = parseInt((widthScreen - width) / 2);
		var htm = '';		
	
		var shadow = $Util.CreateHtmlElement({'elm':'div','id':'blackscreen'});
		$Dom.setStyle(shadow, 'width', widthScreen + 'px');
		$Dom.setStyle(shadow, 'height', heightScreen + 'px');
		if (!$Util.IsIE6()){
			$Dom.setStyle(shadow, 'position', 'fixed');
		}
		document.body.appendChild(shadow);
		
		var content = $Util.CreateHtmlElement({'elm':'div', 'id':'containerBlackScreen'});
		$Dom.setStyle(content, 'width', widthScreen + 'px');
		$Dom.setStyle(content, 'height', heightScreen + 'px');
		if (!$Util.IsIE6()){
			$Dom.setStyle(content, 'position', 'fixed');
		}
		
		var heightForDraw;
		
		if (viewMinHeight){
			heightForDraw = minHeight;
		} else {
			heightForDraw = height;
		}
				
		htm+= '<div id="frameBlackScreen" class="frameBlackScreen" style="width:' + width + 'px;height:' + heightForDraw + 'px;top:' + top + 'px;left:' + left + 'px;">';
		htm+= '<table cellspacing="0" cellpadding="0" width="' + width + 'px" class="baseContainerBlackScreen" id="baseContainerBlackScreen">';
		htm+= '<tr>';
		htm+= '<td class="topLeft"></td>';		
		htm+= '<td class="top"></td>';
		htm+= '<td class="topRight"></td>';
		htm+= '</tr>';
		
		htm+= '<tr height="' + (heightForDraw - 16) + 'px" id="dataBlackScreen">';
		htm+= '<td class="left"></td>';		
		htm+= '<td class="data">&nbsp;</td>';
		htm+= '<td class="right"></td>';
		htm+= '</tr>';
		
		htm+= '<tr>';
		htm+= '<td class="bottomLeft"></td>';		
		htm+= '<td class="bottom"></td>';
		htm+= '<td class="bottomRight"></td>';
		htm+= '</tr>';
		htm+= '</table>';		
					
		/*
		htm+= '<div class="titleBlackScreen" style="width:' + width + 'px">';
		htm+= '  <div id="buttonClose"></div>';
		
		htm+= '  <table cellspacing="0" cellpadding="0" class="base" ';
		if ($Util.IsIE()){
			htm+= 'style="top:-8px;"';
		}
		htm+= '      width="100%">';
		htm+= '    <tr>';
		htm+= '     <td width="20px"></td>';
		htm+= '     <td>';
		htm+= '        <div class="caption" id="titleBlackScreen" style="width:' + (width - 16 - 110 - 20) + 'px">' + title + '</div>';
		htm+= '      </td>';
		htm+= '      <td width="5px"></td>';
		htm+= '    </tr>';
		htm+= '  </table>';
		
		htm+= '</div>';		
		*/
		  
		htm+= '<div id="titleBlackScreen" class="caption" style="width:' + (width - 45) + 'px;">' + title + '</div>';
		htm+= '<div id="buttonClose" style="left:' + (width - 23) + 'px;"></div>'; 
		
		htm+= '<iframe id ="iBlackScreen" class="info" style="width:' + (width - 10) + 'px;height:' + (heightForDraw - 47) + 'px;border:none;" frameborder="0"></iframe>';
		htm+= '</div>';
		
		content.innerHTML = htm;

		document.body.appendChild(content);
		
		$Dom.get('iBlackScreen').src = url;
		
		
		
		$Event.addListener('buttonClose', 'click', _self.close);
		$Event.addListener(window, 'resize', updateWindow);
		$Event.addListener('advertisingBlackScreen', 'click', viewAdvertising);
		
		if ($Util.IsIE6()){
			positionFixedIE6();
			$Event.addListener(window, 'scroll', positionFixedIE6);
		}
		
	};
}