// global functions

function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}

// Programs Section Tabs
function tabSelect() {
	var tabs = document.getElementById("programs_nav");
	var tabLinks = tabs.getElementsByTagName("a");
	for (var i=0; i < tabLinks.length; i++) {
		tabLinks[i].onclick = function() {
			if (this.className != 'selected') { // cancel behavior if tab is selected
				// reposition the scroll to top
				document.getElementById("scrolldiv_content").style.top = 0;
				document.getElementById("scrolldiv_theScroll").style.top = 0;
				var tabLink = this.parentNode.className;
				// change the tabs look
				tabSwitch(tabLink);
				// change program div content
				programSwitch(tabLink);
			}
			return false;
		}
	}
}

function programSwitch(program_id) {
	// show current description and overview
	var descriptionDivId =  program_id + '_description';
	var overviewDivId =  program_id + '_overview';
	var descriptionDiv =  document.getElementById(descriptionDivId);
	var overviewDiv = document.getElementById(overviewDivId);
	var descriptionfadeIn = new Fx.Style(descriptionDiv, 'color', {duration: 3000, transition: Fx.Transitions.Cubic.easeOut}).start('#00a824','#fff');
	var overviewfadeIn = new Fx.Style(overviewDiv, 'color', {duration: 3000, transition: Fx.Transitions.Cubic.easeOut}).start('#00a824','#fff');
	descriptionDiv.className = 'description visible';
	overviewDiv.className = 'overview visible';
	// hide the others
	
	var scanDiv = document.getElementById('program');
	var sectionChilds = scanDiv.getElementsByTagName("h3");
	

	for (var i=0; i < sectionChilds.length; i++) {
		var section = sectionChilds[i].parentNode;
		if (section.id.match("_description") && section.id != descriptionDivId) {
			section.className = 'description invisible';
		}
		if (section.id.match("_overview") && section.id != overviewDivId) {
			section.className = 'overview invisible';
		}
	}
}

function tabSwitch(program_id) {
	var tabs = document.getElementById("programs_nav");
	var tabLinks = tabs.getElementsByTagName("a");
	for (var i=0; i < tabLinks.length; i++) {
		var tabLink = tabLinks[i].parentNode.className;
		if (tabLink == program_id) {
			tabLinks[i].className = 'selected'
		} else {
			tabLinks[i].className = '';
		}
	}
}

addLoadEvent(tabSelect);