/* Tumblr Notes Plugin by Matthew Buchanan v2.01
   Requires jQuery 1.2.6 or higher
   See http://matthewbuchanan.name for installation guide */

$(function() {
	$("a.notes-button").each(function() {
		var noteCount = parseInt($(this).html().substring(0,$(this).html().indexOf(" ")));
		if (noteCount > 14) $(this).addClass("fave");
	});
	$("a.notes-button").click(function(event) {
		event.preventDefault();
		var node = $("#notes-"+$(this).attr("rel"));
		$("#notes-"+$(this).attr("rel")).slideToggle();
		$.ajax({ url: $(this).attr("href")+"&jsonp=1", dataType: "jsonp", success: function(data){
			node.find(".loading").hide();
			node.find(".notes-loader").html(data).find("ol.notes li:last").append("</span>").end().slideDown();
			node.find(".notes-loader").append("<p><a href='#' class='notes-hide'>Hide Notes</a></p>");
			node.find(".notes-hide").click(function(event) {
				event.preventDefault();
				node.slideToggle();
			});
		} });
	});
});
