//创建层与事件对象的关联

// 方法
var Andy_relating={
	arrRelating:[],
	targetObj:null,
	relObj:null,
	nowStyle:null,
	defaultStyle:new Andy_relatingStyle(0,0,"absolute",true,null,null,false),
	show:false,	
	isIE:(navigator.userAgent.toLowerCase().indexOf( "msie")>= 0)?true:false,
	relating:function(strObj,RelObj,apply)
	{
		this.arrRelating.push(strObj);
		var relObj=$(RelObj);
		if(relObj!=null)
		{	
			relObj.setAttribute("_relating",strObj);
			relObj.setAttribute("_relatingStyle",Andy_relating.nowStyle);
		}
		else return false;
		
		var obj=$(strObj);
		if(obj!=null)
		{
			obj.onclick=function(){Andy_relating.show=true};
		}
		if(apply==true)
		{
			this.applay(relObj);
		}
		else
		{			
			if(relObj!=null)
			{
				relObj.onclick=function()
				{					
					Andy_relating.applay(this);
					return false;
				}
			}
		}
		return false;
	},
	close:function()
	{
		if(this.targetObj!=null)
		{
			var obj=$(this.targetObj);
			if(obj!=null)
			{
				obj.style.display="none";
				this.targetObj=null;
				this.relObj=null;
			}
		}
	},
	clear:function()
	{
		this.targetObj=null;
		this.relObj=null;
	},
	applay:function(relObj)
	{
		if(relObj==null) return false;
		if($(this.targetObj)!=null)
			this.hidden();
			
			
		this.show=true;
		var objId=relObj.getAttribute("_relating");
		var obj=(objId!=null)?$(objId):null;
		var oStyle=relObj.getAttribute("_relatingStyle");
		
		if(oStyle==null)
			oStyle=Andy_relating.defaultStyle;
			
		var oCenter=false;//(oStyle.wCenter==true&&oStyle.hMiddle==true)?true:false;
		
		var left,top;
		left=top=0;
		
		top+=((oStyle.isHeight==false)?0:relObj.offsetHeight);
		
		if(oStyle!=null&&oStyle.moveX!=null)
			left+=oStyle.moveX;		
		//else if(oStyle.wCenter==true)
		//	left=Math.round(parseInt(document.body.clientWidth)/2);
		if(oStyle!=null&&oStyle.moveY!=null)
			top+=oStyle.moveY;
		//else if(oStyle.hMiddle==true)
			//top=Math.round(parseInt(document.body.clientHeight)/2);//top=Math.round((screen.height-21)/2);
		
		if(oStyle.position=="relative")		//相对位置
		{
			relObj.parentNode.style.position="relative";
			if(oCenter!=true)
			{
				top+=relObj.offsetTop;
				left+=relObj.offsetLeft;
			}
		}
		else		//绝对位置
		{
			var info=Andy_base.getInfo(relObj);	
			if(oCenter!=true)
			{
				left+=info.left;
				top+=info.top;
			}
		}
		if(obj==null) return false;
		
		var browse = new Browser();
		if(browse.isMZ==false){
			with(obj)
			{
				style.display="block";
				style.position ="absolute";
				var toRight=parseInt(left)+parseInt(offsetWidth);	
				if(oCenter==true)
				{
					left-=Math.round(offsetWidth/2);
					top-=Math.round(offsetHeight/2);
				}
				else if(toRight>(document.body.offsetWidth-5))	//超出右侧框架时的处理
				{
					left-=(offsetWidth-relObj.offsetWidth);
				}
				style.left=left+"px";
				style.top=top+"px";		
				
				Andy_relating.targetObj=obj;
				Andy_relating.relObj=relObj;
			}
		}else{
			with(obj)
			{
				style.display="block";
				style.position ="absolute";
				var toRight=parseInt(left)+parseInt(offsetWidth);	
				if(oCenter==true)
				{
					left-=Math.round(innerWidth/2);
					top-=Math.round(innerHeight/2);
				}
				else if(toRight>(window.innerWidth-5))	//超出右侧框架时的处理
				{
					left-=(innerWidth-relObj.innerWidth);
				}
				style.left=left+"px";
				style.top=top+"px";		
				
				Andy_relating.targetObj=obj;
				Andy_relating.relObj=relObj;
			}
		}
		
		if(obj.childNodes[0].className=="shadow"&&obj.childNodes[1]!=null)
		{
			var content=obj.childNodes[1];
			var shadow=obj.childNodes[0];
			var w=content.offsetWidth;
			var h=content.offsetHeight;		
			shadow.style.width=w;
			shadow.style.height=h;
			content.style.position="relative";	
			content.style.zIndex=20002;
//			content.style.zIndex=0;
			
			var fLn=obj.getElementsByTagName("iframe");
			if((fLn.length>0&&fLn[0].className=="frm__hidden")||this.isIE==false)	return true;
			
			var frm=document.createElement("<iframe frameborder='0' scrolling='no' class='frm__hidden' style='filter: Alpha(Opacity=0);position: absolute;left: 0px;top: 0px;z-index: 20000;'></iframe>");
//			var frm=document.createElement("<iframe frameborder='0' scrolling='no' class='frm__hidden' style='filter: Alpha(Opacity=0);position: absolute;left: 0px;top: 0px;z-index: 0;'></iframe>");
			frm.style.width=obj.offsetWidth;
			frm.style.height=obj.offsetHeight;
			obj.style.zIndex=20001;
//			obj.style.zIndex=0;
			obj.appendChild(frm);
		}	
	},	
	hidden:function()
	{
		var obj=$(this.targetObj);
		if(obj==null) return;
		
		obj.style.display="none";
		this.clear();
	}
};
document.onclick=function()
{
	if(Andy_relating.show==false&&Andy_relating.relObj!=null)
	{
		Andy_relating.hidden();
	}
	Andy_relating.show=false;
}

//定位类型,位移X，位移Y,是否有阴影,屏幕是否变暗
function Andy_relatingStyle(moveX,moveY,position,isHeight,wCenter,hMiddle,ScreenConvert)	
{
	this.moveX=moveX;
	this.moveY=moveY;
	this.position=position;
	//this.shadow=shadow;
	this.wCenter=wCenter;
	this.hMiddle=hMiddle;
	this.isHeight=isHeight;		//是否包括链接本身的宽度
	this.screenConvert=ScreenConvert;
}
