When to load an image to use the Javascript function drawImage()?
<p>I would like to use the drawImage() function to load an image in a Javascript animation, but the image does not load with my current code.  I think I need to specifically ask for the image to be loaded at some point, but I'm not sure when or how.  The idea is to make a cloud that goes across the canvas. Thank you for your help.</p>

<pre><code>function draw(x,y){
    var canvas = document.getElementById('canvas');
    var ctx = canvas.getContext('2d');
    x += 2;
    if(x&gt;1000){
        x=0;
    }

    var cloud = new image();
    cloud.src='small_cloud.png';
    ctx.drawImage(cloud,x,0);

    var loopTimer = setTimeout('draw('+x+','+y+')',20);

}
</code></pre>
