var cloud1 = null; 
var cloud2 = null; 
var cloud3 = null; 
var cloud4 = null;

var c1=0;
var c2=0;
var c3=0;
var c4=0;

var winx = 0;
var ranNum=0;
    
function init() 
   {
   winx = document.documentElement.clientWidth;  
   cloud1 = document.getElementById('cloud1');
   cloud1.style.right=parseInt(winx)*.0+'px';
   c1=winx*.0;
   cloud2 = document.getElementById('cloud2');
   cloud2.style.right=parseInt(winx)*.8+'px';
   c2=winx*.8;
   cloud3 = document.getElementById('cloud3');
   cloud3.style.right=parseInt(winx)*.6+'px';
   c3=winx*.6;
   cloud4 = document.getElementById('cloud4');
   cloud4.style.right=parseInt(winx)*.3+'px';
   c4=winx*.3;
   doMove();      
   }           

function doMove() 
   { 
      cloud1.style.right = parseInt(cloud1.style.right)+1+'px';
      c1= ++c1;      
      cloud2.style.right = parseInt(cloud2.style.right)+1+'px';
      c2= ++c2;
      cloud3.style.right = parseInt(cloud3.style.right)+1+'px';
      c3= ++c3;
      cloud4.style.right = parseInt(cloud4.style.right)+1+'px';
      c4= ++c4;
      time();           
   } 
   
function time()
   {
    setTimeout(ctest,100);
   }        

function ctest()
   {
      if (c1 > winx)
         {
         cloud1.style.right = '0px';
         c1=0;
         get_random();
         }
      else if (c2 > winx)
         {
         cloud2.style.right = '0px';
         c2=0;
         get_random();
         }
      else if (c3 > winx)
         {
         cloud3.style.right = '0px';
         c3=0;
         get_random();
         }
      else if (c4 > winx)
         {
         cloud4.style.right = '0px';
         c4=0;
         get_random();
         }         
      else
         {
         doMove();
         }
   }
          
function get_random()
{
    ranNum= Math.floor(Math.random()*150);
    if (c1==0)
        {
        cloud1.style.top=parseInt(ranNum)+'px';
        reset();
        }
    else if (c2==0)
        {
        cloud2.style.top=parseInt(ranNum)+'px';
        reset();
        }
    else if (c3==0)
        {
        cloud3.style.top=parseInt(ranNum)+'px';
        reset();
        }        
    else if (c4==0)
        {
        cloud4.style.top=parseInt(ranNum)+'px';
        reset();
        }
    else
        {doMove();}    
}                  

function reset()
{       
    var wincheck = document.documentElement.clientWidth;
    if (wincheck != winx)
        {
        c1=c1/winx*wincheck;
        cloud1.style.right=parseInt(c1)+'px';
        c2=c2/winx*wincheck;
        cloud2.style.right=parseInt(c2)+'px';        
        c3=c3/winx*wincheck;
        cloud3.style.right=parseInt(c3)+'px';        
        c4=c4/winx*wincheck;                
        cloud4.style.right=parseInt(c4)+'px';        
        winx=wincheck;
        }
    else {winx=winx;}    
    doMove();
}     
