gallerySelect=-1;
firstPhoto=0;
defTop=0;
defLeft=200;
defHeight=180;
defWidth=300;
listCurrentGal=true;		// Do I show the current gallery's name in the list of links beneath the photo?
brdrWidth=2;				// The width of the border I use on the style sheet
mainTitle="Josh, Inc. Photo Gallery: ";
imagePath="./photos/";
enlargeArea=3;				// Enlarge the area IF the image space includes a false drop shadow!
var textSetUp=false;
var zeroPhotos=true;

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]<12) firstPhoto=arr[1];
	document.title=mainTitle+galleries[gallerySelect];
//	document.write('<h1>Portfolio: '+galleries[gallerySelect]+'</h1>');
}

/*	Place the thumbnails and the main photo */
/*  galName is the text name of the gallery to display. But it can be overridden? */

function placeThumbs(galName, quipType) {

	if (quipType=="deluxe") enlargeArea=5;		// make a little bit bigger.	
	if (gallerySelect==-1) for (i=0; i<galleries.length; i++) {
		if (galleries[i]==galName) { gallerySelect=i; i=galleries.length; }
	}
	
	
	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;
			zeroPhotos=false;
		}
	}
	linkString="More Images: ";
	for (i=0; i<galleries.length; i++) {
		if (listCurrentGal || (i!=gallerySelect)) {
			if (linkString.length>15) linkString+=', ';
			linkString+='<a href="./gallery.html?'+i+'">'+galleries[i]+'</a>';
		}
	}
//	document.write('<div id="quuip"><p class="no_pad">'+linkString+'</p></div>');
//	document.write('<div id="mainphoto"><img id="the_photo" alt="Image" /></div>');
	document.write('<div id="mainphoto"><img id="the_photo" alt="Image Loading ..." ></div>');
//	document.write('<div id="quuip"><p id="the_quip"> </p></div>');
}

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

function newPhoto(i) {
	if (!textSetUp) {
		var obj=document.getElementById("gal_"+gallerySelect);
		if (obj) {
			obj.style.fontWeight="bold";
			obj.style.color="#000000";
		}
		obj=document.getElementById("galleryCaption");
		obj.innerHTML=galText[gallerySelect]
		textSetUp=true;
		if (zeroPhotos) {
			obj=document.getElementById("mainphoto");
			obj.style.display="none";
		}
	}

	if (!zeroPhotos) {
		flashBorder(firstPhoto, "#ffffff");
		flashBorder(i, "#66cc66");
		firstPhoto=i;
		obj=document.getElementById("the_photo");
		obj.src=imagePath+"image-space.gif";
		while(selecter[i]==-1) { i++; }
		p=photos[selecter[i]].split("|");														// get the photo information
		enlargeAreaX=Math.floor(enlargeArea*parseInt(p[3])/450);
		enlargeAreaY=Math.floor(enlargeArea*parseInt(p[4])/450);
		obj.style.width=(parseInt(p[3])+enlargeAreaX).toString()+"px";
		obj.style.height=(parseInt(p[4])+enlargeAreaY).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])+enlargeAreaX).toString()+"px";
		obj.style.height=(parseInt(p[4])+enlargeAreaY).toString()+"px";
		obj.src=imagePath+p[0]+".jpg";
	//	mmm.style.background="#000000 url('"+imagePath+p[0]+".jpg') no-repeat fixed 50% 50%"
		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(20+defTop+(defHeight+Math.floor(p[4]))/2).toString()+"px";	// Move the quip so it's beneath the image
//		quip.innerHTML='<p class="quip_style">'+quipz+'<br />'+linkString+'</p>';
	}
}

function adjustWidth(w) { defWidth=w; }
function adjustHeight(w) { defHeight=w; }

function flashBorder(divvie, color) {
	var obj=document.getElementById("thumb"+divvie);
	obj.style.border="2px solid "+color;
}
