/*
  飘动层：<span id='random_id' style='position:absolute;visibility:hidden;z-index:10;border:1px solid #ff0000'><a href='www.siteem.com' target='_blank'><img src='http://www.siteem.com/images/logo.gif' border='0'></a></span>
  containerid 飘动层的id
  initLoca    层的初始位置 tl tc tr  cl cc cr  bl  bc  br
  speed       飘动速度  unit px/sec 10 - 100 递增10px
  MouseOver   是否有鼠标悬浮事件 1 鼠标悬停 0 鼠标不悬停
*/
var siteem_floatwin =function(containerid,initLoca,speed,MouseOver){
  this.siteemWinGetWinSize=window.innerHeight?function(b_h){return b_h?innerHeight:innerWidth;}:function(b_h){return document.body[b_h?'clientHeight':'clientWidth'];};
  this.siteemWinGetWinScroll=window.innerHeight?function(b_h){return b_h?pageYOffset:pageXOffset;}:function(b_h){return document.body[b_h?'scrollTop':'scrollLeft'];};
  this.c_float_unit=1 ;                                /*px，每次飘动的位移*/
  this.state=0;                                        /*0: 飘动 1: 停顿*/
  this.m_nFloatSpeed=speed;                            /*滚动速度, unit px/sec*/
  this.mouseover=MouseOver;                            /*鼠标悬停事件*/
  if(typeof this.mouseover!="number")return;
  if((this.mouseover!=0)&&(this.mouseover!=1))return;
  this.m_nFloatSpeed=speed;
  if(typeof this.m_nFloatSpeed!="number")return;
  if(this.m_nFloatSpeed<=0)this.m_nFloatSpeed=50;
  this.m_nFloatInterval=parseInt(1000/(this.m_nFloatSpeed/this.c_float_unit));/*调用滚动函数的时间片*/;
  this.container=document.getElementById(containerid);        /*获取飘动span*/
  if(this.container==null)return;
  this.xPos=0;                                         /*当前x坐标*/
  this.yPos=0;                                         /*当前y坐标*/
  this.yDir=0;                                         /*标志y步进的方向(加/减步进)*/
  this.xDir=0;                                         /*标志x步进的方向(加/减步进)*/
  this.clientW=this.siteemWinGetWinSize(false);        /*屏幕宽度*/
  this.clientH=this.siteemWinGetWinSize(true);;        /*屏幕高度*/
  this.ch=0;                                           /*高度*/
  this.cw=0;                                           /*宽度*/
  if(this.container!=null){
    this.ch=this.container.offsetHeight;
    this.cw=this.container.offsetWidth;
  }
  this.initLoca=initLoca;                              /*首次出现位置*/
  if(typeof this.initLoca !="string")return;
  if((this.initLoca !="tl")&&(this.initLoca !="tc")&&(this.initLoca !="tr")&&(this.initLoca !="cl")&&(this.initLoca !="cc")
    &&(this.initLoca !="cr")&&(this.initLoca !="bl")&&(this.initLoca !="bc")&&(this.initLoca !="br"))
    return;
  /*设置首次出现位置*/
  switch (this.initLoca){
    case "tl":
      this.xPos=0;
      this.yPos=0;
      break;
    case "tc":
      this.xPos=parseInt((this.clientW-this.cw)/2);
      this.yPos=0;
      break;
    case "tr":
      this.xPos=this.clientW;
      this.yPos=0;
      break;
    case "bl":
      this.xPos=0;
      this.yPos=this.clientH;
      break;
    case "bc":
      this.xPos=parseInt((this.clientW-this.cw)/2);
      this.yPos=this.clientH;
      break;
    case "br":
      this.xPos=this.clientW;
      this.yPos=this.clientH;
      break;
    case "cl":
      this.xPos=0;
      this.yPos=parseInt((this.clientH-this.ch)/2);
      break;
    case "cc":
      this.xPos=parseInt((this.clientW-this.cw)/2);
      this.yPos=parseInt((this.clientH-this.ch)/2);
      break;
    case "cr":
      this.xPos=this.clientW;
      this.yPos=parseInt((this.clientH-this.ch)/2);
      break;
    default :
      this.xPos=0;
      this.yPos=0;
  }
  this.start=function(inst){
    if (this.container!=null)this.container.style.visibility = "visible";
    if(this.mouseover==1){
      if(typeof this.container.onmouseover!="function"){
        this.container.onmouseover=function(){
          eval(inst+".state=1");
        }
      }
      if(typeof this.container.onmouseout!="function"){
        this.container.onmouseout=function(){
          eval(inst+".state=0");
        }
      }
    }
    setInterval(inst+".move()",this.m_nFloatInterval);
  }  
  this.move=function(){
    if (this.state==1) return;
    this.clientW=this.siteemWinGetWinSize(false);
    this.clientH=this.siteemWinGetWinSize(true);
    if (this.container!=null){
      this.container.style.left=this.xPos+this.siteemWinGetWinScroll(false);
      this.container.style.top=this.yPos+this.siteemWinGetWinScroll(true);
    }
    if (this.yDir){
      this.yPos+=this.c_float_unit;
    }
    else{
      this.yPos-=this.c_float_unit;
    }
    if (this.yPos<0){
      this.yDir=1;
      this.yPos=0;
    }
    if (this.yPos>=(this.clientH-this.ch)){
      this.yDir=0;
      this.yPos=(this.clientH-this.ch);
    }
    if (this.xDir){
      this.xPos+=this.c_float_unit;
    }
    else{
      this.xPos-=this.c_float_unit;
    }
    if (this.xPos<0){
      this.xDir=1;
      this.xPos=0;
    }
    if (this.xPos>=(this.clientW-this.cw)){
      this.xDir=0;
      this.xPos=(this.clientW-this.cw);
    }
  }
}