/*==================================================================================================
	MECHANICS NATIONAL BANK
	------------------------------------------------------------------------------------------------
	Custom Functions
	
	Author: JA, WebLinc
	Date Created: 03.02.2008
	
--------------------------------------------------------------------------------------------------*/

/*======================================
	GET ELEMENTS BY CLASS NAME
----------------------------------------
	Written by Jonathan Snook
	http://www.snook.ca/jonathan
	------------------------------------
	Add-ons by Robert Nyman
	http://www.robertnyman.com
--------------------------------------*/
function getElementsByClassName(oElm, strTagName, strClassName){
	var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
	var arrReturnElements = new Array();
	strClassName = strClassName.replace(/\-/g, "\\-");
	var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
	var oElement;
	for(var i=0; i<arrElements.length; i++){
		oElement = arrElements[i];
		if(oRegExp.test(oElement.className)){
			arrReturnElements.push(oElement);
		}
	}
	return (arrReturnElements)
}

/*======================================
	TOGGLE TIMELINE
----------------------------------------
	Switches the class of each timeline
	ul, effectively hiding and showing
	by century
--------------------------------------*/
function toggleTimeline(century, myElement) {
	
	//switch classes on century ul's
	var centuries = getElementsByClassName(document, "ul", "timeline_list");
	for(i=0; i<centuries.length; i++)
	{	
		if(centuries[i].id == century && centuries[i].className.indexOf("current") == -1) {
			centuries[i].className += " current";
			centuries[i].className = centuries[i].className.replace(/(?:^\s*|\s*$)/, "");
		} else if(centuries[i].id != century) {
			centuries[i].className = centuries[i].className.replace(/\s*current/, "");
		}
	}	
	
	//switch classes on century links
	var links = getElementsByClassName(document, "a", "timeline_link");
	for(i=0; i<links.length; i++)
	{	
		if(links[i] == myElement && links[i].className.indexOf("current") == -1) {
			links[i].className += " current";
			links[i].className = links[i].className.replace(/(?:^\s*|\s*$)/, "");
		} else if(links[i] != myElement) {
			links[i].className = links[i].className.replace(/\s*current/, "");
		}
	}	
}
