var f_delta=0.03;//滑动幅度
var f_closeB=false;//关闭默认状态
var f_canClose=true;//是否允许关闭
var f_IsCloseAll=true;//是否关闭所有
var f_Isfloat=true;//是否漂浮
var f_intervalId;
var f_collection;

function floaters() {
  this.items = [];
  this.addItem = function(id,x,y,src,url,width,height)
  {
    if(src.substring(src.length-4,src.length)==".swf")
    {
      var content='<embed src="'+src+'" quality="high" pluginspage="../www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+width+'" height="'+height+'"></embed>';
    }
    else
    {
      var content='<a href="'+url+'" target="_blank"><img src="'+src+'" border="0"></a>';
    }
    if(f_canClose)content+='<table width="90%" border="0" cellspacing="0" cellpadding="0"><tr><td align="right" bgcolor="#ffffff"><img src="images/x.jpg" onClick="closeBanner(\''+id+'\');"></td></tr></table>';
    document.write('<div id='+id+' style="z-index: 10; position: absolute;width:'+width+'px; height:60px;left:'+(typeof(x)=='string'?eval(x):x)+'px;top:'+(typeof(y)=='string'?eval(y):y)+'px">'+content+'</div>');
    
    var newItem= {};
    newItem.object= document.getElementById(id);
    newItem.x= x;
    newItem.y= y;
    
    this.items[this.items.length]= newItem;
  }
  this.play = function()
  {
    f_collection= this.items
    if(f_Isfloat)f_intervalId=setInterval('play()',1);
  }
  }
  function play()
  {
    if(screen.width<=500 || f_closeB)
    {
      for(var i=0;i<f_collection.length;i++)
      {
        f_collection[i].object.style.display = 'none';
      }
      clearInterval(f_intervalId);
      return;
    }
    
    var scrollLeft=document.body.scrollLeft;
    if(scrollLeft==0)scrollLeft=document.documentElement.scrollLeft;//XHTML版本scrollLeft
    var scrollTop=document.body.scrollTop;
    if(scrollTop==0)scrollTop=document.documentElement.scrollTop;
    
    for(var i=0;i<f_collection.length;i++)
    {
      var followObj= f_collection[i].object;
      var followObj_x= (typeof(f_collection[i].x)=='string'?eval(f_collection[i].x):f_collection[i].x);
      var followObj_y= (typeof(f_collection[i].y)=='string'?eval(f_collection[i].y):f_collection[i].y);
      
      if(followObj.offsetLeft!=(scrollLeft+followObj_x)) {
      var dx=(scrollLeft+followObj_x-followObj.offsetLeft)*f_delta;
      dx=(dx>0?1:-1)*Math.ceil(Math.abs(dx));
      followObj.style.left=followObj.offsetLeft+dx;
    }

    if(followObj.offsetTop!=(scrollTop+followObj_y)) {
      var dy=(scrollTop+followObj_y-followObj.offsetTop)*f_delta;
      dy=(dy>0?1:-1)*Math.ceil(Math.abs(dy));
      followObj.style.top=followObj.offsetTop+dy;
    }
  }
} 
function closeBanner(DivName)
{
  for(var i=0;i<f_collection.length;i++)
  {
    if(f_IsCloseAll)
      f_collection[i].object.style.display = 'none';
    else
      if(f_collection[i].object.id==DivName)f_collection[i].object.style.display = 'none';
  }
  if(f_Isfloat&&f_IsCloseAll)clearInterval(f_intervalId);
  return;
}

var theFloaters= new floaters();

//theFloaters.addItem('DivName',x,y,'src',url,width,height);
theFloaters.addItem('followDiv1','Math.floor((document.body.clientWidth-755)/2-120)',102,'images/gg01.gif','product_9.htm',102,313);
theFloaters.addItem('followDiv2','Math.floor(document.body.clientWidth-(document.body.clientWidth-790)/2)',102,'images/gg02.gif','product_7.htm',102,313);
theFloaters.play();

