if( window.jQuery ) (
	function( $ )
	{
		$.fn.popup = function( settings )
		{
			var config = {
				isPopupRegExp: /popup/,
				sizeRegExp: /popup(\d+)x(\d+)/,
				widthIdx: 1,
				heightIdx: 2,
				windowOptions: 'directories=no,menubar=no,resizable=yes,scrollbars=yes,status=yes,toolbar=no'
			};

			if ( settings )
			{
				$.extend( config, settings );
			}

			return this.each(
				function()
				{
					if ( undefined == this.className || ! config.isPopupRegExp.exec( this.className ) )
					{
						return;
					}

					$(this).click(
						function()
						{
							var matches = config.sizeRegExp.exec( this.className );

							var oWin;
							if ( matches )
							{
								width = matches[config.widthIdx];
								height = matches[config.heightIdx];
								var sizeOptions = 'width=' + width + ',height=' + height + ',';
								oWin = window.open( this.href, this.className, sizeOptions + config.windowOptions );
							}
							else
							{
								oWin = window.open( this.href );
							}

							if ( oWin )
							{
								oWin.focus();
								return false;
							}

							return true;
						}
					);
				}
			);
		}

		$(document).ready(
			function()
			{
				$('a').popup();
			}
		);
	}
)(jQuery);
