jQuery random image fader
<p>I have a header area which is divided up into block areas for images, these images are absolutely positioned within the block and are all different heights and widths.</p>

<p>I have a URL /random-image?width=x&amp;height=y&amp;random=34234 which generates a random image to use for the specific place.</p>

<p>I want these images to randomly fade out and change for another random image, or to fade on click. I have got it working, except the "setTimeout" or "setInterval" only triggers once. I need it to be on an infinite loop.</p>

<p>Here is my code, any ideas:</p>

<pre><code>jQuery(document).ready(function ($) {

$('#main-image img').live('click', function() {     
    var $image = $(this),
    width = $image.width(),
    height = $image.height(),
    random = Math.random();        

    $('&lt;img src="/random-image?width='+width+'&amp;height='+height+'&amp;random='+random+'" /&gt;').hide().load(function() {
        $(this)
        .appendTo($image.parentsUntil('div.columns'))
        .fadeIn('slow', function() {
            $image.remove();
        });

    });        
});

$('#main-image img').each(function() {
    var $image = $(this),
    randVal = Math.round(5000 + Math.random()*(30000 - 5000)) ;

    setTimeout(function() {
        console.log($image.attr('src'));
        $image.trigger('click');
    },randVal);
});

});
</code></pre>
