/*-------------------------------------------------------------------
 *	FILENAME	hilite.js
 *	
 *	PROJECT		Knight Area website
 *	DATE		Friday, July 04, 2008
 *	VERSION		1.0
 *	
 *	Provides highlights for images with surrounding anchors with 
 *	rel="hilite". The image should be in the same location with 
 *	suffix "_h" and the same extension as the original image. 
 *
 *	(C) 2008 Mark Smit
 *-------------------------------------------------------------------*/

function hilite (state) {
	switch (state) {
	case "on":
		this.src = this.img_hilite.src;
		break;
	case "off":
		this.src = this.img_normal.src;
		break;	
	}
}

function hilite_img_on () {
	this.image.hilite ("on");
}

function hilite_img_off () {
	this.image.hilite ("off");
}

function hilite_filename(src) {

	var filename = src.substr(0, src.length-4) + "_h." + src.substr(src.length-3);

	return filename;
}

function hilite_scan() { 

	var rel;
	var anchors;
	var anchor;
	var images;
	var image;
	var i;

	if (!document.getElementsByTagName) 
		return; 

	anchors = document.getElementsByTagName("a"); 
	for (i=0; i<anchors.length; i++) { 
		anchor = anchors[i]; 
		rel = anchor.getAttribute("rel");

		if (rel != null && rel.search("hilite") != -1) {
			images = anchor.getElementsByTagName("img");
			if (images.length == 0) {
				images = anchor.getElementsByTagName("input");
			}

			if (images.length > 0) {
				image = images[0];
				image.img_normal = new Image();
				image.img_normal.src = image.src;
				image.img_hilite = new Image();
				image.img_hilite.src = hilite_filename (image.src); 
				image.hilite = hilite;
				anchor.image = image;
				anchor.onmouseover = hilite_img_on;
				anchor.onmouseout = hilite_img_off;
			}
		}
	} 

/*
	var images;
	var image;
	var anchor;
	var hilite_filename;

	if (!document.getElementsByTagName) 
		return; 

	images = document.getElementsByTagName("img"); 
	for (var i=0; i<images.length; i++) { 
		image = images[i]; 
		hilite_filename = image.getAttribute("hilite");
		if (hilite_filename != null) {
			if (image.parentNode.nodeName == "A")
			{
				anchor = image.parentNode;
			}
			else {
				anchor = document.createElement('A'); 
				anchor.appendChild(image);
				image.parentNode.replaceChild(anchor, image);
			}
		}
	} 
	*/
}