var fileTypes = {
  doc: 'doc.gif',
  rtf: 'doc.gif',
  txt: 'doc.gif',
  wps: 'doc.gif',
  docx: 'doc.gif',
  xls: 'xls.gif',
  swf: 'flash.gif',
  swd: 'flash.gif',
  fla: 'flash.gif',
  xls: 'excel.gif',
  csv: 'excel.gif',
  xlt: 'excel.gif',
  xlw: 'excel.gif',
  ppt: 'powerpoint.gif',
  pps: 'powerpoint.gif',
  zip: 'compress.gif',
  gzip: 'compress.gif',
  rar: 'compress.gif',
  pdf: 'pdf.gif'
};

function externalLinks() {
 if (!document.getElementsByTagName) return;
 var anchors = document.getElementsByTagName("a");
 for (var i=0; i<anchors.length; i++) {
   var anchor = anchors[i];
   if (anchor.getAttribute("href") &&
       anchor.getAttribute("rel") == "external")
     anchor.target = "_blank";

  // get a jQuery object for each anchor found
  var $a = anchor;
 
  // get the href attribute
  var href = $a.getAttribute('href');
 
  // get the extension from the href
  var hrefArray = href.split('.');
  var extension = hrefArray[hrefArray.length - 1];
 
  var image = fileTypes[extension];
 
  if (image) {
	  $a.style.background = 'transparent url("i/icons/' + image + '") no-repeat center left';
  }

 }
}

Event.observe( window, 'load', function() {
  externalLinks();
} );