﻿$(function() {
    if ($("div.storieswrapper.scrolling .storieslistcontainer").length > 0) {
        // set up scrolling div
        $("div.storieswrapper.scrolling .storieslistcontainer").jScrollPane({ scrollbarWidth: 0, scrollbarMargin: 0, animateInterval: 40, maintainPosition: false });
        // scroll with up arrow
        scrollDiv("div.storieswrapper.scrolling .ScrollControls img:eq(0)", "div.storieswrapper.scrolling .storieslistcontainer", -15);
        // scroll with down arrow
        scrollDiv("div.storieswrapper.scrolling .ScrollControls img:eq(1)", "div.storieswrapper.scrolling .storieslistcontainer", 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");
        });
    }
}