Try to understand that the comment line in your code
Code:
//once fadeout has completed, change src attribute of "imgm" to value of imgUrl, then fade in
is wrong, from the point of view of the asynchronous program flow. The order will be
1 - Start the fadeOut (running asynchronously)
2 - Set the src of imgm to the new imgURl (fadeOut is still being processed). The loading process of the image will start (running asynchronously)
3 - Start the fadeIn (running asynchronously). The fadeOut is still being processed, so fadeIn will only run after fadeOut finished (implicit queue). The loading process of the image might still be in progress
4 - Run setup again, which will run anim again (very very fast ... so all of the fadeOut and fadeIn will be queued very very fast but will run one after the other in intervals of 3 seconds)