/**
 *
 * 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 1 :
 * $('a[rel*=external]').externalLinks();
 *
 * example 2 :
 * $('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    : ''
		}, settings);

		jQuery(this).attr('title', function() {
			var title = settings.title_prefix
				+ this.href
				+ settings.title_suffix;
			if (settings.title) {
				title = settings.title;
			}
			return title;
		}).addClass(
			settings.class_name
		).click(function() {
			return !window.open(this.href);
		});

	};

})(jQuery);
