// 
// 2008.4.22   oet/interview00_ja.html  /  oet/interview_nav.php
// <ul><li>タグによるバックナンバーナビを<select>タグによるメニューに置き換え
// Takuro Susaki
// 

window.onload = function() {
	hideNav("oetInterviewBackissueListWrapper");
	var countLi = countInterview("oetInterviewBackissueList");
	if (!countLi) {
		return;
	}

	// メニューの生成
	var parent = document.getElementById("interviewNavJsWrapper");
	// <select>タグの生成
	var selectNode = document.createElement("select");
	selectNode.setAttribute("id","interviewNavJs");
	if (document.all && !window.opera){ // 「&&」前はIEとOperaを含むらしいので、「&&」後ろでOperaをはじく…
		selectNode.setAttribute("onchange",new Function("interviewJump(this);")); // IE用… イベントハンドラはぜんぶ小文字。
	} else {
		selectNode.setAttribute("onChange","interviewJump(this)"); // モダンブラウザ用…
	}
	parent.appendChild(selectNode);

	// XHTMLファイル内のdiv#oetInterviewBackissueList内のli要素から必要なものをコピーして
	// selectタグ内に作成
	var interviewLi = document.getElementById("oetInterviewBackissueList").childNodes;
	var interviewLiValue;    // リンクURLの値
	var interviewLiText;     // 表示するテキスト
	var interviewLiTextCopy; // 表示するテキストをコピーする（しないと元が消えちゃう）
	var optionNode;

	for(i = 0; i < 2 * countLi ;i++) { // 条件式の計算はホワイトテキストノードを加味するため
		if (interviewLi[i].nodeName == "LI" && interviewLi[i].firstChild.nodeName == "A") {
			// まずリンク部分を抽出して、<option>タグを生成し、Valueを付加
			interviewLiValue = interviewLi[i].firstChild.getAttribute("href");
			optionNode = document.createElement("option");
			optionNode.setAttribute("value",interviewLiValue);
			selectNode.appendChild(optionNode);
			// で、<option>タグの子供にテキストを挿入
			interviewLiText = interviewLi[i].firstChild.firstChild;
			interviewLiTextCopy = interviewLiText.cloneNode(false);
			optionNode.appendChild(interviewLiTextCopy);

		} else if (interviewLi[i].nodeName == "LI" && interviewLi[i].firstChild.nodeType == 3) {
			// nodeType == 1 のすぐ下の子供が nodeType == 3 (Text) だったばやい（現在表示中のページを表す行のはず）
			optionNode = document.createElement("option");
			optionNode.setAttribute("selected","selected");
			selectNode.appendChild(optionNode);

			interviewLiText = interviewLi[i].firstChild;
			interviewLiTextCopy = interviewLiText.cloneNode(false);
			optionNode.appendChild(interviewLiTextCopy);

		}
	}
}


// idを指定してその要素を消す
function hideNav(hideNode) {
	hide(hideNode);
}


// 指定されたidの要素を消す
function hide(elementId) {
	document.getElementById(elementId).style.display = "none";
}


// フォームリストからリンクジャンプ
function interviewJump(selAttribute) {
	n = selAttribute.selectedIndex;
	location.href = selAttribute.options[n].value;
}


// 指定されたidの中にあるli要素を数えて返す
function countInterview(elementId) {
	var backIssueDiv = document.getElementById(elementId);
	return backIssueDiv.getElementsByTagName("li").length;
}

