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

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

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

var selff = pathbody(location.pathname)
if( selff.length == 0 )
	selff = document.getElementsByTagName("li")[2].firstChild.getAttribute("href")

//--------------------------------------------------------
// 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 selffid = location.hash.substr(1)
		{
			var a  = document.createElement("a")
			if( selffid != id )
			    a.href      = selff + "#" + id
			a.innerHTML = "*"
            a.onclick   = function(){emph_(id)};
			h2.insertBefore( a, txt )
		}
	})
}

//--------------------------------------------------------
// 現在のURLが #_XXXXXXXX の時は該当記事を強調表示
//    && タイトル変更
//--------------------------------------------------------

function emph_(id)
{
	var e = document.getElementById(id).childNodes[0]
	e.style.backgroundColor = "#ffb"
	document.title = document.getElementById(id).childNodes[1].firstChild.nodeValue + " - d.y.d."
}

function emph_referred_article()
{
	var id = location.hash.substr(1)
	if( id != "" ) emph_(id)
}

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

add_anchor()
emph_referred_article()

