﻿function theRotator() {
    var counter = 0;
    $('#carousel div').each(function () {
        if (counter == 0)
            $(this).css({ opacity: 1.0 });
        else
            $(this).css({ opacity: 0.0 });
        counter++;
    });
    if (counter > 1)
        setInterval('rotate()', 5000);
}

function rotate() {
    if (true) {
        var current; 
        $('#carousel div').each(function () {
            if ($(this).css('opacity') == 1) {
                current = $(this);
            }
        });
        var next = current.next().length ? current.next() : $('#carousel div:first');
        next.animate({ opacity: 1.0 }, 2000);
        current.animate({ opacity: 0.0 }, 2000);
    }
};

$(document).ready(function () {
    theRotator();
});
