$(function () {
    $('#page-switcher').on('change', function(e) {
        var page = $(e.target).val();
        window.location = '/page/' + page;
    });

    $(document).on('keydown', function(e) {
        // Only replace the arrow key functionif there are not needed
        if ($('form input, form textarea').filter(':focus').length > 0)
            return;

        switch (e.keyCode) {
        case 76: // l
        case 39: // -->
            var prevUrl = $('#prev-image').attr('href');
            if (prevUrl !== undefined) window.location = prevUrl;
            break;
        case 72: // h
        case 37: // <--
            var nextUrl = $('#next-image').attr('href');
            if (nextUrl !== undefined) window.location = nextUrl;
            break;
        }
    });
});
