  $(document).ready(function() 
    { 
      var fileTypes = {
        doc:  '/images/icon_word.gif',
        docx: '/images/icon_word.gif',
        pdf:  '/images/icon_pdf.gif',
        ppt:  '/images/icon_powerpoint.gif',
        pptx: '/images/icon_powerpoint.gif',
        xls:  '/images/icon_excel.gif',
        xlsx: '/images/icon_excel.gif'
    };
      var altText = {
        doc:  'Microsoft Word',
        docx: 'Microsoft Word',
        pdf:  'PDF',
        ppt:  'Microsoft PowerPoint',
        pptx: 'Microsoft PowerPoint',
        xls:  'Microsoft Excel',
        xlsx: 'Microsoft Excel'
      };
             
      // iterate over the matched elements
      $('a').each(function() {
       
        // get a jQuery object for each anchor found
        var $a = $(this);
        
        // don't add icons to images that are hyperlinked (eg, lightboxes, PDF thumbnails, etc)
        if ($a.has('img').length == 0) { 
        
        
          // get the whole href attribute value
          var href = $a.attr('href');
  
          // get the extension from the href
          if(typeof(href) !== 'undefined') {
            var hrefArray = href.split('.');
            var extension = hrefArray[hrefArray.length - 1].toLowerCase();
           
            var image = fileTypes[extension];
            
            // add the icon!
            if (image) {
              //console.log('image:'+image);  
              $('<img />', {'src': image,
                          'alt':  altText[extension],
                          'style': 'margin-left:4px; vertical-align:baseline; '}).appendTo($a);
                
            }
        }
      }
       
      });
    } 
  );

