/**
*	modello框架
**
*	author 贺博
*	date 2006-12-8
**
*constructer:
*	new ScreanMap(_color); //_color 为背景颜色 
*
*public interface:
*	setTransparence(_op); //_op 设置背景不透明度 0-100;
*	
*	wait(_html,_disable); //_html 在wait状态下居中显示的代码 ; _disable 设置在wait状态下根节点的disable属性(false/true)
*	
*	notify(); //移除屏风
*
*event:
*	onwaiting(); //在调用 wait() 后响应;
*	
*	onnotify(); //在notify() 后响应;
*/
ScreanMap = Class.create();
ScreanMap.register("com.duxiu.js.ScreanMap");

ScreanMap.construct = function($self, $class){
	var map;
	
	var note;
	
	var _color;
	var _opacity;
	var _html;
	
	var iswaiting = false;	
	
	this.initialize = function(_c){_color = _c;}
	
	this.isWaiting = function(){	
		return iswaiting;
	}
	
	//设置透明度
	this.setTransparence =function(_op){
		_opacity =_op;	
	}
	
	//_t 在wait状态下居中显示的代码 ; _disable 设置在wait状态下根节点的disable属性
	this.wait = function(_t,disable){
		if(iswaiting) return;
		
		iswaiting = true;			
		_html=_t;			
		
		render();
		
		map.style.top = 0;
		map.style.left = 0;		

		setSize();
		UtilTool.addListener(window , "onresize" , setSize , true);	
		
		UtilTool.addListener(window , "onscroll" , setSize , true);	
		
		if(typeof disable =='undefined')
			document.documentElement.disabled=true;
		else 
			document.documentElement.disabled=disable;
		
		this.onwaiting();
	}
	
	this.notify = function(){
		if(!iswaiting) return;
		
		iswaiting = false;
		try{//ie			
			map.removeNode(true);		
			note.removeNode(true);
		}
		catch(e){//mozailla
			removeElement(map);		
			removeElement(note);
		}		
		document.documentElement.disabled=false;	
		
		this.onnotify();
	}
	
	/**
	* 动态在Waiting状态下，改变Note显示	
	* date 2007-7-11
	*/
	this.setNote = function(_h){
		_html = _h;
		
		while(note.firstChild){
			note.removeChild(note.firstChild);			
		}
		
		show(note , _html);	
		
		setSize();
	}
	
	this.onwaiting = function(){};
	this.onnotify = function(){};
	
	var render=function(){
		map = document.createElement("div");
		map.style.backgroundColor=_color;		
		map.style.position="absolute";
		map.style.zIndex = Number.MAX_VALUE-1;
		if(_opacity)map.style.filter="alpha(opacity="+_opacity+")";
		
		note = document.createElement("div");
		//note.style.backgroundColor='red';
		note.style.position="absolute";
		note.style.zIndex = Number.MAX_VALUE;
		
		note.className = "class_sreenmap_note";
		
		show(note , _html);
		
		if(document.body){
			document.body.appendChild(map);
			document.body.appendChild(note);
		}
		else if(document.documentElement){
			document.documentElement.appendChild(map);
			document.documentElement.appendChild(note);
		}
		else throw Error("com.duxiu.js.ScreanMap can't find the root element.");	
	}
	
	var setSize =function(){	
		map.style.width = document.documentElement.clientWidth;
		map.style.height = document.documentElement.clientHeight+getPageScrollHeigth();		

		note.style.left =document.documentElement.clientWidth/2-note.offsetWidth/2;
		note.style.top = (document.documentElement.clientHeight-note.offsetHeight)/2+getPageScrollHeigth();	
	}
	
	var show = function(dom , _html){
		if(typeof _html=='string'){
			dom.innerHTML =_html;
		}
		else if(typeof _html=='object'){
			dom.appendChild(_html);	
		}
	}	
}
