/*
   scListTab.js : 記事リストのタブ機能
 */
function scListTab() {
	// はこ
	var container = document.getElementById('tabBodyWrap');

	// タブコンテナ
	var tabContainer = document.getElementById('univLinkCat');

	// タブ
	var latestTabBtn = document.getElementById('press');
	var secondTabBtn = document.getElementById('school');
	var thirdTabBtn = document.getElementById('club');
	var fourthTabBtn = document.getElementById('association');

	// 呼び出す内容
	var latestListUrl = '/press_list.html';
	var secondListUrl = '/school_list.html';
	var thirdListUrl = '/club_list.html';

	// タブの背景
	// press ボタン
	var tabBGPon = 'url(/img/univs-link_title.gif) no-repeat -7px -85px';
	// school ボタン
	var tabBGSon = 'url(/img/univs-link_title.gif) no-repeat -52px -85px';
	// club ボタン
	var tabBGCon = 'url(/img/univs-link_title.gif) no-repeat -96px -85px';
	var tabBGoff = 'none';

	// タブのボーダー
	var tabBDon = 'none';
	var tabBDoff = 'solid 1px #999999';

	// カーソル
	var tabCRon = 'auto';
	var tabCRoff = 'pointer';

	// イベントハンドラ
	latestTabBtn.onclick = function() {
		// 背景を変更
		latestTabBtn.style.background = tabBGPon;
		secondTabBtn.style.background = tabBGoff;
		thirdTabBtn.style.background  = tabBGoff;
		// ボーダーを変更
		latestTabBtn.style.borderLeft = tabBDon;
		secondTabBtn.style.borderLeft = tabBDon;
		thirdTabBtn.style.borderLeft  = tabBDoff;
		fourthTabBtn.style.borderLeft = tabBDoff;
		// カーソルを変更
		latestTabBtn.style.cursor = tabCRon;
		secondTabBtn.style.cursor = tabCRoff;
		thirdTabBtn.style.cursor  = tabCRoff;

		// 中身を更新
		new Ajax.Updater("container", latestListUrl, {
			asynchronous: true,
			method: "get",
			parameters: "cache=" + (new Date()).getTime(),
			onSuccess: function(request) {
				container.innerHTML = request.responseText;
			}
		});
	};

	secondTabBtn.onclick = function() {
		// 背景を変更
		latestTabBtn.style.background = tabBGoff;
		secondTabBtn.style.background = tabBGSon;
		thirdTabBtn.style.background  = tabBGoff;
		// ボーダーを変更
		latestTabBtn.style.borderLeft = tabBDoff;
		secondTabBtn.style.borderLeft = tabBDon;
		thirdTabBtn.style.borderLeft  = tabBDon;
		fourthTabBtn.style.borderLeft = tabBDoff;
		// カーソルを変更
		latestTabBtn.style.cursor = tabCRoff;
		secondTabBtn.style.cursor = tabCRon;
		thirdTabBtn.style.cursor  = tabCRoff;

		// 中身を更新
		new Ajax.Updater("container", secondListUrl, {
			asynchronous: true,
			method: "get",
			parameters: "cache=" + (new Date()).getTime(),
			onSuccess: function(request) {
				container.innerHTML = request.responseText;
			}
		});
	};

	thirdTabBtn.onclick = function() {
		// 背景を変更
		latestTabBtn.style.background = tabBGoff;
		secondTabBtn.style.background = tabBGoff;
		thirdTabBtn.style.background  = tabBGCon;
		// ボーダーを変更
		latestTabBtn.style.borderLeft = tabBDoff;
		secondTabBtn.style.borderLeft = tabBDoff;
		thirdTabBtn.style.borderLeft  = tabBDon;
		fourthTabBtn.style.borderLeft  = tabBDon;
		// カーソルを変更
		latestTabBtn.style.cursor = tabCRoff;
		secondTabBtn.style.cursor = tabCRoff;
		thirdTabBtn.style.cursor  = tabCRon;

		// 中身を更新
		new Ajax.Updater("container", thirdListUrl, {
			asynchronous: true,
			method: "get",
			parameters: "cache=" + (new Date()).getTime(),
			onSuccess: function(request) {
				container.innerHTML = request.responseText;
			}
		});
	};

}

// イベントローダー
function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	}
	else {
		window.onload = function() {
			oldonload();
			func();
		};
	}
}

// メイン ---------------------------------------------------------------
// DOM が有効のブラウザだけこの機能を有効にする
// かつ Win IE 5.x も除外
if (document.getElementsByTagName) {
	if (!(navigator.userAgent.indexOf("MSIE 5", 0) >= 0)) {
		addLoadEvent(scListTab);
	}
}

