Functions don't execute in the order I expect when using setTimeout()
<p>I have this code where I am using two javascript functions that do some manipulating for me. One function does some calculation but calls the other function before doing anything else. When the other function returns to it, it is supposed to do the final calculations.</p>

<p><strong>The problem:</strong> The call to the other function is not executing properly. Even before the second function returns the first function executes completely.
  <strong>code:</strong> </p>

<pre><code>firstfunction{

        secondfunction();

        do something more nothing related to second
     }

secondfunction(){

           setTimeout(func1(){
               do something independently
                 then call func1 depending on some condition
               },time);     
         }
</code></pre>

<p>second function is used somewhere else also and is working fine.</p>

<p><strong>My question:</strong>
   I used this code thinking that the first function will not execute before second function executes completely. Is it right? Isn't this the way javascript functions should run? The first function executes completely before second returns. I am sure of this because after second returns the position for the graphic first is supposed to place that graphic on screen. But the first executes completely and the graphic is placed awkwardly on screen and viewer can see it moving to right position given by the loop of second. Is <code>setTimeout</code> causing this problem?
Please help.  </p>
