// JavaScript Document

// Page Load
function myLoad(){	
	// Define Menu
	myMenu = document.getElementById('menu').getElementsByTagName('a');
	var uri = document.location.href;
	
	// iterate through the menu
	for (i = 0; i < myMenu.length; i++) {
		
		if (getFileName(myMenu[i].href) == getFileName(uri)){
			// change state of current button		
			changeState(myMenu[i]); 
		}	 	
	}
	
	// if no match found (this happens when the site is first loaded)
	if (getFileName(uri) == ''){
		// change state of default button
		changeState(myMenu[0]); 
			
	}
}

// Get file name
function getFileName(url) {
	//this gets the full url
	//var url = document.location.href;
	//this removes the anchor at the end, if there is one
	url = url.substring(0, (url.indexOf("#") == -1) ? url.length : url.indexOf("#"));
	//this removes the query after the file name, if there is one
	url = url.substring(0, (url.indexOf("?") == -1) ? url.length : url.indexOf("?"));
	//this removes everything before the last slash in the path
	url = url.substring(url.lastIndexOf("/") + 1, url.length);
	//return
	return url;
}

// change button state
function changeState(it){
	var img = it.innerHTML; // get image code
	var position = img.indexOf('.'); // find the dot befor the extension
	// add '_button' to designate on state
	it.innerHTML = img.substr(0, position) + '_button' + img.substr(position);
	// change style
	it.style.cursor = 'default';
}
