// JavaScript Document

var scrollTime = 1000;//how long the scroll lasts
var newsscrolling = true;
var divToScroll = 'scroll-inner'; //div containig list to scroll
var scrollt = 0;
var scrollInterval = 15000; //time between scrolls

$(function () {
    //toddle scrolling on mouse events
    $('#scroll-inner').mouseenter(function () {
        newsscrolling = false;
    });

    $('#scroll-inner').mouseleave(function () {
        newsscrolling = true;
    });
    //set timer
    scrollt = setInterval(swapTopBot, scrollInterval);
});

function swapTopBot() {
    // clones the last item, prepends to list then removes the last

    if (newsscrolling) {
        var el = $('#' + divToScroll + ' ul'); //target the list
        var last = $('li:last', el); 
        el.prepend(last.clone());// clone the last item
        var first = $('li:first', el);

        //set position based on item size
        first.css({
            marginTop: 0 - first.outerHeight(),
            position: 'relative',
            top: 0 - (parseInt(el.css('padding-top')))
        });
        //scroll list then remaove last item
        first.animate({ marginTop: 0 }, scrollTime, function () {
            last.remove();
        });
    }
}

