jQuery(function($) { var toc = $("#toc ul"); jQuery("#toc a.toggle").click(function(){ toc.toggle(); if(toc.is(":visible")){ jQuery("#body").css("margin-right", 280); jQuery("#body h1").css("margin-right", 0); }else{ jQuery("#body").css("margin-right", 20); jQuery("#body h1").css("margin-right", 250); } }); $("#body :header").each(function() { var h = $(this); var name = h.text().replace(/[\s,-;\.]/g, ""); h.before( $("" , {name: name}) ); var li = $("
  • "); var ahref = $("
    ", {href: "#" + name} ).append( h.text().replace(/\s/g, " ") ); li.append(ahref); toc.append(li); }); /* var parent = toc.parent(), tocOverlay = parent .clone() .insertBefore(parent) .css({ overflow: "visible", position: "absolute", right: "10px", }).hide(); */ });