(function( $ ){
  $.fn.UrlTarget = function(whiteListRegExps, targetName) {
  
    return this.each(function() {
    	var href = $(this).attr('href');
    	
    	if (href.match(/((http:\/\/)|(https:\/\/))/i)) {
    		var a = document.createElement("a");
				a.href = href;
				var hostname = a.hostname;
				
				var whitelisted = false;
				
				if (whiteListRegExps != null)
				{		
					$.each(whiteListRegExps, function(index, name) {
						var re = new RegExp(name, 'i');
						if (re.test(hostname))
							whitelisted = true;
					});
				}
				
				if (targetName == null)
					targetName = '_blank';
				
				if (!whitelisted && ($(this).attr('target') == null || $(this).attr('target').length == 0))
					//$(this).attr('target', targetName);
					$(this).attr('target', '_blank');
					//strip http:// and https://
					var targeturl = href.replace("https://", "");
					targeturl = targeturl.replace("http://", "");
					$(this).attr('href', '/analytics/?url='+targeturl);
			}
    });
  };
})( jQuery );

