title: Same function with different values to different objects
body: <p>i have this function to move my #cubo1 but i want to apply the same function with different values to the others (#cubo2, #cubo3 and #cubo4) however i'm kind of new to this and i have no idea how to do it, i've tried duplicate some parts of the function but every time only one works..</p>
  
  <p>HTML</p>
  
  <pre><code>&lt;div class="fundo"&gt;
      &lt;div id='cubo1'&gt;&lt;/div&gt;
      &lt;div id='cubo2'&gt;&lt;/div&gt;
      &lt;div id='cubo3'&gt;&lt;/div&gt;
      &lt;div id='cubo4'&gt;&lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>CSS</p>
  
  <pre><code>.fundo {
      width: 500px;
      height: 80px;
  
  }
  
  div#cubo1 {
      width: 50px;
      height:50px;
      background-color:red;
      position:fixed;   
  }
  
  div#cubo2 {
      width: 50px;
      height:50px;
      background-color:blue;
      position:fixed;   
  }
  
  div#cubo3 {
      width: 50px;
      height:50px;
      background-color:green;
      position:fixed;   
  }
  
  div#cubo4 {
      width: 50px;
      height:50px;
      background-color:orange;
      position:fixed;   
  }
  </code></pre>
  
  <p>JavaScript:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  
  $(document).ready(function(){
      animateDiv();   
  });
  
  function makeNewPosition(){
      var h = $('.fundo').height() - 50;
      var w = $('.fundo').width() - 50;    
      var nh = Math.floor(Math.random() * h);
      var nw = Math.floor(Math.random() * w);   
      return [nh,nw];     
  }
  function animateDiv(){
      var newq = makeNewPosition();
      var oldq = $('#cubo1').offset();
      var speed = calcSpeed([oldq.top, oldq.left], newq);
      $('#cubo1').animate({ top: newq[0], left: newq[1] }, speed, function(){
        animateDiv();        
      });    
  };
  
  
  
  
  function calcSpeed(prev, next) {   
      var x = Math.abs(prev[1] - next[1]);
      var y = Math.abs(prev[0] - next[0]);    
      var greatest = x &gt; y ? x : y;  
      var speedModifier = 0.01;
      var speed = Math.ceil(greatest/speedModifier);
      return speed;
  }
  
  &lt;/script&gt;
  </code></pre>