function handleKeyPress(evt) {
  var ignoreKeyPress = document.body.getAttribute('ignoreKeyPress');
  if(ignoreKeyPress == '1')
    return;
  // Mozilla is weird about this
  // Taken from http://www.faqts.com/knowledge_base/view.phtml/aid/32261
  var keyCode =  evt.keyCode ? evt.keyCode :
                 evt.which ? evt.which : 
                 void 0;

  // p - Previous slide
  if(keyCode == 112)
    prevSlide();
  // n - Next slide
  else if(keyCode == 110)
    nextSlide();
  // a - new Annotation
  else if(keyCode == 97) {
    // What a dirty hack
    if($('user_bar').innerHTML.indexOf('not logged in') == -1) 
      annotate();
  }
}

function initInputs() {
  // First check if they are typing into a text field, and if so, return
  var inputList = document.getElementsByTagName('input');
  var taList = document.getElementsByTagName('textarea');

  for(var i = 0; i < inputList.length; i++) {
    var type = inputList[i].getAttribute('type');
    if(type == 'text' || type == 'password') {
      protectElement(inputList[i]);
    }
  }

  for(var i = 0; i < taList.length; i++) {
    protectElement(taList[i]);
  }
}

function protectElement(e) {
  e.onfocus = function() { document.body.setAttribute("ignoreKeyPress", 1); }
  e.onblur = function() { document.body.setAttribute("ignoreKeyPress", 0); }
}

function nextSlide() {
  var nextLink = $('nextLink');
  if(nextLink != null)
    window.location = nextLink.href;
}

function prevSlide() {
  var prevLink = document.getElementById("prevLink");
  window.location = prevLink.href;
}