// Add an onclick event to all links to certain kinds of file
// Call urchinTracker() with the linked filename
function trackDownloadLinks()
{
  if (!document.getElementsByTagName) return;
  var anchors = document.getElementsByTagName("a");
  for (var i=0; i<anchors.length; i++) {
    var anchor = anchors[i];
    // Only anchors with a file extension (no rails page urls have one)
    // Add extensions to track to the pattern below
    if(anchor.href.match(/\.(pdf)|(xls)|(doc)$/i)){
      anchor.onclick = function(){
        // Match the filename only, not the full URL
        filename = this.href.match(/[^\/]+$/);
        urchinTracker(filename);
      }
    }
  }  
}
addLoadEvent(trackDownloadLinks);
