jQuery.fn.fontify = function(size, fg, bg, wrap) {
	$(this).each(function() {
		var me = $(this);
		var input = $.trim($(this).text());

		if (me.hasClass("fontified") || me.children().hasClass("fontified")) return; // Don't re-fontify!

		me.hide().empty().addClass("fontified");

		if (wrap == true) {
			var txt = input.split(" ");
			/*$.each(txt, function(i, val) {
				txt[i] = txt[i] + " ";
			});*/
		} else {
			var txt = new Array();
			txt.push(input);
		}

		$.each(txt, function() {
			var thisOne = encodeURIComponent(this);
			thisOne = thisOne.replace(/\%2B/g, "(percentu)002B"); // +
			thisOne = thisOne.replace(/\%23/g, "(percentu)0023"); // #
			thisOne = thisOne.replace(/\%26/g, "(percentu)0026"); // &
			thisOne = thisOne.replace(/\%2F/g, "(percentu)002F"); // /
			thisOne = thisOne.replace(/\%u/g,"(percentu)");

			img = $(document.createElement('img')).attr("src",
			["/magic/replace", size, fg, bg, thisOne].join('/')
			).attr("alt", $(thisOne).text());

			me.append(img);
		});
		
		me.show();
	});
}

$(function() {
	$("#header h1 a").fontify(24, "FFFFFF", "6E8FA2");
	
	$("#home div.post h2 a").fontify(24, "4C754D", "F1EDD2", true);
	$("#single div.post h2 a").fontify(48, "4C754D", "F1EDD2", true);

	$("#whereseth h4").fontify(14, "5C4E38", "E7C311");
	$("#searchresults h3 a").fontify(18, "4C754D", "F1EDD2");
	$("div.post h3").fontify(18, "4C754D", "F1EDD2", true);
	$("#midbar>dt, #sidebar dt, #searchform dt").fontify(18, "5C4E38", "F1EDD2");
	$("#linkblog h2").fontify(18, "3F6378", "FFFFFF");
	$("#comments").fontify(18, "E3DEB8", "352a18", true);
	$("#footer h3").fontify(18, "E3DEB8", "352a18");
	$("#postnav a").fontify(18, "4C754D", "F1EDD2");
	$("#idioquote h3, #idioquote cite").fontify(18, "5C4E38", "F1EDD2");
	
	$("#postnav a:last").css("padding-left", "50px");
});

$(function() {
	var font = 125;
	while ($("#whereseth p").height() >= 130) {
		font -= 5;
		$("#whereseth p").css("font-size", font+"%");
	}

	$(".footcolumn ul li:even").addClass("odd");
	/* if ($("#linkblog").length) {
		$.getJSON("http://ma.gnolia.com/json/default/people/SethKinast?callback=?",function(txt) {
			$("#linkblog ul").empty();
			txt = txt.slice(0,10);
			$.each(txt, function() {
				$("#linkblog ul").append("<li><a href='" + this.url + "'><strong>" + this.title + "</strong><em>" + this.description + "</em></a></li>");
			});
			$("#linkblog a strong").fontify(11, "3F6378", "FFFFFF");
		})
	} */
	$("#moar").click(function() {
		$.get("/tools/idioquote/rpc.php",function(txt) {
			$("#idioquote_txt").fadeOut('slow', function() {
				$(this).html(txt).find("h3, cite").fontify(18, "5C4E38", "F1EDD2");
			}).fadeIn('slow');
		});
		return false;
	});
});

