gallerySelect=0;
firstPhoto=0;
defTop=0;
defLeft=450;
defHeight=410;
defWidth=440;
listCurrentGal=true;		// Do I show the current gallery's name in the list of links beneath the photo?
brdrWidth=4;				// The width of the border I use on the style sheet
mainTitle="Artisan Direct: ";
imagePath="./artwork/";

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() {
	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;
		}
	}
//	document.write('<div id="mainphoto"><img id="the_photo" alt="Image" /></div>');
	document.write('<div id="mainphoto"><img id="the_photo" alt="Image" src="../../images/image-space.gif"></div>');
	document.write('<div id="quuip"><p class="quip_style"> </p></div>');
	document.getElementById("heading-n-lead-text").innerHTML="<h1>"+galleries[gallerySelect]+"</h1><p>"+galText[gallerySelect]+"</p><hr>"; 
	linkString="More: ";
	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>';
		}
	}
}

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
	obj.style.width=(parseInt(p[3])).toString()+"px";
	obj.style.height=(parseInt(p[4])).toString()+"px";
	mmm.style.background="#333333 url("+imagePath+p[0]+".jpg)"
	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+(defHeight+Math.floor(p[4]))/2).toString()+"px";	// Move the quip so it's beneath the image
	quip.style.top=Math.floor(brdrWidth*2+defTop+(Math.floor(p[4]))).toString()+"px";	// Move the quip so it's beneath the image
	quip.innerHTML='<p class="quip_style">'+quipz+'</p>';
	document.getElementById("gal_gallery").style.height=Math.max(450, (quip.offsetHeight+parseInt(p[4])+30))+"px";
}
