var path = location.href.substring(0,location.href.lastIndexOf("/")+1);
var imagePath = path + "images/buttons/";
//alert("starting, imagePath = " + imagePath);

function handleMouseOver(imageName,graphicName) {

	if (getCurrentPageName() == getMatchingPageName(imageName)) {
		return;
	}

	rolloverImage = imagePath + graphicName + '-02' + '.jpg';
	//alert("handleMouseOver, imageName = " + imageName + ", rolloverImage = " + rolloverImage);
	changeImageSrc(imageName,rolloverImage);
}

function handleMouseOut(imageName,graphicName) {
	outImage = imagePath + graphicName + getDefaultButtonPrefix(imageName) + '.jpg';
	//alert("outImage = " + outImage);
	changeImageSrc(imageName,outImage );
}


function changeImageSrc(imageName,newGraphic) {
	if (document.images) {
		document.images[imageName].src = newGraphic;
	}
}

function setCurrentPageButton() {

	docImages=document.getElementsByTagName("img"); 
	for(i=0; i-docImages.length; i++){
		currentImageName = docImages[i].name;
		if (currentImageName.indexOf('btn') >= 0 &&
			getCurrentPageName() == getMatchingPageName(currentImageName)) {

			//change to -03 from -01:
			currentImageSrc = docImages[i].src;
			newImageSrc = currentImageSrc .replace("-01", "-03");
			changeImageSrc(currentImageName,newImageSrc);
		}
	}
}

function getDefaultButtonPrefix(imageName) {
	if (getCurrentPageName() == getMatchingPageName(imageName)) {
		return '-03';
	}
	else {
		return '-01';
	}
}

// get the button image name and retirn the html page it is associated with:
function getMatchingPageName(imageName) {
	
	//alert("getMatchingPageName, imageName = " + imageName);

	switch(imageName)
	{
	case 'home_btn':
		return 'index';
	case 'gallery_btn':
		return 'gallery';
	case 'links_btn':
		return 'links';
	case 'contact_btn':
		return 'contact';
	case 'form_btn':
		return 'intake_form';

	default:
		alert("wrong imageName: " + imageName);
		return 'index';
	}
}


// return name of current page (without the 'htm' or 'html' extension):
function getCurrentPageName() {
	currentPath = window.location.pathname;
	currentPage = currentPath .substring(currentPath.lastIndexOf('/') + 1,currentPath.indexOf('htm') - 1);
	return currentPage;
}
