var line_offset = -37;
var target_y    = -1;
var current_y   = -1;
var step        = -1;

function slide_news_up() {
    var item = $("ul#ticker");
    item.css("position", "relative");
    
    step = -1;
    // For a never-ending list, the line below works
    //target_y = target_y + line_offset; 
    current_y = -1;
    target_y  = line_offset;
    move(item, current_y, target_y);
}

function move(item, current, target) {
    if (current <= target) {
        current_y = target; // redundant currently.
        $('ul#ticker').append($('ul#ticker li:first'));
        $('ul#ticker').css("top", -1);
        return;
    }
    item.css("top", current+"px");
    setTimeout(function() {
        step = step * 1.5;
        move(item, current + step, target);
    }, 20);
}
function set_sizes() {
    $("#container").css("height", "auto");
    if ($(document).height() > $("#container").height())
        $("#container").css("height", $(document).height()+"px");
}

$(window).resize(set_sizes);
$(document).ready(function() {
    set_sizes();
    interval = setInterval(slide_news_up, 3000);
});