(function($) {
	$.fn.extend({
		extlink: function() {
			var site = String(document.location)
				.replace(/^(https?:\/\/[^:\/]+).*$/, "$1")
				.replace(/^((site)?(file:\/\/.+\/))[^\/]+$/, "$3")
				.replace(/(\\.)/g, "\\$1");
			$("a", this).filter(function(i) {
				var href = $(this).attr("href");
				if (href == null)
					return false;
				return (
					href.match(RegExp("\\.(pdf|docx?|xlsx?|pptx?|txt|eps|tif|psd|dwg|vsd)")) != null || href.match(RegExp("^(" + site + "|(https?:)?/[^/])")) == null && href.match(RegExp("^(https?|ftp)://.+")) != null
				);
			}).each(function() {
				if ($(this).attr("title").length == 0) {
					$(this).attr("title", $(this).html());
				}
				$(this)
					//.attr("title", $(this).attr("title") + " (öppnas i ett nytt fönster)")
					.addClass("external");
				$(this).click(function() {
					window.open($(this).attr("href"));
					return false;
				});
			});
		}
	});
})(jQuery);

$(document).ready(function() {
	$(this).extlink();
});
