
imgSelected = 0;

shadeImg = (pngSupport) ? "/images/shade.png" : "/images/shade.gif";

function thumbOver(artId) {
	if (!pngSupport || !imgSelected) {
		el = document.getElementById('holder'+artId);
		el.style.borderColor = '#6a6658';
	} else {
		spaceEl = document.getElementById('thumb'+artId);
		spaceEl.src = '/images/space.gif';
	}
}

function thumbOut(artId) {
	if (!pngSupport || !imgSelected) {
		if (artId!=imgSelected) {
			el = document.getElementById('holder'+artId);
			el.style.borderColor = '#4a4945';
		}
	} else {		
		if (imgSelected) {
			spaceEl = document.getElementById('thumb'+artId);
			spaceEl.src = (artId==imgSelected) ? '/images/space.gif' : shadeImg;
		} else {
			el = document.getElementById('holder'+artId);
			el.style.borderColor = '#4a4945';
		}
	}
}

artIds = new Array();
function thumbClick(artworkId) {
	imgSelected = artworkId;
	
	galleryFeatureEl = document.getElementById('galleryFeature');
	galleryFeatureEl.style.display = '';
	
	// shade all other images
	if (!artIds.length) {
		divs = document.getElementsByTagName('DIV');
		for(d=0;d<divs.length;d++) {
			div = divs[d];
			if (artId = div.getAttribute('artId')) {
					artIds[artIds.length] = artId;
			}
		}
	}
	
	for(i=0;i<artIds.length;i++) {
		artId = artIds[i];
		if (pngSupport) {
			spaceEl = document.getElementById('thumb'+artId);
			spaceEl.src = (artId==artworkId) ? '/images/space.gif' : shadeImg;
			
			el = document.getElementById('holder'+artId);
			el.style.borderColor = '#4a4945';
		} else {
			if (artId!=imgSelected) {
				el = document.getElementById('holder'+artId);
				el.style.borderColor = '#4a4945';
			}
		}
	}
	
	document.galleryForm.blurer.focus();
	document.galleryForm.blurer.blur();
	
	setTimeout(setGfx,1);
	
}

function setGfx() {
	featureTitleEl = document.getElementById('featureTitle');
	featureInfoEl = document.getElementById('featureInfo');
	featureInfoEl.innerHTML = '';
	featureTitleEl.innerHTML = '';
	featureImgEl = document.getElementById('featureImg');
	featureImgEl.src = "/images/shade.png";
	featureImgEl.src = "/resources/artwork_large.php?art="+imgSelected;
	featureImgEl.style.height = document.galleryForm['artHeight'+imgSelected].value+'px';
	featureImgEl.style.width = document.galleryForm['artWidth'+imgSelected].value+'px';
	featureShadowInnerEl = document.getElementById('featureShadowInner');
	featureShadowInnerEl.style.width = 1*(document.galleryForm['artWidth'+imgSelected].value)-16;
	
	td1El = document.getElementById('td1');
	td1El.width = 1*(document.galleryForm['artWidth'+imgSelected].value)+12;
	
	setTimeout(setGfx2,1);
}

function setGfx2() {
	artTitle = document.galleryForm['artName'+imgSelected].value;
	
	featureTitleEl = document.getElementById('featureTitle');
	featureInfoEl = document.getElementById('featureInfo');
	featureInfoEl.innerHTML = document.galleryForm['artInfo'+imgSelected].value;
	featureTitleEl.innerHTML = artTitle;

	artTitle = artTitle.substr(0,((artTitle.indexOf('<br>')!=-1)?artTitle.indexOf('<br>'):artTitle.length));
		
	document.title = 'Gallery -- '+artTitle+' -- Chris Bennett';
}

function expandArt() {
	newLoc = "/resources/artwork_xlarge.php?art="+imgSelected;
	
	old_x = document.galleryForm['artWidth'+imgSelected].value;
	old_y = document.galleryForm['artHeight'+imgSelected].value

	maxW =  800;
	maxH = 700;
	
	if (old_x/old_y > maxW/maxH) {
		new_x = maxW;
		new_y = Math.floor(old_y*(new_x/old_x));
	} else {
		new_y = maxH;
		new_x = Math.floor(old_x*(new_y/old_y));		
	}
	
	expWidth = new_x;
	expHeight = new_y;	
	
	expandedWin = window.open(newLoc,'expandedWin',"width="+expWidth+",height="+expHeight);
	expandedWin.focus();
}






