﻿$(function() {
    // set up scrolling div
    $("div.newswrapper.scrolling .newslistcontainer").jScrollPane({ scrollbarWidth: 0, scrollbarMargin: 0, animateInterval: 40, maintainPosition: false });
    // scroll with up arrow
    scrollDiv("div.newswrapper.scrolling .ScrollControls img:eq(0)", "div.newswrapper.scrolling .newslistcontainer", -15);
    // scroll with down arrow
    scrollDiv("div.newswrapper.scrolling .ScrollControls img:eq(1)", "div.newswrapper.scrolling .newslistcontainer", 15);
});

function scrollDiv(trigger, div, verticalpixels) {
    var t;
    $(trigger).unbind();
    if ($(div).siblings(".jScrollPaneTrack").length > 0) {
        $(trigger).mouseover(function() {
            t = setInterval(function() {
                $(div)[0].scrollBy(verticalpixels);
            }, 100);
            $(trigger).addClass("hover");
        }).mouseout(function() {
            clearInterval(t);
            $(trigger).removeClass("hover");
        });
    }
}