//
// Preload images so there isn't a delay
// when the user hovers over a button image.
// Requires libdetect.js to be loaded.
// Pass this an array of css selector names
// whose background images should be preloaded
// and a context path obtained from an html:rewrite of "/".
//
function preloadImagesForSelectorsInContext(styleSheetIndex, selectors, context) {
	if (moz || dom2) {
		cssRuleList = document.styleSheets[styleSheetIndex].cssRules;
	}
	if (ie4 || ie5 || ie6 || ie7) {
		cssRuleList = document.styleSheets[styleSheetIndex].rules;
	}

	for (var i = 0; i < cssRuleList.length; i++) {
		var selectorText = cssRuleList[i].selectorText.toLowerCase();
		for (var j = 0; j < selectors.length; j++) {
			if (selectorText == selectors[j].toLowerCase()) {
				var imagesrc = cssRuleList[i].style.backgroundImage;
				imagesrc = context + imagesrc.substring(imagesrc.indexOf("images"), imagesrc.length - 1);
				var imageRef = new Image();
				imageRef.src = imagesrc;
				//
				// IE hack.  It seems as though the standard image preloading trick
				// is non-deterministic on IE.  So we try another means of loading
				// the image.  Also, Mozilla 1.6 appears to not preload with the above code
				// since we added the no-cache response headers required for Safari.
				//
				document.write("<img src=\"" + imagesrc + "\" style=\"display:none;\"/>");
				//alert(imagesrc + "\n" + imageRef.src + "\n" + imageRef.complete);
			}
		}
	}
}