/*
	Standards Compliant Rollover Script
	Author : Daniel Nolan
	http://www.bleedingego.co.uk/webdev.php

	JRS To use, load normal image with class name "imgover".
	Then put the rolled-over version of the image in the same directory,
	but append "_o" to its basename.
*/

function _initRolloverArray(aImages) {
	var aPreLoad = new Array();
	var sTempSrc;

	for (var i = 0; i < aImages.length; i++) {		
		if (aImages[i].className == 'imgover') {
			var src = aImages[i].getAttribute('src');
			var ftype = src.substring(src.lastIndexOf('.'), src.length);
			var hsrc = src.replace(ftype, '_o'+ftype);

			aImages[i].setAttribute('hsrc', hsrc);
			
			aPreLoad[i] = new Image();
			aPreLoad[i].src = hsrc;
			
			aImages[i].onmouseover = function() {
				sTempSrc = this.getAttribute('src');
//				alert("Setting source to "+this.getAttribute("hsrc");
				this.setAttribute('src', this.getAttribute('hsrc'));
			}	
			
			aImages[i].onmouseout = function() {
				if (!sTempSrc) sTempSrc = this.getAttribute('src').replace('_o'+ftype, ftype);
				this.setAttribute('src', sTempSrc);
			}
		}
	}
}

function initRollovers() {
	if (!document.getElementById) return
	// JRS Need to get both img and input[type="image"] elements.
	// But note that I couldn't find a way in Javascript to take the
	// union of these two sets of elements (the object type returned is
	// HTMLCollection, not Array).
	_initRolloverArray(document.getElementsByTagName('img'));
	_initRolloverArray(document.getElementsByTagName('input'));
}

// JRS In body onload.
//window.onload = initRollovers;
