var curr ='01'; //initally selected thumbnail

function advancePic(direction){
	if(document.getElementById) {
		// find total num of thumbs & get current pic showing
		var tot = document.getElementById('thmb').childNodes.length/2;
		var curr_array = document.getElementById('fullsize').src.split('lrg_');
		var num = curr_array[1].substring(0,2);
		curr = num;
		if(direction=='bwd') { // go backward
			if (curr!='01'){ // if we are not at the last thumb add one
				num--; 
				num = num<10 ? '0'+num : num; // deal with leading zero
			} else {// else set num to 01
				num = tot<10 ? '0'+tot : tot ;
			}
		} else { // go forward
			if (curr!=tot){ // if we are not at the last thumb add one
				num++; 
				num = num<10 ? '0'+num : num; // deal with leading zero
			} else { // else set num to 01
				num = '01';
			}
		}
		showPic(document.getElementById('thmb'+num));
	}
}

function showPic (whichpic) {
 if (document.getElementById) {
  document.getElementById('fullsize').src = whichpic.href;
	var fulldesc = whichpic.childNodes[0].alt;
	if(fulldesc.indexOf("|")!= -1) {
		var desc_array = fulldesc.split("|"); // split alt tag by pipe
	}
	else { // there is only one entry
		var desc_array = new Array(fulldesc,""); 
	}
	
	if(desc_array[1]=="") desc_array[1]="\u00A0"; // make sure there is always something (\u00A0==&nbsp;)
	// may need to adjust for regular caption where only one line and dl used
  document.getElementById('caption').childNodes[0].childNodes[0].nodeValue = desc_array[0];
  document.getElementById('caption').childNodes[1].childNodes[0].nodeValue = desc_array[1];
	//set class on curr to off
	document.getElementById('thmb' + curr).style.borderColor = ''; 
	// Safari will NOT remove/clear/reset borderColors, so just hardcode to bg color...the only other way is to use onmouseovers 
	if(navigator.userAgent.indexOf('Safari') != -1) document.getElementById('thmb' + curr).style.borderColor = '#cccccc'; 
	//set class on num to on
	whichpic.style.borderColor = 'orange'; 
	//update currently selected
	var curr_array = document.getElementById('fullsize').src.split('lrg_');
	curr = curr_array[1].substring(0,2);
	return false;
 } else { // just show the pic
  return true;
 }
}


