// function for setting images
	function swapNextImage(img, sDirection, nNumber) {
	  var img = document.getElementById(img);
	  
	  //if at start or end, do nothing
	  if ((sDirection == "next" && nCurrentImg == nImgCount) || (sDirection == "back" && nCurrentImg == 1) || (nImgCount == 0)) {
	      return;
	  } else {
	  	  // if a box is clicked, set the current number to that box
		  if (nNumber) {
			nCurrentImg = nNumber;
		  } else {
		    // increment number if next or back are clicked
			nCurrentImg = (sDirection == "next") ? nCurrentImg = nCurrentImg + 1 : nCurrentImg = nCurrentImg - 1;
		  }
		  if (img != null) {
		    //Main image. Change "arch" to new naming. Example: "interior"
			img.src = sImgName + nCurrentImg +".jpg";
		  }
		  setBox();
	  }
	}
	
	//function for setting current box
	function setBox() {
	   
		//loop though the boxes	and set em blank or off
		for(i = 1 ; i < 17 ; i++) {
			var sSrc = (i > nImgCount ) ? sImgPath + i + "_blank.gif" : sImgPath + i + "_off.gif";
			document.getElementById("box" + i).src = sSrc;
		}
		
		//set the current box to on
		if(nCurrentImg != 0) {
			document.getElementById("box" + nCurrentImg).src = sImgPath + nCurrentImg + "_on.gif";
			sLastImg = sImgPath + nCurrentImg + "_on.gif";
		}
		
		//set the back and next
		if((nCurrentImg == nImgCount) && (nImgCount != 0)) {
			document.getElementById("next").src = sImgPath + "next_on.gif";
			document.getElementById("back").src = sImgPath + "back_off.gif";
		} else if(nCurrentImg == 1) {
			document.getElementById("back").src = sImgPath + "back_on.gif";
			document.getElementById("next").src = sImgPath + "next_off.gif";
		} else if(nImgCount == 0) {
			document.getElementById("back").src = sImgPath + "back_on.gif";
			document.getElementById("next").src = sImgPath + "next_on.gif";
		} else {
			document.getElementById("next").src = sImgPath + "next_off.gif";
			document.getElementById("back").src = sImgPath + "back_off.gif";
		}
	}
	
	function swapBoxImage(elTarget, sImg, elAnchor) {
		var elTarget = document.getElementById(elTarget);
		sLastImg = elTarget.src;
		if (sLastImg.match("blank") != null) {
			elAnchor.href = "javascript:void()";
		} else {
			elTarget.src = sImg;
		}
	}
	
	function swapBoxRestore(elTarget) {
		var elTarget = document.getElementById(elTarget);
		elTarget.src = sLastImg;
		sLastImg = null;
	}
	
	function swapDirImage(elTarget, sImg) {
		var elTarget = document.getElementById(elTarget);
		sLastDirImg = elTarget.src;
		if (!elTarget.src.match("off")) {
			elTarget.src = sImg;
		}
	}
	
	function swapDirRestore(elTarget) {
		var elTarget = document.getElementById(elTarget);
		elTarget.src = sLastDirImg;
		sLastDirImg = null;
	}

	
function MM_swapImgRestore() { //v3.0
	var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
	var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
	var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
	if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
	var p,i,x;
	if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
		d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
	if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
	if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
	var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
	if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function swapImage(img, src) {
	if (img != null) img.src = src;
}

// Simple DHTML Image Loader 
// by Glen Murphy. Script located at http://bodytag.org/

function bt_forcedone() {
	document.getElementById('bt_container').innerHTML = bt_text_finished;
	bt_done();
	}

function bt_arrived(o) {
	bt_loaded += bt_preimages[o][1];
	var bt_percentage = Math.round((bt_loaded/bt_total)*100);
	document.getElementById('bt_container').innerHTML = bt_text_prefix+bt_percentage+'%';
	//document.getElementById('bt_bar').style.width = bt_percentage;
	
	if(bt_percentage == 100) {
		bt_forcedone();
		}
	}

if(bt_timeout > 0) {
	setTimeout('bt_forcedone()',bt_timeout*1000);
	}

var bt_total = 0;
var bt_loaded = 0;
var bt_out = '';

bt_out += '<div id="bt_container">Preloading..</div>';
//bt_out += '<div id="bt_bar"></div>';

for(i = 0; i < bt_preimages.length; i++) {
	bt_total += bt_preimages[i][1];
	bt_out += '<img src="'+bt_preimages[i][0]+'" width="1" height="1" onload="bt_arrived('+i+');" style="position:absolute; top:-1000px;" />';
	}

document.write(bt_out);
