//image display scripts
document.selectedpic = null;
document.debug = false;
document.gallerydir="";
document.defaulttext = 'Choose an image from the gallery at left.<br>&nbsp;<br>&nbsp;<table width="100%"  border="0" cellpadding="0" cellspacing="0"><tr><td class="smgrey"><a href="javascript:goImg(-1);" onMouseOver="document.getElementById(\'backimg\').src = \'images/back_on.gif\';" onMouseOut="document.getElementById(\'backimg\').src = \'images/back_off.gif\';"><img src="images/back_off.gif" name="backimg" width="13" height="13" border="0" id="backimg"></a> <a href="javascript:goImg(1);" onMouseOver="document.getElementById(\'nextimg\').src = \'images/forward_on.gif\';" onMouseOut="document.getElementById(\'nextimg\').src = \'images/forward_off.gif\';"><img src="images/forward_off.gif" name="nextimg" width="13" height="13" border="0" id="nextimg"></a> Next</td></tr></table>';
document.indicator = null;
document.defaulttmb = '';

function parseGalleryName() {
	doc = document.location.toString();
	if (doc.indexOf('gallery') != -1) {
		lastslash = doc.lastIndexOf('/');
		document.gallerydir = doc.substring(lastslash+1,doc.lastIndexOf('_'));
		if (document.debug) {
			alert(document.gallerydir);
		}
	}
}

function darkbg(objid) {
	//alert(objid);
	objthm = objid.substring(objid.indexOf('_')+1,objid.lastIndexOf('_'));
	//alert(objthm);
	obj = document.getElementById(objid);
	obj.className = "darkbg";
	thumbpic = document.getElementById('displaythumb');
	thumbpic.src = "images/galleries/"+document.gallerydir+"/thumbs/tmb_"+objthm+".gif";
	//alert(thumbpic.src);
	outcell = document.getElementById('displaytextcell');
	outcell.innerHTML = 'Click to view:<br>'+inventory.captions[parseInt(objthm,10)]+'<br>&nbsp;<table width="100%"  border="0" cellpadding="0" cellspacing="0"><tr><td class="smgrey"><a href="javascript:goImg(-1);" onMouseOver="document.getElementById(\'backimg\').src = \'images/back_on.gif\';" onMouseOut="document.getElementById(\'backimg\').src = \'images/back_off.gif\';"><img src="images/back_off.gif" name="backimg" width="13" height="13" border="0" id="backimg"></a> <a href="javascript:goImg(1);" onMouseOver="document.getElementById(\'nextimg\').src = \'images/forward_on.gif\';" onMouseOut="document.getElementById(\'nextimg\').src = \'images/forward_off.gif\';"><img src="images/forward_off.gif" name="nextimg" width="13" height="13" border="0" id="nextimg"></a> Next</td></tr></table>';
}

function lightbg(objid) {
	if (document.selectedpic != objid) {
	  obj = document.getElementById(objid);
	  obj.className = "lightbg";
	  thumbpic = document.getElementById('displaythumb');
	  thumbpic.src = document.defaulttmb;
	  outcell = document.getElementById('displaytextcell');
	  outcell.innerHTML = document.defaulttext;
	}
	else {
	  outcell = document.getElementById('displaytextcell');
	  outcell.innerHTML = document.defaulttext;
	}
}

parseGalleryName();

function parse23(num) {
	nstr = num.toString()
	while(nstr.length < 3) {
		nstr = "0"+nstr;
	}
	return nstr;
}

function getDisplay(imgStr) {
	plimg = document.getElementById('placeholder');
	plimg.src = 'images/galleries/'+document.gallerydir+'/images/img_'+imgStr+'.jpg';
	document.defaulttext = inventory.captions[parseInt(imgStr,10)]+'<br>&nbsp;<br>&nbsp;<table width="100%"  border="0" cellpadding="0" cellspacing="0"><tr><td class="smgrey"><a href="javascript:goImg(-1);" onMouseOver="document.getElementById(\'backimg\').src = \'images/back_on.gif\';" onMouseOut="document.getElementById(\'backimg\').src = \'images/back_off.gif\';"><img src="images/back_off.gif" name="backimg" width="13" height="13" border="0" id="backimg"></a> <a href="javascript:goImg(1);" onMouseOver="document.getElementById(\'nextimg\').src = \'images/forward_on.gif\';" onMouseOut="document.getElementById(\'nextimg\').src = \'images/forward_off.gif\';"><img src="images/forward_off.gif" name="nextimg" width="13" height="13" border="0" id="nextimg"></a> Next</td></tr></table>';
	document.selectedpic = 'gp_'+imgStr+'_cell';
	document.defaulttmb = 'images/galleries/'+document.gallerydir+'/thumbs/tmb_'+imgStr+'.gif';
	thumbpic = document.getElementById('displaythumb');
	thumbpic.src = document.defaulttmb;
	clearCells();
}

function setInd() {
	if (doc.indexOf('.html') > -1) {
		ind = doc.substring(doc.lastIndexOf('/')+1,doc.lastIndexOf('.'));
	}
	else {
		ind = 'index';
	}
	document.indicator = document.getElementById('ind'+ind);
	document.indicator.src = 'images/sdot.gif';
}

function clearCells() {
	for (m=1;m<inventory.images.length;m++) {
		mcell = document.getElementById('gp_'+parse23(m)+'_cell');
		//alert(mcell.id);
		if (document.selectedpic != mcell.id) {
			mcell.className = "lightbg";
		}
	}
}

function goImg(num) {
	if (document.selectedpic != null) {
		picnum = parseInt(document.selectedpic.substring(document.selectedpic.indexOf('_')+1, document.selectedpic.lastIndexOf('_')),10);
		tnum = picnum+num;
		if (tnum <1) {
			tnum = inventory.images.length-1
		}
		if (tnum > inventory.images.length-1) {
			tnum = 1
		}
		targetcell = 'gp_'+parse23(tnum)+'_cell';
		document.selectedpic = targetcell;
		clearCells();
		darkbg(targetcell);
		getDisplay(parse23(tnum));
	}
	else {
		tnum = 1;
		targetcell = 'gp_'+parse23(tnum)+'_cell';
		document.selectedpic = targetcell;
		clearCells();
		darkbg(targetcell);
		getDisplay(parse23(tnum));
	}
	outcell = document.getElementById('displaytextcell');
	outcell.innerHTML = document.defaulttext;
}