/*
	Author: Liceen
	Blog: Http://www.ofme.cn
	2010-04-14 15:30
*/
function floatads() {
	this.items=[];
	this.delta=0.08;
	this.isns=navigator.appName == 'Netscape';
	this.add=function(id,x,y,content)
	{
		var div=document.createElement('DIV');
		div.id=id;
		div.style.zIndex=10;
		div.style.width='120px';
		div.style.overflow='hidden';
		div.style.position='absolute';
		div.style.top=(typeof(y)=='string'?eval(y):y)+'px';
		div.style.left=(typeof(x)=='string'?eval(x):x)+'px';
		div.innerHTML=content;		
		//div.childNodes[0].style.overflow='hidden';
		//div.childNodes[0].style.width=parseInt(div.style.width)-2+'px';
		document.body.appendChild(div);
		var newItem={};
		newItem.object=document.getElementById(id);
		newItem.x=x;
		newItem.y=y;
		this.items[this.items.length]=newItem;
	}
	this.show=function()
	{
		var rthis=this;
		window.setInterval(
			function()
			{
				for(var i=0;i<rthis.items.length;i++)
				{
					var followObj=rthis.items[i].object;
					var prefixy=(rthis.isns?pageYOffset:document.documentElement.scrollTop)+(typeof(rthis.items[i].y)=='string'?eval(rthis.items[i].y):rthis.items[i].y);
					var prefixx=(rthis.isns?pageXOffset:document.documentElement.scrollLeft)+(typeof(rthis.items[i].x)=='string'?eval(rthis.items[i].x):rthis.items[i].x);
					
					if(followObj.offsetLeft!=prefixx)
					{
						var dx=(prefixx-followObj.offsetLeft)*rthis.delta;
						dx=(dx>0?1:-1)*Math.ceil(Math.abs(dx));
						followObj.style.left=followObj.offsetLeft+dx+'px';
					}
					
					if(followObj.offsetTop!=prefixy)
					{
						var dy=(prefixy-followObj.offsetTop)*rthis.delta;
						dy=(dy>0?1:-1)*Math.ceil(Math.abs(dy));
						followObj.style.top=followObj.offsetTop+dy+'px';
					}	
					followObj.style.display	= '';
				}
			},
		10);
	}
}

/*
用法
var floatads2=new floatads();
//右侧
floatads2.add('followDivRight','document.documentElement.clientWidth-116',100,要显示的HTML);
//左侧
floatads2.add('followDivLeft',6,100,要显示的HTML);
floatads2.show();
*/
