/* (c)2009 Dan Masquelier - www.danmasq.com */

/* jQuery Image Slideshow (w/ Alpha Fade)
--------------------*/
/* Notes:
In view, use <img> for intended images or use <span> for background-images.
Give first <img> or <span> the "active" class (e.g. <img class="image_1 active"/>
*/
var slideDelay = 10000; // Time between images in milliseconds
var transitionTime = 6000; // Transition Time between in milliseconds

function slideshow() {
    var $active = $('#slideshow img.active, #slideshow span.active');

    if ( $active.length == 0 ) $active = $('#slideshow img:last, #slideshow span:last');

    // use this to pull the images in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('#slideshow img:first, #slideshow span:first');

    // Randomize
    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $( $sibs[ rndNum ] );

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, transitionTime, function() {
            $active.removeClass('active last-active');
        });
}

// Run Slideshow
$(function() {
    setInterval("slideshow()", slideDelay);
});
