﻿var index = 0;

var sift = function () {
    index++;
    var images = $('#headlines_list li');
    if (index > images.length) {
        index = 1;
    }
    $('#headlines_list li#' + parseInt(index)).click();
};

$(document).ready(function () {
    sift();
    var refreshIntervalId = setInterval("sift()", 6000);
    $('#headlines_list li').click(function (e) {
        if (e.detail)
            clearInterval(refreshIntervalId);

        var count = $('#headlines_list li').length;
        var currIdx = parseInt($(this).attr('id'));
        var prevIdx = currIdx == 1 ? count : currIdx - 1;

        $('#headlines_list li').each(function () {
            $(this).removeClass('selected');
            $(this).removeClass('bottom');
        });

        var Headline = 'headline' + $(this).attr('id');

        var prevHeadline = 'headline' + prevIdx;
        $('.headline_image_cont').fadeOut(800);
        $('#' + Headline).stop().fadeIn(800);

        $(this).addClass('selected');

        if ($(this).attr('id') < 7) {
            $('#headlines_list li#' + (parseInt($(this).attr('id')) + 1)).addClass('bottom');
        }
    });
});
