/*
 * samaxesJS JavaScript Library
 * jQuery TOC Plugin v1.1.0
 * http://code.google.com/p/samaxesjs/
 *
 * Copyright (c) 2010 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 k=c.extend({},c.fn.toc.defaults,h);var m=this.append("<ul></ul>").children("ul");var l={h1:0,h2:0,h3:0,h4:0,h5:0,h6:0};var g=0;var f={h1:0,h2:0,h3:0,h4:0,h5:0,h6:0};for(var j=1;j<=6;j++){f["h"+j]=(k.exclude.match(new RegExp("h"+j,"i"))===null&&c("h"+j).length>0)?++g:0}return this.each(function(){c(k.context+" :header").not(k.exclude).each(function(){var o=c(this);for(var n=6;n>=1;n--){if(o.is("h"+n)){a(l["h"+n],m);b(l,"h"+n);o.text(e(l,"h"+n,o.text()));d(m,f["h"+n],o.attr("id"),o.text())}}})})};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(l,f,k,j){var h=l;for(var g=1;g<f;g++){if(h.find("> li:last > ul").length===0){h.append("<li><ul></ul></li>")}h=h.find("> li:last > ul")}if(k===""){h.append("<li>"+j+"</li>")}else{h.append('<li><a href="#'+k+'">'+j+"</a></li>")}}c.fn.toc.defaults={exclude:"h1, h5, h6",context:""}})(jQuery);