$( document ).ready( init );

// change home page images every 3 secs
function init(){
    setInterval( 'update_images()', 3000);
}

// run this only on the front page
function update_images(){
    $('body.front').each( slideshow );
}

// call the php script to get the filename JSON styles 
// and pass them on to add_images
function slideshow(){
    var random = Math.random();
    $.getJSON('/ajax/select_photos.php?random='+random, add_image);  
}

function add_image( data ){
    // get a random number between 1 and 8 to select which image we change
    var rand_num = Math.floor( (8)*Math.random() );
    // grab the wrapped set of img's, pick out the random one, fade it out, change the 
    // src attribute and fade it back in
    $('div#home_pics').children().slice( rand_num, (rand_num+1) ).fadeOut( 'slow', function(){
        this.src = '/sites/default/images/homepage_slideshow/' + data[0];
    }).fadeIn('slow');
}

