// JavaScript Document
/*
*程序制作：李勃 
*制作时间：2006-06-05
*功能：对联广告
*用法：首先创建两个对象，分别是左右两个广告DIV对象；
	   再执行该对象的initDivOfConvenienceLink()或initDivOfConvenienceLink1()函数；
	   如：
	<script language="javascript" src="duilian.js"></script>
	<script>
	str1='<table width="100%" height="100%" border="0" cellpadding="1" cellspacing="1"><tr bgcolor="#0099CC"><td>sdf</td></tr></table>';
	str2='<img src="p1.gif">';
	var wokao=new ConvenienceLink("wokao",20,20,str1,2,20);
	wokao.initDivOfConvenienceLink();
	var w=new ConvenienceLink2("w",20,20,str2,2,20);
	w.initDivOfConvenienceLink2();
	</script>
*对象参数说明：
ObjName:对象名称；
Width：宽度；
Height：高度；
contentHTML：广告内容的HTML代码；
spaceOfLeft：左边广告距左边的距离；
spaceOfRight：右边广告距右边的距离；
spaceOfTop：距上边的距离；
linkURL:链接地址，为空的话就没有；
另外说明：所有的HTML内容是放在一个层div里面，无边框，透明色，overflow=hidden；可以调整其宽度和高度来适当调整位置；
*
*/
/*左边广告*/
function ConvenienceLink(ObjName,Width,Height,contentHTML,spaceOfLeft,spaceOfTop,linkURL)
{
	//alert("wori")
	this.ObjName=ObjName;
	this.divName=ObjName+"div";
	this.Width=Width;
	this.Height=Height;
	this.contentHTML=contentHTML;
	this.spaceOfLeft=spaceOfLeft;
	this.spaceOfTop=spaceOfTop;
	this.linkURL=linkURL;
	//alert("we")
	this.locateDiv=locateDiv;
	this.initDivOfConvenienceLink=initDivOfConvenienceLink;
	this.resizeDiv=resizeDiv;
}

/*右边广告*/
function ConvenienceLink2(ObjName,Width,Height,contentHTML,spaceOfRight,spaceOfTop,linkURL)
{
	this.ObjName=ObjName;
	this.divName=ObjName+"div2";
	this.Width=Width;
	this.Height=Height;
	this.contentHTML=contentHTML;
	this.spaceOfRight=spaceOfRight;
	this.spaceOfTop=spaceOfTop;
	this.linkURL=linkURL;
	
	this.locateDiv2=locateDiv2;
	this.initDivOfConvenienceLink2=initDivOfConvenienceLink2;
	this.resizeDiv2=resizeDiv2;
}
function initDivOfConvenienceLink()
{
	with(this)
	{
		s='<div id="'+divName+'" style="position:absolute; z-index:9999; visibility:visible; top:0px; left:0px; width:'+Width+'px; height:'+Height+'px; overflow:hidden; border:1px; z-index:999">';
		if(linkURL!='')
			s+='<a href="'+linkURL+'" target="_blank">'+contentHTML+'</a>';
		else
		 	s+=contentHTML;
		s+='</div>';
		document.write(s);
		locateDiv();
	}
}
function locateDiv()
{
	with(this)
	{
		theTop=parseInt(document.getElementById(divName).style.top);
		theLeft=parseInt(document.getElementById(divName).style.left);
		theWidth=parseInt(document.getElementById(divName).style.width);
		theHeight=parseInt(document.getElementById(divName).style.height);
		bodyWidth=document.body.clientWidth;
		bodyHeight = document.body.clientHeight;
		document.getElementById(divName).style.top=document.body.scrollTop+spaceOfTop;
		document.getElementById(divName).style.left=document.body.scrollLeft+spaceOfLeft;
		window.setInterval(ObjName+'.resizeDiv()',40);
	}
}
function resizeDiv()
{
	with(this)
	{
		theTop=parseInt(document.getElementById(divName).style.top);
		theLeft=parseInt(document.getElementById(divName).style.left);
		theWidth=parseInt(document.getElementById(divName).style.width);
		theHeight=parseInt(document.getElementById(divName).style.height);
		bodyWidth=document.body.clientWidth;
		bodyHeight = document.body.clientHeight;
		document.getElementById(divName).style.top=document.body.scrollTop+spaceOfTop;
		document.getElementById(divName).style.left=document.body.scrollLeft+spaceOfLeft;
	}
}

function initDivOfConvenienceLink2()
{
	with(this)
	{
		s='<div id="'+divName+'" style="position:absolute; z-index:9999; visibility:visible; top:0px; left:0px; width:'+Width+'px; height:'+Height+'px; overflow:hidden; border:1px; z-index:999">';
		if(linkURL!='')
			s+='<a href="'+linkURL+'" target="_blank">'+contentHTML+'</a>';
		else
		 	s+=contentHTML;
		s+='</div>';
		document.write(s);
		locateDiv2();
	}
}
function locateDiv2()
{
	with(this)
	{
		theTop=parseInt(document.getElementById(divName).style.top);
		theLeft=parseInt(document.getElementById(divName).style.left);
		theWidth=parseInt(document.getElementById(divName).style.width);
		theHeight=parseInt(document.getElementById(divName).style.height);
		bodyWidth=document.body.clientWidth;
		bodyHeight = document.body.clientHeight;
		document.getElementById(divName).style.top=document.body.scrollTop+spaceOfTop;
		document.getElementById(divName).style.left=bodyWidth+document.body.scrollLeft-theWidth-spaceOfRight;
		window.setInterval(ObjName+'.resizeDiv2()',40);
	}
}
function resizeDiv2()
{
	with(this)
	{
		theTop=parseInt(document.getElementById(divName).style.top);
		theLeft=parseInt(document.getElementById(divName).style.left);
		theWidth=parseInt(document.getElementById(divName).style.width);
		theHeight=parseInt(document.getElementById(divName).style.height);
		bodyWidth=document.body.clientWidth;
		bodyHeight = document.body.clientHeight;
		document.getElementById(divName).style.top=document.body.scrollTop+spaceOfTop;
		document.getElementById(divName).style.left=bodyWidth+document.body.scrollLeft-theWidth-spaceOfRight;
	}
}