/* Encapsulation */ (function() {



// openLink
//

function openLink() {

  var address = this.href;
  var index = address.indexOf(".pdf");
  if (index != -1) {
    index += 4;

    // Add a .html to the filename so that apache will match the pdf.html special case
    address = address.substring(0, index) + ".html" + address.substring(index);

    // Convert any hash to a query string so that they get passed to the server.
    // Hashes are used to instruct the pdf reader where to go in a document when it is opened.
    address = address.replace(/\#/g, "?");
  }

  window.open(address);

  return false;
}



// bindLinks
//

function bindLinks() {
  var links = document.getElementsByTagName("a");

  var link, i=0;
  while (link = links[i++]) {
    if (link.href.indexOf(".pdf") != -1) link.onclick = openLink;
  }
}



// init
//

function init() {
  bindLinks();
}





// onload assignment

if (window.onload) {
  var oldInit = window.onload;
  window.onload = function() {
    oldInit();
    init();
  }
}
else {
  window.onload = init;
}





})(); /* Encapsulation */
