jQuery(function($){
    var nextId = 0;
    var prevId = 0;

    var myTarget = $('#cases_viewer').get(0);

    myTarget.scrollLeft = myTarget.scrollTop = 0;

    $.localScroll.hash({
        target: myTarget,
        axis:'xy',
        queue:true,
        duration:1500
    });


    $('#cases').localScroll({
        target: myTarget,
        axis:'xy',
        queue:true,
        duration:1000,
        hash:true,
        //event:'mouseover',
        onBefore:function(e, anchor, $target){
            var a = $(this);

            if(a.attr('id') == 'nextCase') {
                var thisId = parseInt(a.attr('href').slice(7));
                nextId = thisId + 2;
                prevId = thisId - 2;
            }

            if(a.attr('id') == 'prevCase') {
                var thisId = parseInt(a.attr('href').slice(7));
                nextId = thisId + 2;
                prevId = thisId - 2;
            }
        },
        onAfter:function(anchor){
            $('#nextCase').attr('href', '#cases_' + nextId);
            $('#prevCase').attr('href', '#cases_' + prevId);
        }
    });
});