(function($) {
	$.fn.pir = function(options) {
		return $(this).hide().each(function() {
			$.pir(this, options);
		}).show();
	};
	$.pir = function(elem, options) {
		var $e = $(elem), meta = ($.metadata) ? $(elem).metadata() : {}, o = $
				.extend( {
					size : $e.css("font-size"),
					color : $e.css("color"),
					casing : $e.css("text-transform"),
					text : $e.text().split("'").join("&#039;")
				}, $.pir.options, meta, options), e = encodeURIComponent;
		$e.html("");
		$.each(o.wrap ? o.text.split(" ") : [ o.text ], function() {
			if ($.trim(this) != "") {
				var $img = $(
						"<img alt='" + this.replace("'", "&rsquo;") + "' src='"
								+ o.php + "?text=" + e(this) + "&font="
								+ e(o.font) + "&size=" + e(o.size) + "&color="
								+ e(o.color) + "&casing=" + e(o.casing) + "&backgroundColor=" + e(o.backgroundColor) + "'>")
						.css( {
							"vertical-align" : "bottom"
						});
				$e.append($img);
				$e.append(" ");
			}
		});
		if (o.prettyPrint) {
			$("img", $e).addClass("pir-prettyprint-image");
			$("<span>" + o.text + "</span>").addClass("pir-prettyprint-text")
					.appendTo($e);
			$("<style type='text/css' media='print'></style>").text(
					".pir-prettyprint-image { display: none; }").appendTo(
					"head");
			$("<style type='text/css' media='screen'></style>").text(
					".pir-prettyprint-text { display: none; }")
					.appendTo("head");
		}
		;
		return $e;
	};
	$.pir.options = {
		php : "/pir.php",
		font : "denmark.ttf",
		wrap : false,
		prettyPrint : false,
		backgroundColor : 'FFFFFF'
	};
	$.pir.version = "0.1";
	$(function() {
		$(".pir").pir();
	});
})(jQuery);
