$(document).ready(function() {
  // Creating custom :external selector

  $.expr[':'].external = function(obj){

      return !obj.href.match(/^mailto\:/)
                
            && !obj.href.match(/^tel\:/)

              && (obj.hostname != location.hostname)

              !obj.href.match(/#/);

  };


  // Add 'external' CSS class to all external links

  $('a:external').addClass('external');


  $('.external').click(function() {

    var link = $(this).attr('href');

    var warningMsg = '<div>You are currently leaving our site, and headed towards: <br /> '+(link)+' <br /> are you sure you want to proceed?</div>';
    $(warningMsg).dialog({

      title: "External Link",

      modal : true,

      overlay: {

        backgroundColor: '#000',

        opacity: 0.5

      },

      buttons: {

        'Okay': function() {

          $(this).dialog('close').remove();

          window.open(link);

        },

        'Cancel': function() {

          $(this).dialog('close').remove();

          return false;

        }

      }

    });


    return false;

  });

})
