function floatinitial()
{
	Amount=8;
	Ypos_float=new Array();
	Xpos_float=new Array();
	Speed_float=new Array();
	Step_float=new Array();
	CStep_float=new Array();
  var newDiv=document.createElement("<div id='floatlayer'  style='position:absolute;top:0px;left:0px;z-index:300'></div>");
	//漂浮物的层
	var str="<div style='position:relative'>";
	for (i = 0; i < Amount; i++)
	{
	    var P= Math.floor(Math.random()*4);
	    str+='<img id="si" src="about:blank" style="position:absolute;top:0px;left:0px;visibility=hidden">';
	}
	str+='</div>';
  newDiv.innerHTML=str;
  top.document.write(str);
  top.document.all.body.appendChild(newDiv);
	WinHeight=625;
	WinWidth=925;

	for (i=0; i < Amount; i++)
	{
		Ypos_float[i] = Math.round(Math.random()*WinHeight);
		Xpos_float[i] = Math.round(Math.random()*WinWidth);
		Speed_float[i]= Math.random()*1.5+1;
		CStep_float[i]=0;
		Step_float[i]=Math.random()*0.05+0.05;
	}

}

//漂浮物,去掉原始的漂浮物,新增一种类别的漂浮物
function space_addFloatItem(type, itemno, mode, num)
{
	var totalnum=8;
	//if (itemno==0) {
		//return false;
	//}
	//if (findWndElement(type, itemno) >=0) {
		//deleteWindowByTypeAndItemno(type, itemno);
    	//return 0;
   //}
    //var itemdir=itemno%16;

    for(i=0; i<totalnum; i++)
    {
       if (top.si[i])
           top.si[i].style.visibility="hidden";
    }

    //停止层运动,比较笨的方法
    stop_Falling();
	if (mode==0)
	{
        top.document.all.floatlayer.style.pixelLeft=0;
        top.document.all.floatlayer.style.pixelTop=0;
    }
    else if(mode==1)
    {
        top.document.all.floatlayer.style.pixelLeft=0;
        top.document.all.floatlayer.style.pixelTop=625;

    }
    else if(mode==2)
    {
        top.document.all.floatlayer.style.pixelLeft=0;
        top.document.all.floatlayer.style.pixelTop=0;
    }
    else if(mode==3)
    {
        top.document.all.floatlayer.style.pixelLeft=925;
        top.document.all.floatlayer.style.pixelTop=0;

    }

	for(i=0; i<totalnum;i++)
	{
          if(top.si[i]) {
               top.si[i].style.visibility="";
               var P=Math.floor(Math.random()*num);
               top.si[i].src="Fly/286_"+(P+1)+".gif";
          }
    }
    top.g_FallingMode= mode;
    start_Falling();
    new CFloat (type, itemno, mode, num);
}

/** 开始飘浮物
  */
function start_Falling() {
	falling= setInterval("fall()", 200);
}

function stop_Falling() {
	if (falling) {
		clearTimeout(falling);
		falling= null;
		g_FallingMode= null;
	}
}

//定义轨迹
function fall()
{
	if (top.g_FallingMode == null) {
		return;
	}
	var mode= top.g_FallingMode;
    var totalnum=8;
	var WinHeight=625;
	var WinWidth=925;
    var hscrll=(document.layers)?window.pageYOffset:top.document.body.scrollTop;
    var wscrll=(document.layers)?window.pageXOffset:top.document.body.scrollLeft;
    for (i=0; i <totalnum; i++)
    {
        if(mode==0||mode==1)
        {
            sy = top.Speed_float[i]*Math.sin(90*Math.PI/180);
            sx = top.Speed_float[i]*Math.cos(top.CStep_float[i]);
            top.Ypos_float[i]+=sy;
            top.Xpos_float[i]+=sx;
            if (top.Ypos_float[i] > WinHeight)
            {
                top.Ypos_float[i]=0;
                top.Xpos_float[i]=Math.round(Math.random()*WinWidth);
                top.Speed_float[i]=Math.random()*1+1;
            }
         }
         else
         {
             sx = top.Speed_float[i]*Math.sin(90*Math.PI/180);
             sy = top.Speed_float[i]*Math.cos(top.CStep_float[i]);
             top.Ypos_float[i]+=sy;
             top.Xpos_float[i]+=sx;
             if (top.Xpos_float[i] > WinWidth)
             {
                  top.Xpos_float[i]=0;
                  top.Ypos_float[i]=Math.round(Math.random()*WinHeight);
             }
         }

          //控制方向
          if (mode==0)
          {
               top.si[i].style.pixelLeft=top.Xpos_float[i];
               top.si[i].style.pixelTop=top.Ypos_float[i]+hscrll;
          }
          else if(mode==1)
          {
               top.si[i].style.pixelLeft=top.Xpos_float[i];
               top.si[i].style.pixelTop=-top.Ypos_float[i]+hscrll;
          }
          else if(mode==2)
          {
               top.si[i].style.pixelLeft=top.Xpos_float[i]+wscrll;
               top.si[i].style.pixelTop=top.Ypos_float[i];
          }
          else if(mode==3)
          {
               top.si[i].style.pixelLeft=-top.Xpos_float[i]+wscrll;
               top.si[i].style.pixelTop=top.Ypos_float[i];
          }
     }
}

function CFloat (type, itemno, mode, num)
{
	this.type= type;
	this.itemno= itemno;
	this.mode= mode;
	this.num= num;
	this.alive= true;
	InsertUniqueType (this);
}

CFloat.prototype.remove = function() {
	if (this.alive) {
		var totalnum= 8;
    	stop_Falling();
		for(i=0; i<totalnum; i++)
		{
    		if(top.si[i]) {
    	        top.si[i].style.visibility="hidden";
    	    }
    	}
	}
}

