﻿function relative_auto(){
	this.nTop;//
	this.oFdiv;//父对像
	this.oZdiv;//子对像（要重新定位的对像）
	this.name;
	this.xc;
	this.inset=function(subname,zID,fID,nTopHeight){//实例化名称,要定位的元素ID,父元素ID,TOP安全距离
		this.name=subname;
		if(document.getElementById(zID)){
			this.oZdiv=document.getElementById(zID);
		}else{
			return;
		};
		if(document.getElementById(fID)){
			this.oFdiv=document.getElementById(fID);
		}else{
			return;
		};
		if(parseInt(nTopHeight)>0){this.nTop=parseInt(nTopHeight);};
		this.xc = setInterval(this.name+".play()",30);
	};
	
	this.play=function(){
		var tep;
		if(document.documentElement.clientHeight > this.oZdiv.clientHeight){
			tep = document.documentElement.scrollTop-this.nTop;
		}else{
			tep = document.documentElement.scrollTop-(this.nTop+this.oZdiv.clientHeight-document.documentElement.clientHeight);//
		}	
		if(tep>0){
			if(tep+this.oZdiv.clientHeight > this.oFdiv.clientHeight){
				HDDW(this.oZdiv.id,this.oFdiv.clientHeight-this.oZdiv.clientHeight,"top",0.4)
				//this.oZdiv.style.top= this.oFdiv.clientHeight-this.oZdiv.clientHeight+"px";
			}else{
				HDDW(this.oZdiv.id,tep,"top",0.2)
				//this.oZdiv.style.top=tep+"px";
    		};
		}else{
			HDDW(this.oZdiv.id,0,"top",0.2)
			//this.oZdiv.style.top="0px";
		};
	};
};
