function setupSlider() {
  var randomImg = Math.floor(Math.random() * 6);
  $('#main-image img:eq(' + randomImg + ')').addClass('active');
}

function slideSwitch() {
    var $active = $('#main-image img.active');

    if ( $active.length == 0 ) $active = $('#main-image img:last');

    var $next =  $active.next().length ? $active.next()
        : $('#main-image img:first');

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

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

$(function() {
    setupSlider();
    setInterval( "slideSwitch()", 8000 );
});

