$(function() {
    
    // for every link
    $('a').each(function () {
        var href = $(this).attr('href');
        
        // remove the ‘www.’ prefix from the href value (if it exists)
        var domain = location.hostname.replace(/^(www\.)?/, '');
        
        // set up a regular expression that sees if a string starts with http[s]://[www.]mydomain.com
        var re = new RegExp('^https?:\\/\\/(www.)?' + domain);
        
        // guaranteed to be an external link
        if (!re.test(href)) {
            $(this).addClass('target_blank');
        }
        
        // or maybe a pdf
        if (href.match('\\.(pdf|PDF)/?$')) {
            $(this).addClass('target_blank');
        }
    });
    
    $('a.target_blank').click( function() {
        window.open(this.href);
        return false;
    });
    
    
});

