title: JS: Why isn't this variable available to the other functions?
body: <p>I've am trying to make a canvas animation:</p>
  
  <pre><code>var context;
  var meter;
  var pin;
  
  function init() {
      var meter = new Image();
      var pin = new Image();
      var context = document.getElementById('canvas').getContext('2d');
      meter.src = 'background.png';
      pin.src = 'needle.png';
      context.drawImage(meter,0,0);
      context.translate(275,297);
      context.save();
      setTimeout(startup,500);
  }
  
  function startup() {
      var r=2;    // set rpm here.
      var i=r*36-27;
      var angleInRadians = 3.14159265 * i/180;  //converting degree to radian                
      context.rotate(angleInRadians); //rotating by angle
      context.drawImage(pin,-250,-3);  //adjusting pin center at meter center
      context.restore();
  }
  </code></pre>
  
  <p>You can see the script at <a href="http://www.kingoslo.com/instruments/" rel="nofollow">http://www.kingoslo.com/instruments/</a></p>
  
  <p>With firebug I get error saying that context is undefined, which I think is strange.</p>
  
  <p>Thanks.</p>
  
  <p>Kind regards,
  Marius</p>