/**
 * Slideshow for BrightNow.com homepage using jQuery
 */

$(document).ready(function() {

    // Set the interval for slideshow
    $(function() {
        setInterval(switchSlide, 4000);
    });

    // Handles slideshow
    function switchSlide() {
        var $active = $('#homeBodyLeft div.active');

        if ($active.length == 0) {
            $active = $('#homeBodyLeft div:last');
        }

        var $next = $active.next('div.slide').length ? $active.next('div.slide') : $('#homeBodyLeft div:first');

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

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