var xPos = document.body.clientWidth*Math.random();
var yPos = document.body.clientHeight*Math.random();
var step = 1;
var delay = 30;
var height = 0;
var Hoffset = 0;
var Woffset = 0;
var yon = 0;
var xon = 0;
var FloatWidth=120;
var FloatHeight=80;
var pause = true;
var interval;
function changePos(subdiv) {
var FloatImg=document.getElementById(subdiv);
width = document.body.clientWidth;
height = document.body.clientHeight;
Hoffset = FloatImg.offsetHeight;
Woffset = FloatImg.offsetWidth;
FloatImg.style.left = xPos + document.body.scrollLeft;
FloatImg.style.top = yPos + document.body.scrollTop;
if (yon) {
yPos = yPos + step;
}else {
yPos = yPos - step;
}
if (yPos < 0) {
yon = 1;
yPos = 0;
}
if (yPos >= (height - Hoffset)) {
yon = 0;
yPos = (height - Hoffset);
}
if (xon) {
xPos = xPos + step;
}else {
xPos = xPos - step;
}
if (xPos < 0) {
xon = 1;
xPos = 0;
}
if (xPos >= (width - Woffset)) {
xon = 0;
xPos = (width - Woffset);
}
}
function SetImagePX(iWidth,iHeight){ 
if(!isNaN(iWidth)){
FloatWidth=iWidth;
}else{
FloatWidth=0;
}
if(!isNaN(iHeight)){
FloatHeight=iHeight;
}else{
FloatHeight=0;
}
}

//显示图片的HTML代码
function showImageHtml(divID,adImgSrc,adHref,adTitle){
var sWidth,sHeight;
if(FloatWidth<5){
sWidth="";
}else{
sWidth=" width='"+FloatWidth+"'";
}
if(FloatHeight<5){
sHeight="";
}else{
sHeight=" height='"+FloatHeight+"'";
}
document.write("<div id='"+divID+"' style='position:absolute;'>");
document.write("<a href='"+adHref+"' target='_blank' title='"+adTitle+"'>");
document.write("<img src='"+adImgSrc+"' border='0'"+sWidth+sHeight+" onclick='document.getElementById(\""+divID+"\").style.display=\"none\"' >");
document.write("</a></div>");
}
//显示Flash文件的HTML代码
function showFlashHtml(divID,adImgSrc,adHref,adTitle){
var sWidth,sHeight;
if(FloatWidth<5){
sWidth=" width='80'";
}else{
sWidth=" width='"+FloatWidth+"'";
}
if(FloatHeight<5){
sHeight=" height='80'";
}else{
sHeight=" height='"+FloatHeight+"'";
}
document.write("<div id='"+divID+"' style='position:absolute;'>");
document.write("<a href='"+adHref+"' target='_blank' title='"+adTitle+"'>");
document.write("<object  codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0'"+sWidth+sHeight+" align='middle'>");
document.write("<param name='movie' value='"+adImgSrc+"'>");
document.write("<param name='quality' value='high'>");
document.write("<embed src='"+adImgSrc+"'"+sWidth+sHeight+" quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer&#39; type='application/x-shockwave-flash'></embed></object>");
document.write("</a></div>");
}
function Close(subdiv)
{
var StartFloatImg=document.getElementById(subdiv);
StartFloatImg.style.visibility="hidden";
}
function MvInit(subdiv,pic,url,title) {
var re=/(.swf)$/gi;
var re2=/(.gif)$|(.jpg)$|(.png)$|(.bmp)$/gi;
if(re.test(pic)){
showFlashHtml(subdiv,pic,url,title);
}else if(re2.test(pic)){
showImageHtml(subdiv,pic,url,title);
}
var StartFloatImg=document.getElementById(subdiv);
StartFloatImg.style.top = yPos;
StartFloatImg.style.visibility = "visible";
interval = setInterval('changePos("'+subdiv+'")', delay);
}
MvInit("Test","./vaxel/ani.gif","./vaxel/vaxel.html");
