(function(){
	$(function(){
		$(".math p").each(function(i, p){
			$(p).html($(p).html().replace(/\$(.*?)\$/g, "<span class='equation'>$1</span>"));
		});
		$(".equation").each(function(i, p){
			var para = $(p);

			var texdata = para.html();

			var query = {
				inline: 1,
				output: "json",
				tex: texdata
			}

			jQuery.getJSON("http://sleepingcyb.org/apis/texmath2png.py", query, function(data){
				para.html("<img alt='" + texdata + "' src='" + data.uri + "' style='vertical-align: -" + data.depth + "ex; height: " + (data.depth + data.height) + "ex;' />");
			});
		});
	});
})();

