
function moveCloud(which) {
  var elem = $("#" + which);
  
  
  var xpos = parseFloat(elem.attr('xpos'));
  xpos += parseFloat(elem.attr('speed'));
  elem.attr('xpos', xpos);
  
  
  var xposi = Math.floor(xpos);
  
  if (xpos > $("#top").width()) {
    elem.attr('xpos', Math.floor(Math.random() * 500 + 200) * -1);
    speed = (Math.random() * 2) + 1; 
    elem.css('top', Math.floor(Math.random() * 250 - 30));
  }

  
  elem.css('left', xpos + "px");
  
  elem.movement = setTimeout(
			function(ms){
				moveCloud(which);
			}
		, 100);
}

function initClouds() {
  
  
  $(document).find(".cloud").each( function() {
    var which = $(this).attr('id');
    var elem = $("#" + which);
    
    elem.attr('speed', (Math.random() * 2) + 1);
    elem.attr('xpos', parseInt(elem.css('left')));
    
    
	  elem.movement = setTimeout(
			function(ms){
				moveCloud(which);
			}
		, 100);
	});
	
}

$(document).ready(initClouds);

