//----------------------------------------------------------------------------------
// Plugin for jQuery 1.2.x to set up external links to open in a new window
//
// All links are scanned and any non-local links are modified to use window.open()
// to open their locations in a new window.
//
// To start up this functionality, issue the init() command, passing an optional
// array of strings specifying additional exceptions that will open in the current window.
//
// custom - Array of strings to add to the exception list
//
// $.externalLinks.init();
// $.externalLinks.init(["othersite.com", "www.whatever.com"]);
//
// jQuery data can be assigned to individual anchor tags to store specifics for the
// window to open. You can set a class on the link to facilitate different options
// for a specific type of popup.
//
// name - The name to assign to the window for this type of popup
// options - Set the appropriate window options
//
// $("a.contact")
//     .data("window", {
//         name: "ContactInfo",
//         options: "toolbar=0,location=0,directories=0,status=0,menubar=0," +
//             "scrollbars=yes,resizable=yes,top=(20),left=(20),screenX=(20)," +
//             "screenY=(20),width=400,height=300"
//     });
//
// Neil Monroe (neil.monroe@gmail.com)
//
//
// Change Log:
//
// 1.1 / 07.21.2009
// - Updated to allow for custom exceptions
//
// 1.0 / 02.12.2009
// - Initial Release
//----------------------------------------------------------------------------------

(function($) {

	$.extend({
		externalLinks: {
			defaults: {
				site: location.protocol + "//" + location.hostname,
				exceptions: ["#", "javascript:"]
			},
			init: function(custom) {
				var def = this.defaults;
				$.merge(def.exceptions, custom || []);
				$("a").each(
					function() {
					    var isLocal = (this.href.indexOf(def.site) == 0);
					    for (var i=0; def.exceptions[i]; i++)
					        isLocal = isLocal || (this.href.indexOf(def.exceptions[i]) == 0);
						if (!isLocal) {
							$(this).click(function(e) {
								// Cancel default action
								e.stopPropagation();
								e.preventDefault();
								// Load external link
								var winData = $(this).data("window");
								var win = {
									url: this.href,
									name: (winData ? winData.name : ""),
									options: (winData ? winData.options : "")
								};
								window.open(win.url, win.name, win.options);
							});
						}
					}
				);
			}
		}
	});

})(jQuery);
