/**
 * jQuery Google Analytics Link Tracking plugin v1.0
 * http://www.gerryvandermaesen.com/, http://www.morris-chapman.be/
 * 
 * Copyright (c) 2009 Gerry Vandermaesen, Morris & Chapman Belgium
 * Dual licensed under the MIT and GPL licenses.
 * http://docs.jquery.com/License
 */
(function($) {
	$.fn.extend({
		gaLinkTrack: function(options) {
			options = $.extend({ path: '/{rel:external}/{domain}/{page}' }, options);
			this.click(function() {
				var path = options.path, matches, data;
				matches = /^.+:\/\/(?:.+@)?([^:\/]+)(?::[^\/]+)?\/([^#]+)/.exec(this.href);
				data = {
					domain: matches[1],
					page: matches[2],
					rel: this.rel
				};
				$.each(data, function(k, val) {
					var pattern, matches;
					pattern = new RegExp('{' + k + '(?::(.+?))?}', 'g');
					while ((matches = pattern.exec(options.path)) !== null) {
						path = path.replace(matches[0], val || matches[1] || 'undefined');
					}
				});
				try {
					pageTracker._trackPageview(path);
				} catch (err) {}
			});
			return this;
		}
	});
})(jQuery);
