﻿var xPos = 20;
var yPos = 10;

var step = 1;
var delay = 100; 
var width,height,Hoffset,Woffset;
var y = 1;
var x = 1;
var interval;
$("fRandom").onmouseover=pause_resume
$("fRandom").onmouseout=floatstart
function changePos() 
{
  width = document.body.clientWidth;
  height = document.body.clientHeight;
  Hoffset = $("fRandom").offsetHeight;
  Woffset = $("fRandom").offsetWidth;
  if (y) 
  {
    yPos = yPos + step;
  }
  else 
  {
    yPos = yPos - step;
  }
  if (yPos < 0) 
  {
    y = 1;
    yPos = 0;
  }
  if (yPos >= (height - Hoffset)) 
  {
    y = 0;
    yPos = (height - Hoffset);
  }
  if (x) 
  {
    xPos = xPos + step;
  }
  else 
  {
    xPos = xPos - step;
  }
  if (xPos < 0) 
  {
    x = 1;
    xPos = 0;
  }
  if (xPos >= (width - Woffset)) 
  {
    x = 0;
    xPos = (width - Woffset);
  }
  $("fRandom").style.left = xPos + document.body.scrollLeft;
  $("fRandom").style.top = yPos + document.body.scrollTop;
}
function floatstart() 
{
    if($("fRandom"))
    {
        $("fRandom").style.left= xPos;
        $("fRandom").style.top = yPos;
        $("fRandom").visibility = "visible";
        interval = setInterval('changePos()', delay);
    }
}
function pause_resume() 
{
    clearInterval(interval);
}

// 根据ID获取页面元素
function $(id)
{	
	return document.getElementById(id);
}
floatstart();