/**
 *
 * Stef A. Spijkerman
 * http://www.saspijkerman.com/
 * mail@saspijkerman.com
 *
 * Version : 1.0
 * Date    : February 4th, 2008
 *
 * Options :
 *
 * class_name   : Add this [string] to the elements class-attribute
 *                (default : 'external')
 * title        : New title [string] or [false] to use prefix and suffix
 *                (default : false)
 * title_prefix : Prefix of new title [string]
 *                (default : 'New window : ')
 * title_suffix : Suffix of new title [string]
 *                (default : '')
 *
 * example : $('a[rel*=external]').externalLinks();
 * example : $('a[href$=.pdf]').externalLinks({ class : 'pdf', title : 'Opens a acrobat document' });
 *
 */

(function(){

	jQuery.fn.externalLinks = function(settings) {

		settings = jQuery.extend({
			class_name      : 'external',
			title           : false,
			title_prefix    : 'New window : ',
			title_suffix    : '',
			tracking_prefix : 'external'
		}, settings);

		jQuery(this).attr('title', function() {
			var title = settings.title_prefix + this.href + settings.title_suffix;
			if (settings.title) {
				title = settings.title;
			}
			return title;
		});

		jQuery(this).click(function() {
			pageTracker._trackPageview('/' + settings.tracking_prefix + '/' + this.href);
			return !window.open(this.href);
		});

		jQuery(this).addClass(settings.class_name);

	};

})(jQuery);
