// Creating custom :external selector
$.expr[':'].external = function(obj){
    return !obj.href.match(/^mailto\:/)
            && (obj.hostname != location.hostname)
			&& (!obj.href.match(/^javascript/));
};

$(document).ready(function() {

	// All external links
	$('a:external').click(function() {
		$(this).attr("target", "_blank");
		
		if($(this).attr("onclick")==undefined){
			var linkHostname = get_hostname_from_url($(this).attr('href'));
			pageTracker._trackEvent('link', 'click', linkHostname);
		}
	});


	//all PDF links in new window
	$("a[href*=.pdf]").click(function(){
		$(this).attr("target", "_blank");
	});

});


function get_hostname_from_url(url) {
	return url.match(/:\/\/(.[^/]+)/)[1];
}
