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

function preloadNotes() {
	jQuery(".notes-button").click(function(event) {
		event.preventDefault();
		jQuery("#notes-"+jQuery(this).attr("rel")).slideToggle();
	});
	jQuery(".notes-button").each(function() {
		var button = jQuery(this);
		var node = jQuery("#notes-"+jQuery(this).attr("rel"));
		// add &noimages=1 after &jsonp=1 to strip images from the notes file
		jQuery.ajax({ url: jQuery(this).attr("href")+"&jsonp=1", dataType: "jsonp", success: function(data){
			node.html(data);
			var num = node.find("ol li").size();
			if( num > 14 ) button.addClass("fave");
			if( num > 1 ) button.prepend(num+"&nbsp;").fadeIn();
			node.append("<p><a href='#' class='notes-hide'>Hide Notes</a></p>");
			node.find(".notes-hide").click(function(event) {
				event.preventDefault();
				node.slideToggle();
			});
		} });
	});
}

jQuery(document).ready(function() {
	preloadNotes();
});