


var headline_count;
var headline_interval;
var old_headline = 0;
var current_headline = 0;

$(document).ready(function(){

    var ScrollApi = $("div.scrollable").scrollable({
        size: 1,
        navi: ".navigation",
        speed: 500,
        api: true

    });

    function autoScroll(){
        if(ScrollApi.getIndex() == 4){
            ScrollApi.begin();
        }else{
            ScrollApi.nextPage();
        }

    };

    scrollInterval = setInterval(autoScroll,5000);
    $('#newestArticles').hover(function() {
        clearInterval(scrollInterval);
    }, function() {
        scrollInterval = setInterval(autoScroll,5000);
    });

    headline_count = $("div.headline").size();
    $("div.headline:eq("+current_headline+")").css('top','5px');

    headline_interval = setInterval(headline_rotate,5000); //time in milliseconds
    $('#scrollup').hover(function() {
        clearInterval(headline_interval);
    }, function() {
        headline_interval = setInterval(headline_rotate,5000); //time in milliseconds
    });
});

function headline_rotate() {
    current_headline = (old_headline + 1) % headline_count;
    $("div.headline:eq(" + old_headline + ")").animate({
        top: -205
    },"slow", function() {
        $(this).css('top','210px');
    });
    $("div.headline:eq(" + current_headline + ")").show().animate({
        top: 5
    },"slow");
    old_headline = current_headline;
}