//
// This sets up the mapping between links and images.  For each link you
// enter two comma-separated (no space) strings.  The first is the item
// to match in the image, the second is the string to replace it with
// if it corresponds to the current page.  You don't need to supply
// the entire string, just enough to be unique.
//
function SetImageLink(name, value) {
    SetImageLink.prototype[name] = '';
    SetImageLink[name] = value;
}
function GetImageLink(name) {
    return SetImageLink[name];
}

function SetCurrentPageLinks () {
    var i, oldimage, newimage, link;
    var loc = document.location.pathname;

    if (document.location.search) loc += document.location.search;
    if (document.location.hash) loc += document.location.hash;

    // scan links to current page and change their class
    for (i = 0; i < document.links.length; ++i) {
	var n = document.links[i].pathname;
	if (document.links[i].search) n += document.links[i].search;
	if (document.links[i].hash) n += document.links[i].hash;
	if (n == loc) {
	    document.links[i].className = 'currentpage';
	}
    }

    if (!document.images) return;	// not 1.1

    // scan images for the links to the curren page, and change their src
    link = GetImageLink(document.location.pathname);
    if (!link) return;
    oldimage = link.replace(/,.*/, '');
    for (i = 0; i < document.images.length; ++i) {
	newimage = link.replace(/.*,/, '');
	if (document.images[i].src.indexOf(oldimage) >= 0) {
	    document.images[i].src = document.images[i].src.replace(oldimage, newimage);
	}
    }
}
