/*
 * KEYBOARD NAVIGATION
 */

var keyboard_navigation_enabled = true;
var KEY_LEFT_ARROW = 37;
var KEY_RIGHT_ARROW = 39;
var KEY_SLASH = 191;
var FFFFFFUUUUUUU = '_jerkcity';
var handlers = new Object();

addKeyboardHandler (KEY_LEFT_ARROW, handleLeftArrow);
addKeyboardHandler (KEY_RIGHT_ARROW, handleRightArrow);
addKeyboardHandler (KEY_SLASH, handleSlash);

function addKeyboardHandler (key, callback)
{
    handlers[key] = callback;
}

function handleLeftArrow()
{
    if (wot <= 1) return;
    --wot;
    window.location.href = '/' + FFFFFFUUUUUUU + wot + '.html';
}

function handleRightArrow()
{
    if (wot >= high) return;
    ++wot;
    window.location.href = '/' + FFFFFFUUUUUUU + wot + '.html';
}

function handleSlash()
{
    keyboard_navigation_enabled = false;
    document.search.q.focus(); 
}

function handleKeyUp(e)
{
    if (! keyboard_navigation_enabled) 
        return;

    e = e || event;
    var code = e.which || e.keyCode;

    if (code != undefined && handlers[code] != undefined) 
        handlers[code]();
}

document.onkeyup = handleKeyUp;

