window.onload = function(){
	createTab();
	hideHeading();
	showCategory('this_month');
	setTabClick('thisNav','this_month');
	setTabClick('nextNav','next_month');
	setTabClick('thirdNav','third_month');	
};

function hide(elementId){
	document.getElementById(elementId).style.display = "none";
}
function show(elementId){
	document.getElementById(elementId).style.display = "block";
}
function hideHeading(){
	hide('this_month_text');
	hide('next_month_text');
	hide('third_month_text');
}
function showCategory(categoryName){
	hide('this_month');
	hide('next_month');
	hide('third_month');
	show(categoryName);
	changeTab(categoryName);
}
function createTab(){
	var wrapper = document.getElementById("wrapper");
	var calendar = document.getElementById("calendar");
	var nav = document.createElement("ul");
	nav.setAttribute('id','nav');
	nav.appendChild(createListItem('thisNav','#this_month','9月のスタッフ予定表'));
	nav.appendChild(createListItem('nextNav','#next_month','10月のスタッフ予定表'));
	nav.appendChild(createListItem('thirdNav','#next_month','11月のスタッフ予定表'));
	wrapper.insertBefore(nav,calendar);
}
function createListItem(id,href,text) {
	var li = document.createElement("li");
	var a = document.createElement("a");
	var t = document.createTextNode(text);
	li.setAttribute('id',id);
	a.setAttribute('href',href);
	a.appendChild(t);
	li.appendChild(a);
	return li;
}
function setTabClick(listName,categoryName) {
	var e = document.getElementById(listName).getElementsByTagName('a')[0];
	e.onclick = function(){
		showCategory(categoryName);
		return false;
	};
}
function changeTab(categoryName){
	var e = document.getElementById('nav');
	e.className = categoryName;
}