
window.onload = function() {
 	set_current_page();
	rewrite_links();
    init_rollover(); //do this last
    trace('finished onload');
}

// Code to set "current page" indicator.
// BDD, 1/2006
function set_current_page() {


	var startIdx;
	var stopIdx;
	
	// Extract name of current section.
	
	// Get URL of current page
	var str=document.location.href;
	// Find last slash in string
	startIdx = str.lastIndexOf("/") + 1;
	// Find the dot after the last slash in the string
	stopIdx = startIdx + (str.substr(startIdx)).search(/\./);
	// Extract the page name
	str = str.substr(startIdx,stopIdx-startIdx);
	
	// Now, trap all gallery subject pages and convert their name to gallery.
	// Note:  this translation is only necessary if file name isn't same as section name
	switch(str) {
		case "vanityvirtue":
		case "stockexchanges":
		case "specandcredit":
		case "politicsandwar":
		case "moneydevil":
		case "misersmoneylenders":
		case "loveandmoney":
		case "louisphilipe":
		case "biblicalmythol":
		case "bankers":
			str = "gallery";
	}
	
	// Finally, look for all pages where the current page should be set
	// Note:  requires file name and id name in <img> tag to match
	switch(str) {
		case "bibliography":
		case "artistindex":
		case "introduction":
		case "gallery":
			// If we're on one of those pages, do the swap
			turn_on_state(str);
	}
}
	


// Functiopn that actually changes out the graphic on the current page.
// BDD, 1/2006
function turn_on_state(str) {

	// safety check
    if (document.getElementsByTagName) {
		// grab all images
    	var allimgs = document.getElementsByTagName('img');
		// look for image I want
        for (i=0; i < allimgs.length; i++) {
            if (allimgs[i].name == str) {
				// when I find it, add a '-on' to the suffix of the file name
				// Note:  assumes images with the -on suffix are in the same folder as off state ones.
			    newsrc = allimgs[i].src; 
                newsrc = newsrc.replace('.gif','-on.gif');
				// reset the image
				allimgs[i].src = newsrc;
            } 
        }
    }
}
