﻿function RotateStories(newsCount) {

    // JScript File
    var storiesToDisplay = 2;
    var currentTopStoryIdx = 0;
    var t = (newsCount > storiesToDisplay) ? window.setInterval(scrollStories, 7000) : null;

    //scrolls the stories down by 1, makes "storiesToDisplay" stories visible at a time
    function scrollStories() {

        for (var i = 0; i < storiesToDisplay; i++) {
            var tmpIdx = currentTopStoryIdx + i;

            if (tmpIdx >= newsCount) {
                break;
            }

            document.getElementById("newsStoryDiv" + tmpIdx).style.display = "none";
        }

        //update to a new top story index
        if (currentTopStoryIdx + storiesToDisplay < newsCount)
            currentTopStoryIdx += storiesToDisplay;
        else
            currentTopStoryIdx = 0;

        for (var j = 0; j < storiesToDisplay; j++) {
            var tmpIdxj = currentTopStoryIdx + j;

            if (tmpIdxj >= newsCount) {
                break;
            }

            document.getElementById("newsStoryDiv" + tmpIdxj).style.display = "block";
        }
    }
}