function keys(key) {
  if (!key) key=window.event;
  if (key.keyCode) key=key.keyCode;
  if (key.target) key=key.which;
  var links = document.getElementsByTagName('link');

  if (key == 37 || key == 33 || key == 38 || key == 75) {
    /* go backwards */
    for (var i=0; i<links.length; i++) {
      if (links[i].getAttribute("rel") == "prev") {
       document.location = links[i].getAttribute("href");
      }
    }
  } else if (key == 39 || key == 74 || key == 32 || key == 34 || key == 40) {
    /* advance */
    for (var i=0; i<links.length; i++) {
      if (links[i].getAttribute("rel") == "next") {
       document.location = links[i].getAttribute("href");
      }
    }
  }  
}

document.onkeyup = keys;
document.onclick = function() {keys(39);}

// allow IE to recognize HTMl5 elements
if (!document.createElementNS) {
  document.createElement('article');
  document.createElement('section');
  document.createElement('aside');
  document.createElement('footer');
  document.createElement('header');
  document.createElement('nav');
  document.createElement('time');
}

if (document.addEventListener) {
  var show_clock = function() {
    var heads = document.getElementsByTagName('header');
    if (heads.length == 0) return;
    var text=document.createTextNode('00:00:00Z');
    var span = document.createElement('time');
    span.appendChild(text);
    heads[0].appendChild(span);
    var update = function() {
      var now = new Date().toGMTString().match(/\d\d:\d\d:\d\d/).toString();
      text.replaceData(0,7, now.substr(0,7));
      setTimeout(update,1000*(10-parseInt(now.substr(7,1))));
    }
    update();
  }
  document.addEventListener("DOMContentLoaded", show_clock, false);
}

