var currentNewsIndex = 0;
var newsList = new Array();

window.onload = function() {
    currentNewsIndex = 0;
    newsList = getNewsList();
    var interval = 5; // Interval in seconds
    var count = 2;

    // rotate news display:
    if (newsList.length > 0) {
        ShowNews(0, true);
        if (newsList.length > 1) {
            window.setInterval(function() {
                ShowNews(currentNewsIndex, false);

                if (count > 0 && currentNewsIndex == 0) count--;
                else {
                    count = 2;
                    currentNewsIndex++;
                    if (newsList.length == currentNewsIndex)
                        currentNewsIndex = 0;
                }
                ShowNews(currentNewsIndex, true);
            }, interval * 1000);
        }
    }
}

function getNewsList(){
    var i = 0;
    var _NewsUL = document.getElementById("news");
    
    List = new Array();

    if(_NewsUL){
        if(_NewsUL.hasChildNodes){
            for(var node = 0; node < _NewsUL.childNodes.length; node++){
                if(_NewsUL.childNodes[node].firstChild != null){ // if "li"
                    List[i] = _NewsUL.childNodes[node];
                    i++;
                }
            }
        }
    }

    return List;
}

function ShowNews(index, show){
    newsList[index].style.display = (show)? 'inline': 'none';
}