(function($, Lego) {

var currentPager;

function goByHref(el) {
    el[0] && !!el.attr('href') && (window.location.href = el.attr('href'));
}

Lego.block['b-pager'] = function(params) {

    if(currentPager) {
        return params.override && (currentPager = $(this));
    }

    currentPager = $(this);
    $(document).keydown(function(e) {
        if(!e.ctrlKey || $(e.target).is('input, textarea')) {
            return;
        }

        if(e.keyCode == 37) { // <-ctrl
            goByHref(currentPager.find('.b-pager__prev'));
        }
        else if(e.keyCode == 39) { // ctrl->
            goByHref(currentPager.find('.b-pager__next'));
        }
    });

};

})(jQuery, window.Lego);
