(function ($) {
	$.fn.external = function() {
		this.delegate('a', 'click', function(e) {
			var href = $(this).attr('href');

			if (href == undefined || !href.match(/^http/) || href.indexOf(window.location.host) >= 0 || $(this).hasClass('popup')) {
				return;
			}

			if (!$.browser.msie || $.browser.version > 6) {
				// If this isn't IE 6, use native browser functionality
				$(this).attr('target', '_blank');
			} else {
				// otherwise, do it for 'em
				window.open(href, (new Date()).getTime(), [
					// array joining is faster than string concatenation
					['height=', document.body.clientHeight].join(''),
					['width=', document.body.clientWidth].join(''),
					'top=0',
					'left=0',
					'scollbars=yes',
					'resizeable=yes',
					'status=yes',
					'titlebar=yes',
					'toolbar=yes'
				].join(','));
				e.preventDefault();
			}
		});

		return this;
	};

	$.fn.popup = function(config) {
		var conf = $.extend({
			width: 900,
			height: 600,
			selector: 'a.popup'
		}, config);

    	this.delegate(conf.selector, 'click', function(e) {
			e.preventDefault();
			var $if = $('<iframe/>', {
				src: $(this).attr('href') + window.location.search,
				width: conf.width + 'px',
				height: conf.height + 'px',
				frameborder: 0
			}).wrap('<div/>').parent();
    
			if ($.browser.msie && $.browser.version < 7) {
				$if.bgiframe();
			}
    
			$if.dialog({
				modal: true,
				width: conf.width + 40,
				height: conf.height + 40,
				position: ['center', 'center']
			});

			return false;
		});

		return this;
	};

  	$.fn.modal = function(config) {
		this.dialog($.extend({
			bgiframe: true,
			width: 600,
			modal: true,
			resizable: false,
			draggable: false		
		}, config));

		return this;
	};
})(jQuery);
