﻿function slideSwitch(id, nextId, duration) {
    var $active = $('#' + id + ' .active');
    if ($active.length == 0) {
        $active = $('#' + id + ' *:first');
    }

    var $next;
    if (nextId) {
        $next = $('#' + nextId);
    } else {
        $next = $active.next().length ? $active.next() : $('#' + id + ' *:first');
    }

    if (!$active.attr('id') || ($active.attr('id') !== $next.attr('id'))) {
        switchTwoSlides($active, $next, duration);
    }
}


function switchTwoSlides($active, $next, duration) {
    $active.addClass('last-active');

    $active.animate({ opacity: 0.0 }, duration || 1000);
    $next.css({ opacity: 0.0 })
                 .show()
                 .addClass('active')
                 .animate({ opacity: 1.0 }, duration || 1000, function () {
                     $active.removeClass('active last-active');
                 });
}


$(function () {
    setInterval("slideSwitch('slideShow')", 8000);
});
