var FADEINFNOBJ=null;  var FADEOUTFNOBJ=null; var ENLARGEINFNOBJ=null;

function showEngineDiv(type,bgId,otherId,obj){ 
	this.wait=function(){
		showEngineDiv(type,bgId,otherId);
	}

		timers=setTimeout(this.wait,1000);

	if(timers!=null){clearTimeout(timers);}
	if(type=="in"){
		var fn=otherId!=null?function(){			
			showEDIV();
		}:null;
		FADEINFNOBJ=new fadeIn(D(bgId),fn,true);
		FADEINFNOBJ.begin();
	}else if(type=="out"){	

			FADEOUTFNOBJ=new fadeOut(D(bgId),null);
			FADEOUTFNOBJ.begin();
			quitDiv(obj);
	}
}

function D(id){
	return (typeof(id)=='object')?id:document.getElementById(id);
}
//object fade in :
//(targetObj: The dom object  , nextFunctionName:The next will be execute funcation's name ,  tensile:do you want to show the tensile)
function fadeIn(targetObj,nextFunctionName,tensile){
	this.target=((typeof(targetObj)).toLowerCase().indexOf("object")==-1?D(targetObj):targetObj);
	this.speed=15;
	this.maxOpacity_IE=80;
	this.maxOpacity_OT=0.80;
	this.currentOpacity_IE=0;
	this.currentOpacity_OT=0.0;
	this.timer=null;	
	this.nFN=nextFunctionName;
	this.tens=tensile;	
	this.show=function(){
		this.target.style.display="block";
	}
	this.clearTimes=function(){
		clearInterval(this.timer);
		if(!isNull(this.nFN)){
			T=setTimeout(this.nFN,500);
		}
		FADEINFNOBJ=null;
	}
	this.fade_ie=function(){
		if(this.currentOpacity_IE<this.maxOpacity_IE){
			this.target.style.filter="alpha(opacity="+(this.currentOpacity_IE+=20)+")";
		}else{
			this.currentOpacity_IE=0; 
			this.clearTimes();
		}
	}
	this.fade_ot=function(){
		if(this.currentOpacity_OT<this.maxOpacity_OT){
			this.target.style.opacity=(this.currentOpacity_OT+=0.04);
		}else{
			this.currentOpacity_OT=0.0;
			this.clearTimes();
		}
	}
	this.init=function(){
		var browser=getBrowserSize();
		//document.title=browser.x +","+browser.y ;
		this.target.style.width="1000px";
		var grayHeight = toInt(document.body.scrollHeight)-130+"px";
		if(grayHeight==null||grayHeight=="undefined"){
			grayHeight=toInt(browser.y)-130+"px";	
		}
		this.target.style.height=grayHeight;	
	}
	this.begin=function(){
		if(isNull(this.target)){return;}
		this.show();  if(this.tens) this.init();
		
		this.timer=setInterval("executeFade('in')",this.speed);		
	}	
}
function fadeOut(targetObj,nextFunctionName){
	this.target=((typeof(targetObj)).toLowerCase().indexOf("object")==-1?D(targetObj):targetObj);
	this.speed=15;
	this.minOpacity=0.0;
	this.currentOpacity_IE=80;
	this.currentOpacity_OT=0.80;
	this.timer=null;	
	this.nFN=nextFunctionName;
	
	this.hidden=function(){
		this.target.style.display="none";
	}	
	this.clearTimes=function(){
		clearInterval(this.timer);
		if(!isNull(this.nFN)){
			T=setTimeout(this.nFN,500);
		}
		FADEINFNOBJ=null;
	}
	this.fade_ie=function(){
		if(this.currentOpacity_IE>this.minOpacity){
			this.target.style.filter="alpha(opacity="+(this.currentOpacity_IE-=20)+")";
		}else{
			this.currentOpacity_IE=0; 
			this.hidden();
			this.clearTimes();
		}
		
		
	}
	this.fade_ot=function(){
		if(this.currentOpacity_OT>this.minOpacity){
			this.target.style.opacity=(this.currentOpacity_OT-=0.04);
		}else{
			this.currentOpacity_OT=0.0;
			this.hidden();
			this.clearTimes();
		}
	}
	this.begin=function(){
		if(isNull(this.target)){return;}		
		this.timer=setInterval("executeFade('out')",this.speed);		
	}	
}

function executeFade(t){
	if(t=="in"){	
		if(isNull(FADEINFNOBJ)){		return; 	}//############################have some mistakes####################################
		if(isIE()){//fade in ie
			FADEINFNOBJ.fade_ie();
		}else{//fade in other brower
			FADEINFNOBJ.fade_ot();
		}
	}else if(t=="out"){	
		if(isIE()){//fade out ie
			FADEOUTFNOBJ.fade_ie();
		}else{//fade out other brower
			FADEOUTFNOBJ.fade_ot();
		}
	}
}

function getBrowserSize(){
	var B_H = Body().clientHeight;
	var B_W = Body().clientWidth;
	return {x:B_W,y:B_H};
}
function Body(){
    var Body;
    if (typeof document.compatMode != 'undefined' && document.compatMode != 'BackCompat') {
       Body = document.documentElement;
    }
    else if (typeof document.body != 'undefined') {
       Body = document.body;
    }
    return Body;
}

function toInt(T_O){
	if(isNull(T_O)){return 0;}
	T_O = T_O.toString().toLowerCase();
	var num = 0;
	try{
		num = parseInt(T_O.indexOf("px") != -1 ? T_O.substring(0,T_O.indexOf("px")) : T_O);
	}catch(e){}	
	return num;
}
function isNull(t){
	return t==null||t==undefined;
}
function isIE(){
	return navigator.userAgent.toLowerCase().indexOf("ie") != -1;
}