// 初期設定
function jsTabInit(){
	
	var url = window.location.hash;
	
	// タブ内のアンカーリンクへ飛ぶ場合
	if (url.indexOf("jsBox1") != -1) {
		showCategory("jsBox1", "jsNav1");
	} else if (url.indexOf("jsBox2") != -1) {
		showCategory("jsBox2", "jsNav2");
	} else if (url.indexOf("jsBox3") != -1) {
		showCategory("jsBox3", "jsNav3");
	} else if (url.indexOf("jsBox4") != -1) {
		showCategory("jsBox4", "jsNav4");
	} else {
	
		// 今月のタブを表示
		var nowMonth = (new Date()).getMonth() + 1;
		if (nowMonth <= 3) {
			showCategory("jsBox1", "jsNav1");
		} else if (nowMonth <= 6) {
			showCategory("jsBox2", "jsNav2");
		} else if (nowMonth <= 9) {
			showCategory("jsBox3", "jsNav3");
		} else {
			showCategory("jsBox4", "jsNav4");
		}
		
	}
	
	// タブのイベント設定
	setTabClick("jsTab1", "jsBox1", "jsNav1");
	setTabClick("jsTab2", "jsBox2", "jsNav2");
	setTabClick("jsTab3", "jsBox3", "jsNav3");
	setTabClick("jsTab4", "jsBox4", "jsNav4");
	
	if(window.location.hash !="") window.location.href = window.location.hash;


};

function hideBox(elementId) {
	document.getElementById(elementId).style.display = "none";
}
function showBox(elementId) {
	document.getElementById(elementId).style.display = "block";
}

// 表示BOXの切り替え
function showCategory(categoryName, bgName){
	hideBox("jsBox1");
	hideBox("jsBox2");
	hideBox("jsBox3");
	hideBox("jsBox4");
	showBox(categoryName);
	changeTab(bgName);
}

// タブのイベント設定
function setTabClick(liName,categoryName, bgName) {
	var e = document.getElementById(liName).getElementsByTagName('a')[0];
	e.onclick = function(){
		showCategory(categoryName, bgName);
		return false;
	};
}

// タブのclass名の切り替え
function changeTab(bgName){
	var e = document.getElementById("jsTabNav");
	e.className = bgName;
}


Event.observe(window, "load", jsTabInit, false);
