// timeline.js
// by Brian Stanley
// These functions are used in displaying a timeline view of a resume.

//On page load, runs the showLatestYear function.
window.onload = function() {showAllYears()}

//Shows the latest year (strictly speaking, the year listed first).
function showLatestYear() {
	//Grab the innerHTML of the first descendant node of the "all-years-inner" div. This will be the latest year. 
	var sourcediv = document.getElementById('all-years-inner').getElementsByTagName("*")[0].innerHTML;
	var targetdiv = document.getElementById('display');
	targetdiv.innerHTML = sourcediv;
}

//Shows all years.
function showAllYears() {
	clearActiveLink();
	document.getElementById('link-all').className = 'timeline-links-list-item-link active';
	var sourcediv = document.getElementById('all-years-inner').innerHTML;
	var targetdiv = document.getElementById('display');
	targetdiv.innerHTML = sourcediv;
}

//Shows a particular year.
function showYear(yearId,linkId) {
	clearActiveLink();
	document.getElementById(linkId).className = 'timeline-links-list-item-link active'; //set the current year link to "active"
	var sourcediv = document.getElementById(yearId).innerHTML;
	var targetdiv = document.getElementById('display');
	targetdiv.innerHTML = sourcediv;
}

//Toggles the full description for a particular event.
function toggleDescription(descriptionId,toggleId) {
	var div = document.getElementById(descriptionId);
	if (div.style.display == 'block') {
		div.style.display = 'none';}
	else {
		div.style.display = 'block';}
	var currentToggle = document.getElementById(toggleId);
	if (currentToggle.innerHTML == "Hide Description") {
		currentToggle.innerHTML = "Show Description";}
	else {
		currentToggle.innerHTML = "Hide Description";}
}

//This function resets the class names for the year links, thus removing the existing "active" link.
function clearActiveLink() {
	var parent = document.getElementById('timeline-links-list');
	var list = parent.getElementsByTagName('a');
	for (var i=0; i<list.length; i++) {
	list[i].className = "timeline-links-list-item-link";	
	}
}


	
