/**
 *
 * Stef A. Spijkerman
 * http://www.saspijkerman.com/
 * mail@saspijkerman.com
 *
 * Version : 1.0
 * Date    : February 4th, 2008
 *
 * example : $('a[rel*=external]').externalLinks();
 * example : $('a[href$=.pdf]').externalLinks({ class_name : 'pdf' });
 *
 */

(function($){

	$.fn.externalLinks = function(options) {

		// Default options
		var options = $.extend({
			class_name   : 'external',
			title_prefix : '',
			title_suffix : '',
			title        : ''
		}, options);

		/* Update title attribute */
		if (options.title != '') {
			$(this).attr('title', options.title);
		} else if (options.title_prefix != '' || options.title_suffix != '') {
			$(this).attr('title', function() {
				return options.title_prefix + this.href + options.title_suffix;
			});
		}

		/* Open in new window */
		$(this).click(function() {
			return !window.open(this.href);
		});

		/* Add class */
		$(this).addClass(options.class_name);

		return this;
	};

})(jQuery);
