$(document).ready(function() {

  // Creating custom :external selector
  $.expr[':'].external = function(obj){
      return !obj.href.match(/^mailto\:/)
				&& (obj.hostname != "director.ilsoy.org")
      	&& (obj.hostname != "www.ilsoy.org")
				&& (obj.hostname != "ilsoy.org")
				&& (obj.hostname != "secure.ilsoy.org")
				&& (obj.hostname != "soy2020.ilsoy.org")
				&& (obj.hostname != "www.soyyieldchallenge.com")
				&& (obj.hostname != "soyyieldchallenge.com")
				&& (obj.hostname != "www.soycam.com")
				&& (obj.hostname != "soycam.com")
				&& (obj.hostname != "www.podtoplate.org")
				&& (obj.hostname != "podtoplate.org")
				&& (obj.hostname != "www.getb11.info")
				&& (obj.hostname != "getb11.info");
  };

  // Add 'external' CSS class to all external links
  $('a:external').addClass('external');

  $('.external').click(function() {
    var link = $(this).attr('href');

    $('<div>You are now leaving an Illinois Soybean Association website.</div>').dialog({
      title: "External Link",
      modal : true,
      overlay: {
        backgroundColor: '#000',
        opacity: 0.5
      },
      buttons: {
        'Proceed': function() {
          $(this).dialog('close').remove();
          window.open(link);
        },
        'Cancel': function() {
          $(this).dialog('close').remove();
          return false;
        }
      }
    });

    return false;
  });
});
