$(document).ready(function() {
	var pathname = document.URL;
	init();
	$('#tab_menu_list a').click(function(){
		// clears tab highlights
		resetLinks();
		
		var toLoad = pathname+' #all_content div'+$(this).attr('href');
		
		// sets clicked tab to highlight
		$(this).addClass("current-nav-link");
		loadSection($(this).attr('href'));
		function resetLinks() {
			var parent = document.getElementById("tab_menu_list");
			var childCount = parent.getElementsByTagName("li").length;
			for(var i = 0;i<childCount;i++) {
				var thisLink = "#tab_menu_list #link0" + (i+1) + " a";
				$(thisLink).removeClass("current-nav-link");	
			}
		}
		return false;
	});
	function init() {
		$("#main_content_block #section01").toggle();
	}
	function hideAll() {
		$("#main_content_block #section01").hide();
		$("#main_content_block #section02").hide();
		$("#main_content_block #section03").hide();
		$("#main_content_block #section04").hide();
	}
	function loadSection(thisSection) {
		var toLoad = "#main_content_block "+thisSection; // section to load
		var displayMode = $(toLoad).css("display"); // current mode of section clicked
		
		// loads content only if section clicked is not equal to the current section already loaded
		if(displayMode === "none") {
			hideAll();
			$(toLoad).fadeIn();
		}
	}
});
function resetTabs() {
	var linkName = "";
	var thisTab = null;
	for(i = 1;i < 5;i++){
		linkName = "a_link0"+i;
		// alert(linkName);
		thisTab = document.getElementById(linkName);
		thisTab.className = "none";
	}
}
function resetSections() {
	var linkName = "";
	var thisTab = null;
	for(i = 1;i < 5;i++){
		linkName = "section0"+i;
		// alert(linkName);
		thisTab = document.getElementById(linkName);
		thisTab.style.display = "none";
	}
}
function selectTab(linkIndex) {
	resetTabs();
	var linkName = "a_link0"+linkIndex;
	var thisTab = document.getElementById(linkName);
	thisTab.className = "current-nav-link";
	resetSections();
	showSection(linkIndex);
}
function showSection(linkIndex) {
	var linkName = "section0"+linkIndex;
	//alert(linkName);
	var thisTab = document.getElementById(linkName);
	//alert(thisTab.style.display);
	thisTab.style.display = "block";
}