﻿/*window.addEvent('domready', function () {
    var showDuration = 15000;
    var container = $('Featured').getChildren();
    var currentIndex = 0;
    container.each(function (div, d) {
        if (d > 0) {
            div.set('opacity', 0).setStyle('display', 'none');
        }
    });

    var show = function () {
        container[currentIndex].fade('out');
        (function () {
            container[currentIndex].setStyle('display', 'none');
            var next = currentIndex = currentIndex < container.length - 1 ? currentIndex + 1 : 0;
            container[next].setStyle('display', 'block');
            container[next].fade('in');
        }).delay(500);

    };

    window.addEvent('load', function () {
        interval = show.periodical(showDuration);
    });
});

*/
var showDuration = 12000;
var currentIndex = 0;
var items = $("#Featured").children();

$(document).ready(function () {
    items.each(function (index) {
        if (index != 0) {
         $(this).fadeOut();
        }
    });

    setTimeout(function () {
        showNext();
    }, showDuration-1000);


});

var showNext = function () {
    $(items[currentIndex]).fadeOut();
    setTimeout(function () {
        if ((currentIndex + 1) < items.length) {
            currentIndex = currentIndex + 1;
        }
        else {
            currentIndex = 0;
        }

        $(items[currentIndex]).fadeIn();
    }, 400);

    setTimeout(function () {
        showNext();
    }, showDuration);
};

