// Author:      Dietmar Rabich, lewiser
// Date:        2003-02-13
// Description: A generic script for highlighting links with rollover images.
//              If the image points to the current page, it stays highlighted.
//              The image within the link must have the same name as the two
//              images, and these must be called "....gif" and "../../www.expo-archive.ch_high.gif"
//              or "....jpg" and "../../www.expo-archive.ch_high.jpg".
//              This script also fully supports language suffixes.
// Usage:
// load_images (           Pre-loads an image's two versions when the page has loaded. Call this in <body onload="...">.
//    name                 The name of the image object. This is the same as in <img name="...">
//    filename             The filename of the image file. The highlighted version must end in "_high.gif".
//    file_suffix          The file suffix of the image file. If none is specified, "gif" is the default.
// )
//
// show_image (            Shows the highlighted version of the image.
//    name                 The name of the image object. This is the same as in <img name="...">
// )
// Returns:
// showStatus              The status of the highlighting, which must be "true", otherwise JavaScript chokes.
//
// hide_image (            Shows the normal version of the image.
//    name                 The name of the image object. This is the same as in <img name="...">
// )
//
// select_active_image (   This checks what links points to the current URL. The correspondant image is then highlighted. Call this in <body onload="...">.
// )
//
// doc_image (             Creates an image object from a file. This is only used internally, so don't use it.
//    filename             The filename of the image file.
// )
// Returns:
// image                   The JavaScript image object containing the two images.
//
// Original:    http://www.rabich.de
// HTML usage:
// <head>
// <script src="../common_scripts/highlight_link.js" type="text/javascript" language="javascript"></script>
// </head>
// <body onload="load_images('button1','../images/button1');select_active_image();">
// <a href="my_page.html" onmouseover="return show_image('button1');"
// onmouseout="hide_image('button1');"><img src="../images/button1.gif" name="button1"
// width="20" height="40" border="0" alt="This is my page"></a>
// </body>


// Create the image array
var Img = new Array();

// Create the image object
// Note that for files with suffixes, we insert the '_high' part before the first suffix,
// which is indicated by the first '-'.
function doc_image(filename, file_suffix) {
	this.normal = new Image();
	this.high   = new Image();

	var suffixIndex = filename.indexOf('-');
	if (suffixIndex > -1) {
		this.normal.src = filename + "." + file_suffix;
		this.high.src   = filename.substring(0, suffixIndex) + "_high" + filename.substring(suffixIndex) + "." + file_suffix;
	} else {
		this.normal.src = filename + "." + file_suffix;
		this.high.src   = filename + "_high." + file_suffix;
	}
	
	return this;
}

// Create the image information
function load_images(name, filename, file_suffix) {
	if (file_suffix == null || file_suffix == "") {
		file_suffix = "gif";
	}
	Img[name] = new doc_image(filename, file_suffix);
}

// Show the image
function show_image(name) {
	document[name].src = Img[name].high.src;
	return true;
}

// Hide the image, but only if it's not the image of the current page
function hide_image(name) {
	var currentPage;
	currentPage = document.URL;
	currentPage = currentPage.substring(currentPage.lastIndexOf("/")+1);
	
	if (name != currentPage.substr(0,name.length)) {
		document[name].src = Img[name].normal.src;
	}
}

// Select the active image, depending on the page's file name.
function select_active_image () {
	var i;
	var currentPage;
	var keyLength;
	
	currentPage = document.URL;
	currentPage = currentPage.substring(currentPage.lastIndexOf("/")+1);
	
	for (i in Img) {
		keyLength = i.length;
		if (i == currentPage.substr(0,keyLength)) {
			document[i].src = Img[i].high.src;
		}
	}
}

