/* image highlight by Veneficus (c) 2001
 *
 * add the following code to your page:
 * <script language="JavaScript" src="image-highlight.js" type="text/javascript"></script>
 * add the line at the bottom of your page (before </body>) because of netscape's bugs ;-)
 * for usage without link bluring remove the line "blurAll(document);" in the init() function
 *
 * you may use this script freely unless you leave these comment lines
 *
 * for commercial use please contact: veneficus@gmx.net
 *
 */

/******************* the active image at script startup *********************************/

var active = new String();
active = "";

/******************* the ending of the highlighted pics *********************************/

var hlSuffix = "_hl";		// highlight
var stSuffix = "_hl";		// status

/******************* don't change the following *****************************************/

var lowImages = new Array();
var highImages = new Array();
var statImages = new Array();
var allLoaded = false;

function loadImages(doc) {
    for (i = 0; i < doc.images.length; i++) {
		// create images
		lowImages[doc.images[i].name] = new Image();
		highImages[doc.images[i].name] = new Image();
		statImages[doc.images[i].name] = new Image();
		// make filenames
		highlighted = doc.images[i].src.substring(0, doc.images[i].src.lastIndexOf("."))
		statusImage = highlighted + stSuffix + doc.images[i].src.substring(doc.images[i].src.lastIndexOf("."))
		highlighted += hlSuffix + doc.images[i].src.substring(doc.images[i].src.lastIndexOf("."))
		// set images sources
		lowImages[doc.images[i].name].doc = doc;
		lowImages[doc.images[i].name].src = doc.images[i].src;
		highImages[doc.images[i].name].src = highlighted;
		statImages[doc.images[i].name].src = statusImage;
	}
	// for netscape: check layers
	if (doc.layers) {
		for (i = 0; i < doc.layers.length; i++) {
			loadImages(doc.layers[i].document);
		}
	}
	allLoaded = true;
}

function lowlight(name) {
	if (!allLoaded || active == name) return;
	lowImages[name].doc.images[name].src = lowImages[name].src;
}

function highlight(name) {
	if (!allLoaded || active == name) return;
	lowImages[name].doc.images[name].src = highImages[name].src;
}

function status(name) {
    if (!allLoaded) return;
	tmp = active;
	active = "";
	lowlight(tmp);
	lowImages[name].doc.images[name].src = statImages[name].src;
	active = name;
}

function init() {
    loadImages(document);
	blurAll(document);
	if (active) if (active != "") status(active);
}

/****************************************************************************************/

// link bluring by Veneficus (c) 2001
// feel free to add it to your page

function blurAll(doc) {
    for (i = 0; i < doc.links.length; i++) {
		doc.links[i].onfocus = doBlur;
	}
}

function doBlur() {
    if (this.blur) this.blur();
}

/****************************************************************************************/

window.onload = init;

