/**
 * Copyright 2008, 2009 Brian Holt <jquery@planetholt.com>.  
 * 
 * This file is distributed under the terms of version three of the 
 * GNU Lesser General Public License, the details of which can be 
 * found at http://www.gnu.org/licenses/lgpl-3.0.txt
 */
(function(c){jQuery.fn.footnotes=function(d){var e=c.extend({},c.fn.footnotes.defaults,d);return this.each(function(f){b("INFO: Building footnotes for "+(f+1)+"...",e.debugMode);c(e.footnotes,this).addClass(e.autoFootnoteClass);var h=(""==e.contentBlock)?c(this):c(e.contentBlock,this),g=e.orderedList?"<ol>":"<ul>";c("."+e.autoFootnoteClass).each(function(n){var l,r,t=-1,s,p=f+"-"+n,u,q,k,o,j,m;if(e.singleFootnoteDestination){l=c("#"+e.destination);if(0==l.length){b("INFO: No #autoFootnotes found; adding our own",e.debugMode);l=c(g).attr("id",e.destination).addClass("footnotesList").appendTo(h)}}else{l=c("#"+e.destination+f);if(0==l.length){b("INFO: No #autoFootnotes"+f+" found; adding our own for "+(f+1),e.debugMode);l=c(g).attr("id",e.destination+f).addClass("footnotesList").appendTo(h)}}c(this).removeClass(e.autoFootnoteClass);r=e.fnExtractFootnote(this);t=-1;p=f+"-"+n;c("li > .footnoteContent",l).each(function(i){if(c(this).html()==r){t=i;s=c(c(this).parents("li").get(0));return false}});if(-1==t){u=c("<a>").attr("href","#cite-text-"+p).attr("name","cite-ref-"+p).text("["+(n+1)+"]").addClass("footnoteLink");if(c(this).is(e.prependTags)){c("<sup>").prependTo(this).append(u)}else{c("<sup>").appendTo(this).append(u)}q=c("<li>").attr("id","cite-text-"+p);k=c("<span>").addClass("footnoteBackReferenceGroup").appendTo(q);c("<span>").addClass("footnoteContent").html(r).appendTo(q);u=c("<a>").text("^").attr("href","#cite-ref-"+p).addClass("footnoteBackref");c("<sup>").prependTo(k).append(u);l.append(q)}else{p=f+"-"+t;o=c(c("li > .footnoteBackReferenceGroup",l).get(t));j=o.find(".footnoteBackref");m=j.length;switch(j.length){case 0:b("ERROR: backRefs.length == 0, which should have prevented this code path",e.debugMode);break;case 1:c("<sup>").text("^ ").addClass("footnoteBackref").prependTo(o);c(j).text("a");++m;default:u=c("<a>").attr("href","#"+s.attr("id")).attr("name","cite-ref-"+p+"-"+j.length).text("["+(t+1)+"]").addClass("footnoteLink");if(c(this).is(e.prependTags)){c("<sup>").prependTo(this).append(u)}else{c("<sup>").appendTo(this).append(u)}u=c("<a>").attr("href","#cite-ref-"+p+"-"+j.length).addClass("footnoteBackref");if(m>=26){b("WARN: multiple letter functionality is probably broken when more than 26 footnotes exist",e.debugMode)}u.prepend(String.fromCharCode((m)+96));c("<sup>").appendTo(o).append(u);break}}});b("INFO: Done building footnotes for "+(f+1),e.debugMode)})};c.fn.footnotes.version=function(){return"1.0.0"};c.fn.footnotes.defaults={footnotes:"blockquote[title],span.footnote",prependTags:"blockquote",singleFootnoteDestination:false,destination:"autoFootnotes",contentBlock:".content",autoFootnoteClass:"autoFootnote",fnExtractFootnote:a,orderedList:true,debugMode:false};function b(e,d){if(d){if(window.console&&window.console.log){window.console.log(e)}}}function a(f){if(c(f).is("span.footnote")){footnoteHTML=c(f).html();var d=/^\s+\(([\S\s]+)\)$/,e=footnoteHTML.match(d);if(null!=e&&2==e.length){footnoteHTML=e[1]}c(f).empty()}else{if(c(f).is("blockquote[title]")){footnoteHTML=c(f).attr("title");c(f).attr("title","")}}return footnoteHTML}})(jQuery);

