// rel Keyboard Navigation
// Copyright (c) 2008 Christoffer Sawicki <christoffer.sawicki@gmail.com>
//
// Licensed under WTFPL (Do What The Fuck You Want To Public License) version 2
// http://sam.zoy.org/wtfpl/COPYING
//
// Requirements:
// * W3C DOM Level 2 Events
// * Selectors API
//
// These can be fulfilled for all common web browsers with
// Dean Edwards' Base2 (http://code.google.com/p/base2/).

if (base2 && base2.DOM) { base2.DOM.bind(document); }

(function() {

var ArrowKeys = {
  37: "left",
  38: "up",
  39: "right",
  40: "down"
}

function handleKeyUp(event) {
  var direction = ArrowKeys[event.keyCode];
  
  if (direction) {
    var link = document.querySelector("*[rel~=" + direction + "]");
    
    if (link) {
      window.location = link.href;
    }
  }
}

document.addEventListener("keyup", handleKeyUp, false);

}());