$(function(){
	// H1～H6タグより目次を生成する
	var toc = '';
	var currentlevel = 0;
	var maxlevel = 6;
	
	$("div.question")
		.children("h3")
			.each(function(){
				var level = this.nodeName.match(/[1-6]/i);
				if(maxlevel>level){maxlevel=level;currentlevel = maxlevel-1;}
			}).each(function(idcount){
				var level = this.nodeName.match(/[1-6]/i);
				if($(this).attr("id")==null){$(this).attr("id","toc" + idcount)};
				while(currentlevel < level) {
					toc += "<ol>";
					currentlevel++;
				}
				while(currentlevel > level) {
					toc += "<\/ol>";
					currentlevel--;
				}
				toc += '<li><a href="#'+ $(this).attr("id") + '" title="'+$(this).text()+'">' + $(this).text() + "<\/a><\/li>\n";
			});
	while(currentlevel > 0) {
		toc += "<\/ol>";
		currentlevel--;
	};
	$("div#toc")
		.append(toc)
		.children(":first")
			.attr("class","bord");
});
