﻿
 /* Loops through all hrefs checking for reference to .pdf or .zip and attaches onclick code for Google Analytics */
  
  $(function() 
  {
      var myHref, newHref;

      $("a").each(function() 
      {
          myHref = ($(this).attr("href")) ? $(this).attr("href") : "";

          if (myHref.toLowerCase().indexOf(".pdf") != -1 || myHref.toLowerCase().indexOf(".zip") != -1 || myHref.toLowerCase().indexOf(".mp4") != -1)
          {
              if ($(this).attr("onclick") == null) 
              {
                  newHref = (myHref.split("/"))[(myHref.split("/")).length - 1]
                  $(this).attr("onclick", "javascript:pageTracker._trackPageview('File:" + newHref + "');")
              }
          }
      });
  });
  