/*
对联广告的JS脚?
*/
var closeband = "<div style='cursor:hand;height:10;width:{w};background-color:#48914E;color:#A5CC98;font-size:8pt;' align=right>{id}&nbsp;&nbsp;<img src='\js/close.gif' onclick=CloseAD('{id}')>&nbsp;</div>";
var popAD = {};
function DistichAD(id,x,y,w,h)
{
	this.AddCotent = function(content)
	{	
		document.write("<DIV id="+id+" style='Z-INDEX: 0; POSITION: absolute;  width:" + w + "; height:" + h + ";left:"+(typeof(x)=='string'?eval(x):x)+";top:"+(typeof(y)=='string'?eval(y):y)+"'>" + closeband.replace('{w}', w).replace('{id}',id).replace('{id}',id) + content + closeband.replace('{w}', w).replace('{id}',id).replace('{id}',id) + "</DIV>");
	}
	this.Play = function()
	{
		document.getElementById(id).style.left = x;
		document.getElementById(id).style.right = y;
		setInterval("Play('" + id + "', " + x + ", " + y + ", " + w + ", " + h + ")",10);
	}
}

function CloseAD(id)
{
	document.getElementById(id).style.display = "none";
}

function Play(id,x,y,w,h)
{
	
	var delta = 0.015;
	var ad = {};
	ad.object = document.getElementById(id);
	ad.x = x;
	ad.y = y;
	ad.w = w;
	ad.h = h;
	
	if(screen.width <= 800)
    {
        ad.object.style.display    = 'none';
        return;
    }
    var ad_x        = (typeof(ad.x)=='string'?eval(ad.x):ad.x);
    var ad_y        = (typeof(ad.y)=='string'?eval(ad.y):ad.y);

    if(ad.object.offsetLeft != (document.body.scrollLeft + ad_x)) {
        var dx=(document.body.scrollLeft + ad_x - ad.object.offsetLeft ) * delta;
        dx = (dx > 0 ? 1 : -1 ) * Math.ceil(Math.abs(dx));
        ad.object.style.left = ad.object.offsetLeft + dx;
        }
    if(ad.object.offsetTop != (document.body.scrollTop + ad_y)) {
        var dy = (document.body.scrollTop + ad_y - ad.object.offsetTop) * delta;
        dy = (dy > 0 ? 1 : -1) * Math.ceil(Math.abs(dy));
        ad.object.style.top = ad.object.offsetTop + dy;
        }
    //ad.object.style.display    = '';
}
/*
var distichAd = new DistichAD("ad1", "0", "0", "20", "180");
distichAd.AddCotent("<img src='http://www.patnet.cn/Themes/default/images/logo.gif'>");
distichAd.Play();

var floatAD = new FloatAD("ad2", "50", "400", "1", "10");
floatAD.AddCotent("<img src='http://bbs.hidotnet.com/Themes/default/images/logo.gif'>");
floatAD.Play();

var floatAD2 = new FloatAD("ad3", "600", "400","1", "10");
floatAD2.AddCotent("<img src='http://bbs.hidotnet.com/Themes/default/images/logo.gif'>");
floatAD2.Play();
*/
/*
漂浮广告
待解决问题：
此处xRev和yRev只一个，如果漂浮广告为多个对象。不能分别控制?
*/
var xRev = false, yRev = false;
function FloatAD(id,x,y,w,h)
{
	this.AddCotent = function(content)
	{
		document.write('<DIV id='+id+' style="Z-INDEX: 0; POSITION: absolute;  width:" + w + "; height:" + h + ";left:'+(typeof(x)=='string'?eval(x):x)+';top:'+(typeof(y)=='string'?eval(y):y)+'">' + closeband.replace('{w}', w).replace('{id}',id).replace('{id}',id) + content.replace("\"", "'") + closeband.replace('{w}', w).replace('{id}',id).replace('{id}',id) + '</DIV>');
	}
	this.Play = function()
	{
		//设置浮动的初始点?
		document.getElementById(id).style.left = x;
		document.getElementById(id).style.top = y;
		//开始浮动?
		var itl= setInterval("Start('" + id + "', 1)", 10);
		//鼠标移动到上面时，停目浮动?
		document.getElementById(id).onmouseover=function(){clearInterval(itl)} 
		//鼠标移开时，继续浮动?
		document.getElementById(id).onmouseout=function(){itl=setInterval("Start('" + id + "', 1)", 10)}

	}
}


  function Start(id, step)
  {
	//body的左边界
     var left = document.body.scrollLeft;
     //body的顶边界
     var top = document.body.scrollTop;
     //取得浮动对象
     var obj = document.getElementById(id);
     //body的右边界
     var right = document.body.scrollLeft + document.body.clientWidth - obj.offsetWidth;
     //body的下边界
     var bottom = document.body.scrollTop + document.body.clientHeight - obj.offsetHeight;
     //浮动对象当前的左边界
	 var objLeft = obj.offsetLeft;
	 //浮动对象当前的右边界
	 var objTop = obj.offsetTop;

	//如果X方向到达右边?
	 if (xRev)
	 {
		//X方向负向移动
		objLeft -= step;
	 }
	 else
	 {
		//X方向正向移动
		objLeft += step;
	 }
	 //如果Y方向到下边界
     if (yRev)
     {
		//Y方向负向移动
		objTop -= step;
	 }
	 else
	 {
		//Y方向正向移动
		objTop += step;
	 }
	 if (objTop <= top)
	 {
		//如果Y方向顶上超边BODY边界
		yRev = false;
		objTop = top;
	 }
	 if (objTop >= bottom)
	 {
		//如果Y方向超出BODY底边?
		yRev = true;
		objTop = bottom;
	 }
	  if (objLeft <= left)
     {
		//如果X方向超出左边?
		xRev = false;
		objLeft = left;
     }
     if (objLeft >= right)
     {
		//如果Y方向超出右边?
		xRev = true;
		objLeft = right;
     }
	 obj.style.left = objLeft;
	 obj.style.top = objTop;
}

/*
弹出广告
*/

function PopAd(appPath,x,y,w,h,content)
{
	popAD.x = x;
	popAD.y = y;
	popAD.w = w;
	popAD.h = h;
	popAD.content = content;
	window.open(appPath + "/js/PopAD.htm", "", "width=" + w + ",height=" + h + ",left=" + x + ",top=" + y);
}