jQuery(document).ready(function() {

  // Creating custom :external selector
  jQuery.expr[':'].external = function(obj){
      return !obj.href.match(/^mailto\:/)
              && (!(obj.href.match(/paxworld\.com/))) && obj.innerHTML != "?" && !obj.href.match(/app\.streamsend\.com/);
  };

  // Add 'external' CSS class to all external links
  jQuery('a:external').addClass('external');

  jQuery('.external').click(function() {
    var link = jQuery(this).attr('href');

    jQuery('<div>You are now leaving PaxWorld.com. Thank you for visiting. Pax World Management Corp. and ALPS Distributors, Inc. are not responsible for the content on the page you are linking to. Please click OK to continue and open your link in a new window. Close the new window at any time to return to PaxWorld.com.</div>').dialog({
      title: "External Link",
      modal : true,
      overlay: {
        backgroundColor: '#000',
        opacity: 0.5
      },
      buttons: {
        'Okay': function() {
          jQuery(this).dialog('close').remove();
          window.open(link);
        },
        'Cancel': function() {
          jQuery(this).dialog('close').remove();
          return false;
        }
      }
    });

    return false;
  });
});
