<!--
/* Button switching for ADI Handloaders Guide */
/* Created 19 Aug 2003 */

//initialise the global variables
var d=window.document;
var hasImg=false;
var imgDir="./images/";
d.onArray=new Array(); d.offArray=new Array(); d.overArray=new Array(); d.topArray=new Array();

//Preload all images
function preloadImages() {
	for(i=0;i<d.images.length;i++){
		var img=d.images[i], idxOff=img.src.indexOf("_off"), idxOn=img.src.indexOf("_on"), idxOver=img.src.indexOf("_over");
    var imgFmt=getImgFmt(img), btnName=img.name, sectImg="";
		if(idxOff>=0){
			sectImg=img.src.substring(img.src.lastIndexOf("/") + 1, idxOff);
			d.onArray[btnName]=new Image(); d.onArray[btnName].src=imgDir + sectImg + "_on" + imgFmt;
			d.offArray[btnName]=new Image(); d.offArray[btnName].src=img.src;
			d.overArray[btnName]= new Image(); d.overArray[btnName].src=imgDir + sectImg + "_over" + imgFmt;
		}
		if(idxOn>=0){
			sectImg=img.src.substring(img.src.lastIndexOf("/") + 1, idxOn);
			d.overArray[btnName]= new Image(); d.overArray[btnName].src=imgDir + sectImg + "_over" + imgFmt;
			d.onArray[btnName]=new Image(); d.onArray[btnName].src=img.src;
			d.offArray[btnName]=new Image(); d.offArray[btnName].src=imgDir + sectImg + "_off" + imgFmt;
		}
	}
 hasImg=true;
}

//Switch an image
var imgState = ""
function swapImg(imgName,evt){
 if (hasImg && eval("d.images." + imgName)){
  var theImage=eval("d.images." + imgName);
	var imgFmt;
  switch (evt.type){
    case "mouseout" :
				theImage.src = imgState //return the image to its previous state
//			theImage.src=d.offArray[imgName].src;
    	break;
    case "mouseover" :
			imgState = theImage.src //store the current state of the image
			theImage.src=d.overArray[imgName].src;
    	break;
    case "load" : // gives orientation
			theImage.src=d.onArray[imgName].src;
			for(i=0;i<d.images.length;i++){
				var img=d.images[i], idxOff=img.src.indexOf("_off"), idxOn=img.src.indexOf("_on");
				imgFmt=getImgFmt(img);
		 		if ((idxOff>=0) || (idxOn>=0)){img.src=img.src.substr(0,img.src.lastIndexOf("_"))+"_off" + imgFmt;}
			}
			imgFmt=getImgFmt(theImage);
			theImage.src=theImage.src.substr(0,theImage.src.lastIndexOf("_"))+"_on" + imgFmt;
    	break;
    default :
  }
 }
}

function getImgFmt(thisImg){
	return thisImg.src.substring(thisImg.src.lastIndexOf("."),thisImg.src.length); //get button image format
}
//-->

