/*
 * samaxesJS JavaScript Library
 * jQuery TOC Plugin v1.0.2
 * http://code.google.com/p/samaxesjs/
 *
 * Copyright (c) 2008 samaxes.com
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
(function(c){c.fn.toc=function(h){var i=c.extend({},c.fn.toc.defaults,h);var k=this.append("<ul></ul>").children("ul");var j={h1:0,h2:0,h3:0,h4:0,h5:0,h6:0};var g=0;var f={h1:(i.exclude.match("h1")===null&&c("h1").length>0)?++g:0,h2:(i.exclude.match("h2")===null&&c("h2").length>0)?++g:0,h3:(i.exclude.match("h3")===null&&c("h3").length>0)?++g:0,h4:(i.exclude.match("h4")===null&&c("h4").length>0)?++g:0,h5:(i.exclude.match("h5")===null&&c("h5").length>0)?++g:0,h6:(i.exclude.match("h6")===null&&c("h6").length>0)?++g:0};return this.each(function(){c(":header").not(i.exclude).each(function(){var l=c(this);if(l.is("h6")){a(j.h6,k);b(j,"h6");l.text(e(j,"h6",l.text()));d(k,f.h6,l.attr("id"),l.text(),j)}else{if(l.is("h5")){a(j.h5,k);b(j,"h5");l.text(e(j,"h5",l.text()));d(k,f.h5,l.attr("id"),l.text(),j)}else{if(l.is("h4")){a(j.h4,k);b(j,"h4");l.text(e(j,"h4",l.text()));d(k,f.h4,l.attr("id"),l.text(),j)}else{if(l.is("h3")){a(j.h3,k);b(j,"h3");l.text(e(j,"h3",l.text()));d(k,f.h3,l.attr("id"),l.text(),j)}else{if(l.is("h2")){a(j.h2,k);b(j,"h2");l.text(e(j,"h2",l.text()));d(k,f.h2,l.attr("id"),l.text(),j)}else{if(l.is("h1")){b(j,"h1");l.text(e(j,"h1",l.text()));d(k,f.h1,l.attr("id"),l.text(),j)}}}}}}})})};function a(g,f){if(g===0&&!f.find(":last").is("ul")){f.find("li:last").append("<ul></ul>")}}function b(f,g){c.each(f,function(h,j){if(h===g){++f[h]}else{if(h>g){f[h]=0}}})}function e(h,i,g){var f="";c.each(h,function(j,k){if(j<=i&&h[j]>0){f+=h[j]+"."}});return f+" "+g}function d(m,f,l,k,j){var h=m;for(var g=1;g<f;g++){if(h.find("> li:last > ul").length===0){h=h.append("<li><ul></ul></li>")}h=h.find("> li:last > ul")}if(l===""){h.append("<li><a>"+k+"</a></li>")}else{h.append('<li><a href="#'+l+'">'+k+"</a></li>")}}c.fn.toc.defaults={exclude:"h1, h5, h6"}})(jQuery);