Javascript order on which functions are being called
<p>Hi I am still pretty new to programming and I haven't had the chance to fully understand Java or Javascript the only programming languages I know but I am trying really hard to understand Javascript.</p>

<p>What I am facing is that some times I do not understand when javascript is calling my created functions for example. I have created a small plugin for jQuery: <a href="http://jsfiddle.net/a9gjK/1/" rel="nofollow">http://jsfiddle.net/a9gjK/1/</a></p>

<p>The plugin is very easy the images are set on top of each other using position absolute. I then take the first image and set the z-index to 100 then I take the next image and set it's z-index to 50 after this I take the first image again and fade it to 0 opacity, then I call a callback function witch sets the first image's z-index to 0 and fade it to 1 opacity and the next image's z-index to 100.</p>

<p>After this hole process is done the variable first is set to the next element.This is where my problem appears. If I set the variable first to the next img inside the callback function the plugin works well and everything is well, but if I do this outside the callback function after the script is ran once on each image and has to start again from the first image when it fade's out I see the background. This doesn't happen if I set the first image to next inside the callback function.</p>

<p>Can anyone explain why this is happening and on what topic is this related so I can read and understand better what's happening.</p>
