/*
   scBNTab.js : バックナンバーページのタブ機能
 */
function scBNTab() {
	// はこ
	var container = document.getElementById('bnListWrap');

	// タブ
	var jleagueTabBtn = document.getElementById('jleagueBNList');
	var worldTabBtn = document.getElementById('worldBNList');
	var japanTabBtn = document.getElementById('japanBNList');
	var soccerTabBtn = document.getElementById('soccerBNList');

	// 呼び出す内容
	var jleagueBNUrl = '/soccer/jleague/bnlist_sc_jleague.html';
	var worldBNUrl = '/soccer/world/bnlist_sc_world.html';
	var japanBNUrl = '/soccer/japan/bnlist_sc_japan.html';
	var soccerBNUrl = '/soccer/bnlist_sc_soccer.html';

	// イベントハンドラ
	jleagueTabBtn.childNodes[0].onclick = function() {
		// 背景を変更
		jleagueTabBtn.setAttribute("class", "on");
		worldTabBtn.setAttribute("class", "off");
		japanTabBtn.setAttribute("class", "off");
		soccerTabBtn.setAttribute("class", "off");

		jleagueTabBtn.setAttribute("className", "on");
		worldTabBtn.setAttribute("className", "off");
		japanTabBtn.setAttribute("className", "off");
		soccerTabBtn.setAttribute("className", "off");

		// 中身を更新
		new Ajax.Updater("container", jleagueBNUrl, {
			asynchronous: true,
			method: "get",
			parameters: "cache=" + (new Date()).getTime(),
			onSuccess: function(request) {
				container.innerHTML = request.responseText;
			}
		});
		return false;
	};

	worldTabBtn.childNodes[0].onclick = function() {
		// 背景を変更
		worldTabBtn.setAttribute("class", "on");
		jleagueTabBtn.setAttribute("class", "off");
		japanTabBtn.setAttribute("class", "off");
		soccerTabBtn.setAttribute("class", "off");

		worldTabBtn.setAttribute("className", "on");
		jleagueTabBtn.setAttribute("className", "off");
		japanTabBtn.setAttribute("className", "off");
		soccerTabBtn.setAttribute("className", "off");


		// 中身を更新
		new Ajax.Updater("container", worldBNUrl, {
			asynchronous: true,
			method: "get",
			parameters: "cache=" + (new Date()).getTime(),
			onSuccess: function(request) {
				container.innerHTML = request.responseText;
			}
		});
		return false;
	};

	japanTabBtn.childNodes[0].onclick = function() {
		// 背景を変更
		japanTabBtn.setAttribute("class", "on");
		jleagueTabBtn.setAttribute("class", "off");
		worldTabBtn.setAttribute("class", "off");
		soccerTabBtn.setAttribute("class", "off");

		japanTabBtn.setAttribute("className", "on");
		jleagueTabBtn.setAttribute("className", "off");
		worldTabBtn.setAttribute("className", "off");
		soccerTabBtn.setAttribute("className", "off");

		// 中身を更新
		new Ajax.Updater("container", japanBNUrl, {
			asynchronous: true,
			method: "get",
			parameters: "cache=" + (new Date()).getTime(),
			onSuccess: function(request) {
				container.innerHTML = request.responseText;
			}
		});
		return false;
	};

	soccerTabBtn.childNodes[0].onclick = function() {
		// 背景を変更
		soccerTabBtn.setAttribute("class", "on");
		jleagueTabBtn.setAttribute("class", "off");
		worldTabBtn.setAttribute("class", "off");
		japanTabBtn.setAttribute("class", "off");

		soccerTabBtn.setAttribute("className", "on");
		jleagueTabBtn.setAttribute("className", "off");
		worldTabBtn.setAttribute("className", "off");
		japanTabBtn.setAttribute("className", "off");

		// 中身を更新
		new Ajax.Updater("container", soccerBNUrl, {
			asynchronous: true,
			method: "get",
			parameters: "cache=" + (new Date()).getTime(),
			onSuccess: function(request) {
				container.innerHTML = request.responseText;
			}
		});
		return false;
	};
}

// イベントローダー
function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	}
	else {
		window.onload = function() {
			oldonload();
			func();
		};
	}
}

// メイン ---------------------------------------------------------------
// DOM が有効のブラウザだけこの機能を有効にする
if (document.getElementsByTagName) {
	addLoadEvent(scBNTab);
}

