
//--------------------------------------------------------
// ユーティリティ
//--------------------------------------------------------

function for_each_element( tagname, handler )
{
	var objs = document.getElementsByTagName(tagname)
	for( var i=0; i!=objs.length; ++i )
		handler( objs[i] )
}

var self = (function(){
	var i = location.pathname.lastIndexOf('/')
	if( i <= 0 ) i = location.pathname.lastIndexOf('\\')
	if( i >  0 ) i += 1
	return location.pathname.substr(i)
})()

//--------------------------------------------------------
// h2要素を列挙して、段落アンカー的なもの追加
//--------------------------------------------------------

function add_anchor()
{
	for_each_element( "h2", function(h2) {
		// h2の中身テキスト
		var txt= h2.firstChild
		txt.nodeValue = " " + txt.nodeValue

		// 自分リンクを追加
		var id     = h2.parentNode.id
		var selfid = location.hash.substr(1)
		{
			var a  = document.createElement("a")
			if( selfid != id )
			    a.href      = self + "#" + id
			    a.innerHTML = "*"
			h2.insertBefore( a, txt )
		}
	})
}

//--------------------------------------------------------
// 現在のURLが #_XXXXXXXX の時は該当記事を強調表示
//--------------------------------------------------------

function emph_referred_article()
{
	var id = location.hash.substr(1)
	if( id != "" )
	{
		var e = document.getElementById(id).childNodes[0];
		e.style.backgroundColor = "#ffb"
	}
}

//--------------------------------------------------------
// main
//--------------------------------------------------------

add_anchor()
emph_referred_article()

