// Make the pretty clouds!
// Will Cooke (c) 2009.  
// GPL'd for what it's worth

 
var cloudArray = new Array();
var bg = 800;
var w = document.getElementById("weather");

function rand (n){
  return ( Math.floor ( Math.random ( ) * n + 1 ) );
};

function moveClouds(){
  for (var i=0; i<cloudArray.length; i++) { 
    var singleCloud = cloudArray[i];
    singleCloud.move();
  };
 if (w == null) {w = document.getElementById("weather")};
 if (bg <= 0) {bg = 800};
 bg -= 0.1;
 w.style.backgroundPosition = bg+'px';
};

function addCloud(parentDivId,speed,cloudClass){
  var cloudNumber = cloudArray.length;
  var cloudDiv = document.createElement('div');
  cloudDiv.setAttribute('id', 'cloud'+cloudNumber);
  cloudDiv.style.width = '75px';
  cloudDiv.style.height = '45px';
  cloudDiv.style.position = "absolute";
  cloudDiv.setAttribute('class',cloudClass);  // class could be "sunny" or "fog" or whatever.
  document.getElementById(parentDivId).appendChild(cloudDiv);
  cloudDiv.end_x = screen.width;
  cloudDiv.x = -60.0;
  cloudDiv.y = rand(60);
  cloudDiv.style.top = cloudDiv.y+'px';
  cloudDiv.speed = speed;
  cloudDiv.move = function() {
    if (parseInt(cloudDiv.style.right) > cloudDiv.end_x) {
      cloudDiv.style.right = '-60px';
      cloudDiv.x = -60;
      cloudDiv.y = rand(60);
      cloudDiv.style.top = cloudDiv.y+'px';
      };
    cloudDiv.style.right = cloudDiv.x+'px';
    cloudDiv.x += cloudDiv.speed;
    };
  cloudArray.push(cloudDiv);
  return cloudDiv;
  };

