window.onload = function (){
	createTab();
	hideHeading();
	showCategory('houjin');
	setTabClick('houjinNav','houjin');
	setTabClick('kojinNav','kojin');
	setTabClick('opinionNav','opinion');	
};

function hide(elementId) {
	document.getElementById(elementId).style.display = "none";
}
function show(elementId) {
	document.getElementById(elementId).style.display = "block";
}
function hideHeading() {
	hide('houjinHeading');
	hide('kojinHeading');
	hide('opinionHeading');
}
function showCategory(categoryName) {
	hide('houjin');
	hide('kojin');
	hide('opinion');
	show(categoryName);
	changeTab(categoryName);
}


function createTab() {
	var primary = document.getElementById("primary");
	var container = document.getElementById("container");
	var nav = document.createElement("ul");
	nav.setAttribute('id','nav');
	nav.appendChild(createListItem('houjinNav','#houjin','法人のお客様'));
	nav.appendChild(createListItem('kojinNav','#nenkin','個人のお客様'));
	nav.appendChild(createListItem('opinionNav','#company','セカンドオピニオン'));
	primary.insertBefore(nav,container);
}

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;
}
	
