// JavaScript Document

// The following is used to insert the external link image icon immediately after all external links.  
// The safeList var determines which links are internal/external.
	var safeList = new Array('airprojects.org', 'dev2-iwgyp.airprojects.org', 'nationalservice.org', 'addthis.com');
	
	// (Only works with elements that have href):
	// Compares safeList against all href attributes within A tags
	$.extend($.expr[':'], {
		external: function(a, i, m) {
			if (!a.href) { return false; }
			if (a.hostname && a.hostname !== window.location.hostname) {
				var fixedHostname = a.hostname.replace(/^\s+|\s+$/g, '').replace('www.', '').toLowerCase();
				if (jQuery.inArray(fixedHostname, safeList) >= 0 || a.hostname.indexOf(".gov") >=0 || a.hostname.indexOf(".mil") >=0) {
					return false;
				}
				else return true;
			}
			else return false;
		}
	});
	
	// Inserts icon behind link and wrap the image in a link leading to the disclaimer page
	$(document).ready(function() {
		$('a:external').ready(function addExtLink() {
				if (document.createElement){
					var linkImg=document.createElement('img');
					linkImg.style.marginLeft='2px';
					linkImg.setAttribute('src','http://www.hhs.gov/web/images/exit_small.png');
					linkImg.setAttribute('class','disclaimer');
					linkImg.setAttribute('alt','External Web Site Policy');
					linkImg.setAttribute('title','External Web Site Policy');
					$('#content a:external').after(linkImg);
					$('img.disclaimer').wrap('<a class="disclaimer" href="/ExternalLink.aspx">');
				}
		});
	});