/***********全局变量**************/
var ad_width = 400;	//默认宽度300
var ad_height= 300;	//默认高度200
var ad_time1 = 0;	//默认延迟时间，设为0则不延迟直接显示
var ad_time2 = 5;	//默认关闭时间，设为0则不自动关闭
var objbottom,objout,diffX,diffY;        
var ad_j = 0,lastScrollX = 0,lastScrollY = 0;
/***********全局变量**************/

function pushad(filename,width,height,time1,time2) {
  if (width)  ad_width = width;
  if (height) ad_height= height;
  if (time1>=0)  ad_time1 = time1;
  if (time2>=0)  ad_time2 = time2;

  objbottom = document.createElement("DIV");
  objbottom.style.display = "none";				//刚开始隐藏起来
  objbottom.style.position = "absolute";			//不用绝对定位无法推送
  objbottom.style.left = "0px";
  //objbottom.style.right = "0px";				//距离屏幕最右边的象素
  objbottom.setAttribute("id","objbottom");
  objbottom.innerHTML = "<table bordercolor='#000000' bgcolor='#ffffff' cellpadding=0 "+
	"cellspacing=0 style='border:1px;border-collapse: collapse;text-align:center;'>"+
	"<tr><td><iframe marginwidth=0 marginheight=0  frameborder=0 "+
	"scrolling=no src=\'\/gg\/" +filename+ "\' width=" +ad_width+ " height=" +ad_height+ "><\/iframe><\/td><\/tr>"+
	  "<tr style='cursor:pointer;font-size:12px;height:30px;line-height:30px;'><td align=right onclick='objbottom.innerHTML=\"\";'>关 闭<\/td><\/tr>" +
	  "<\/table>";
  document.body.appendChild(objbottom);

  self.onError=null;
  if(ad_time1) window.setTimeout("start();",ad_time1*1000);//定时开始推送广告
  else start();
}

//右飘
function pushadR(filename,width,height,time1,time2) {
  if (width)  ad_width = width;
  if (height) ad_height= height;
  if (time1>=0)  ad_time1 = time1;
  if (time2>=0)  ad_time2 = time2;

  objbottom = document.createElement("DIV");
  objbottom.style.display = "none";				//刚开始隐藏起来
  objbottom.style.position = "absolute";			//不用绝对定位无法推送
  //objbottom.style.left = "0px";
  objbottom.style.right = "0px";				//距离屏幕最右边的象素
  objbottom.setAttribute("id","objbottom");
  objbottom.innerHTML = "<table bordercolor='#000000' bgcolor='#ffffff' cellpadding=0 "+
	"cellspacing=0 style='border:1px;border-collapse: collapse;text-align:center;'>"+
	"<tr><td><iframe marginwidth=0 marginheight=0  frameborder=0 "+
	"scrolling=no src=\'\/gg\/" +filename+ "\' width=" +ad_width+ " height=" +ad_height+ "><\/iframe><\/td><\/tr>"+
	  "<tr style='cursor:pointer;font-size:12px;height:30px;line-height:30px;'><td align=right onclick='objbottom.innerHTML=\"\";'>关 闭<\/td><\/tr>" +
	  "<\/table>";
  document.body.appendChild(objbottom);

  self.onError=null;
  if(ad_time1) window.setTimeout("start();",ad_time1*1000);//定时开始推送广告
  else start();
}

//不用iframe
function pushad2(filename,width,height,time1,time2) {
  if (width)  ad_width = width;
  if (height) ad_height= height;
  if (time1>=0)  ad_time1 = time1;
  if (time2>=0)  ad_time2 = time2;

  objbottom = document.createElement("DIV");
  objbottom.style.display = "none";				//刚开始隐藏起来
  objbottom.style.position = "absolute";		//不用绝对定位无法推送
  objbottom.style.right = "260px";				//距离屏幕最右边的象素
  objbottom.setAttribute("id","objbottom");
  objbottom.innerHTML = "<table bordercolor='#000000' bgcolor='#ffffff' cellpadding=0 "+
	"cellspacing=0 style='border:0px;border-collapse: collapse;text-align:center;'>"+
	"<tr><td>" + document.getElementById(filename).innerHTML + "<\/td><\/tr>"+
	  "<tr style='cursor:pointer;font-size:12px;'><td align=right onclick='objbottom.innerHTML=\"\";'>关 闭<\/td><\/tr>" +
	  "<\/table>";
  document.body.appendChild(objbottom);
  document.getElementById(filename).style.display = "none";

  self.onError=null;
  if(ad_time1) window.setTimeout("start();",ad_time1*1000);//定时开始推送广告
  else start();
}

function start(){
  document.getElementById('objbottom').style.display = "";
  document.getElementById('objbottom').style.top = document.documentElement.clientHeight + document.documentElement.scrollTop +"px";
  objout = window.setInterval("moveOut()",20);	//推送出来,10为延迟时间，越小推出速度越快
}

function moveOut(){
  document.getElementById('objbottom').style.top = (document.documentElement.clientHeight + document.documentElement.scrollTop-10*ad_j++) +"px";
  //一次减10象素加快推送速度，高度加上滚动高度以适应滚动条位置
  if(ad_j>=Math.floor(ad_height/10)+5) {
    clearInterval(objout);			//停止推送
    lastScrollY = document.documentElement.scrollTop;	//将最后一次滚动位置设置为当前滚动条位置
    window.setInterval("moveObj()",20);	//开始跟随滚动条效果
    if(ad_time2) window.setTimeout("document.getElementById('objbottom').innerHTML='';",ad_time2*1000);
  }
}
function moveObj() {
  //document.getElementById('objbottom').style.top = document.documentElement.clientHeight + document.documentElement.scrollTop - 30 - ad_height;
  //直接用上面代码则没有过渡效果而直接显示到指定位置
  //下面的代码其实是增加了过渡效果，每次变化当前位置差距的10%
  var diffY = document.documentElement.scrollTop;
  var diffX = 0;
  var tmp = 0;
  if(diffY != lastScrollY) {
    percent = .1 * (diffY - lastScrollY);
    if(percent > 0) percent = Math.ceil(percent);
    else percent = Math.floor(percent);
    tmp = parseInt(document.getElementById('objbottom').style.top.toString().replace("px",""));//替换掉px才能转为int
    document.getElementById('objbottom').style.top = tmp + percent + "px";//加上px才能赋值
    lastScrollY = lastScrollY + percent;
  }
  if(diffX != lastScrollX) {
    percent = .1 * (diffX - lastScrollX);
    if(percent > 0) percent = Math.ceil(percent);
    else percent = Math.floor(percent);
    tmp = parseInt(document.getElementById('objbottom').style.left.toString().replace("px",""));//替换掉px才能转为int
    document.getElementById('objbottom').style.left = tmp + percent + "px";//加上px才能赋值
    //document.getElementById('objbottom').style.pixelLeft += percent;		//IE下才有效
    lastScrollY = lastScrollY + percent;
  }  
}  