﻿// JScript 文件
var floatImages; 
var dirX=new Array(); //方向
var height;
var width;

var coordinate =new Array(); //偏移位置
var offsetMax=10;  //偏移量
var offsetMin=-10;
    
var interval;
function addFloatContain(picName)
{
    if(IsInitialized(picName))
    { 
        if(interval){ clearInterval(interval);}         
        interval=setInterval("Move()",60);
    }
}
  
function Move()
{     
     for(var i=0; i<floatImages.length; i++)
     {
         for(var i=0; i<floatImages.length; i++)
         {
            if(coordinate[i] == offsetMax)
            {               
                dirX[i] = 0;                
                
            } 
            if(coordinate[i] == offsetMin)
            {  
                dirX[i] = 1;
            }
           
           if(dirX[i] == 1)
           {
              coordinate[i] = coordinate[i] +1 ;
           }else
           {
              coordinate[i] = coordinate[i] -1 ;   
           }
           imageMove(floatImages[i], dirX[i]);
         }
     }
}
        
    function imageMove(obj,flag){
         var objCurTop = parseFloat(obj.style.top.substring(0, obj.style.top.indexOf("p"))); 
         var objCurLeft = parseFloat(obj.style.left.substring(0, obj.style.left.indexOf("p")));       
         obj.style.top = (objCurTop + 1.5) + "px";
                
         if(flag == 1){          
            objCurLeft = objCurLeft +1;            
            }
         else{
            objCurLeft = objCurLeft -1;           
         }
         obj.style.left = objCurLeft + "px";
         if(objCurTop > height-50) obj.style.top = -50 + "px";
    }
    
    //初始化化
    function IsInitialized(picName){            
         //页面是否需要显示漂浮
         var fixContent = document.getElementById("fixContent");
         if(!fixContent) return false;
         
         //清空
         if(picName == ""){
            fixContent.innerHTML = "";
            return false;
         }        
         fixContent.innerHTML = '<div id="floatContain" style="position: absolute; left: 0px; top: 0px;">'
                    +'<img style="position: absolute;" />'
                    +'<img style="position: absolute;" />'
                    +'<img style="position: absolute;" />'
                    +'<img style="position: absolute;" />'
                    +'<img style="position: absolute;" />'
                    +'<img style="position: absolute;" />'
                    +'<img style="position: absolute;" />'
                    +'<img style="position: absolute;" />'
                    +'<img style="position: absolute;" />'
                    +'<img style="position: absolute;" />'
                    +'</div>';
            
          if(document.all){           
              //height = document.body.scrollHeight;
              height = document.documentElement.scrollHeight;              
          }else{
              height = document.documentElement.clientHeight ;             
          }
          
           
         width = document.body.scrollWidth; 
      
         floatImages = document.getElementById("floatContain").getElementsByTagName("img");
         var picName = picName.substring(0, picName.indexOf(".")).split('_');   
              
         for(var i=0; i<floatImages.length; i++)
         {  
            var img =  floatImages[i];
            if(img && picName.length>1){            
                img.src ="http://si.yaolanimage.cn/images/floatPic/" + picName[0] + "_" +getIntRandom(1, picName[1]) + ".gif"; 
                img.style.top = getFloatRandom(-30, height-20) + "px";
                img.style.left = getFloatRandom(0, width-100) + "px";           
            }
            
            //标志位
             dirX[i] = getIntRandom(0, 1) ;
            coordinate[i] = getIntRandom(offsetMin, offsetMax);
         }
         return true;
    }
    
    function getIntRandom(iFirstValue, iLastValue)
    {
        var iChoices = iLastValue - iFirstValue + 1;
        return Math.floor(Math.random() * iChoices + iFirstValue);
    }
    
    function getFloatRandom(iFirstValue, iLastValue)
    {
        var iChoices = iLastValue - iFirstValue + 1;
        return Math.random() * iChoices + iFirstValue;
    }
