gallerySelect=0;
firstPhoto=0;
defTop=165;
defLeft=330;
defHeight=310;
defWidth=555;
listCurrentGal=true;		// Do I show the current gallery's name in the list of links beneath the photo?
brdrWidth=10;				// The width of the border I use on the style sheet
mainTitle="RCM Gallery: ";
imagePath="./photos/";

selecter=new Array(-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1);

// Parse variables passed to this page.  Format ?gallery&firstImage
// firstImage is an integer, 0-9, the first image to display.
// gallery is the gallery name or number. Name must be ESCAPED in the link, e.g. ?fine%20art
// will match Fine Art, but not Fine Art II.
whichie=document.URL.split("?");
if (whichie.length>1) {
	arr=whichie[1].split("&");
	if (arr[0].length>0) {
		if (isNaN(arr[0])) { // if not passed a number, then see if it's the name of a gallery
			arr[0]=unescape(arr[0]);
			for (i=0; i<galleries.length; i++) {
				if (arr[0]==galleries[i].toLowerCase()) {
					gallerySelect=i;
					i=galleries.length;
				}
			}
		}
		else if (arr[0]<galleries.length) gallerySelect=arr[0];
	}
	if (arr.length==2) if (arr[1]<10) firstPhoto=arr[1];
	document.title=mainTitle+galleries[gallerySelect];
}

/*	Place the thumbnails and the main photo */

function placeThumbs() {
	highestThumb=0;									// This is so I can move the gallery text up and down
	for (i=0; i<photos.length; i++) {				// Look at all photos
		p=photos[i].split("|");
		if (p[1]==gallerySelect) {					// If this photo belongs in the gallery then document.write it.
			document.write('<div id="thumb'+p[2]+'" onclick="newPhoto('+p[2]+')"><img src="'+imagePath+p[0]+'_th.jpg" alt=" " /></div>');
			selecter[p[2]]=i;
			if (p[2]>highestThumb) highestThumb=p[2];
		}
	}
//	document.write('<div id="mainphoto"><img id="the_photo" alt="Image" /></div>');
	document.write('<div id="quuip"><p class="quip_style">Click a thumbnail to view the larger image.</p></div>');
	linkString="Galleries: ";
	for (i=0; i<galleries.length; i++) {
		if (listCurrentGal || (i!=gallerySelect)) {
			if (linkString.length>6) linkString+=' :: ';
			linkString+='<a href="./gallery.html?'+i+'">'+galleries[i]+'</a>';
		}
	}
	zobj=document.getElementById("heading-n-lead-text");		// For this client, the gallery name and copy go below the thumbs
	zobjTop=80+Math.floor(highestThumb/4)*80;					// Determine the top and bottomPadding based on the highest-Top thumb
	zobj.style.top=zobjTop+"px";								// Set the top
	zobj.style.paddingBottom=zobjTop+"px";						// Set the paddingBottom
	zobj.innerHTML="<h2>"+galleries[gallerySelect]+"</h2><p>"+galText[gallerySelect]+"</p><hr /><p>"+linkString+"</p>"; 
}

function placeLinks() {
	document.write(linkString);
}

function newPhoto(i) {
//	obj=document.getElementById("the_photo");
	while(selecter[i]==-1) { i++; }
	p=photos[selecter[i]].split("|");														// get the photo information
//	obj.style.width=(parseInt(p[3])).toString()+"px";
//	obj.style.height=(parseInt(p[4])).toString()+"px";
	mmm=document.getElementById("mainphoto");
//	mmm.style.top=Math.floor(defTop+(defHeight-Math.floor(p[4]))/2).toString()+"px";		// Reposition based on height
	mmm.style.left=Math.floor(defLeft+(defWidth-Math.floor(p[3]))/2).toString()+"px";		// Reposition based on width
	mmm.style.width=(parseInt(p[3])).toString()+"px";
	mmm.style.height=(parseInt(p[4])).toString()+"px";
	mmm.style.background="#ffffff url("+imagePath+p[0]+".jpg) no-repeat scroll center center"
	mmm.style.display="block";																// Make the area visible
	quipz=((p[5].length>0)?p[5]:mainTitle+galleries[gallerySelect]);				// Set the quip to the proper text
	quip=document.getElementById("quuip");
	quip.style.top=Math.floor(10+brdrWidth*2+defTop-146+(defHeight+Math.floor(p[4]))/2).toString()+"px";	// Move the quip so it's beneath the image
	quip.innerHTML='<p class="quip_style">'+quipz+'</p>'; 
}
