﻿function slideSwitch() {
    var $active = $('#quotes DIV.active');

    if ($active.length == 0) $active = $('#quotes DIV:last');

    // use this to pull the divs in the order they appear in the markup
    var $next = $active.next().length ? $active.next() : $('#quotes DIV:first');

    // uncomment below to pull the divs randomly
    var $sibs  = $active.siblings();
    $sibs.hide();
    var rndNum = Math.floor(Math.random() * $sibs.length );
    var $next  = $( $sibs[ rndNum ] );
    var len = $("#quotes > div").size();

    if (len > 1) {
        $active.addClass('last-active');
        $active.hide();
        $next.show();
        $next.css({ opacity: 0.0 })
                        .addClass('active')
                        .animate({ opacity: 1.0 }, 2000, function() {
                            $active.removeClass('active last-active');
                        });
    }
    else {
        $active.show();
        $next.css({ opacity: 1.0 }).addClass('active');
        $active.removeClass('active');
    }
}
$(function() {
    /* Show first quote without waiting for the interval */
    slideSwitch();
    setInterval("slideSwitch()", 20000);
});