function initImageSet(image_setID, status){
	numImages = galleryarray[image_setID][status];
	numPages = Math.ceil(numImages/6);
	numImagesLastPage = numImages % 6;
	currentPage = 1;
	
	constructDescription(image_setID, status, currentPage, numPages);
	constructMainImage(image_setID, 1, status, currentPage);
	constructThumbnails(image_setID, status, currentPage, numPages, numImagesLastPage);
}

function resetImageSet(){
	
	// reset description
	hza = document.getElementById('desc');
	hza.innerHTML = "";
	
	// reset main image
	hza = document.getElementById('maincontent');
	hza.innerHTML = '<img src=\"images/intro_specials.jpg\" alt=\"Car Restoration\" />';
	
	// reset thumbnails
	hza = document.getElementById('content_2');
	hza.innerHTML = '';
	
}

function constructDescription(image_setID, status, currentPage, numPages){
	
	var statusLabel = "";
	
	switch(status) // assign text to status
	{
		case 0:
			statusLabel = "before";
			break;
		case 1:
			statusLabel = "during";
			break;
		case 2:
			statusLabel = "after";
			break;
		default:
			break;
	}
	
	hza = document.getElementById('desc');
	hza.innerHTML = galleryarray[image_setID][3] +" "+ galleryarray[image_setID][4] +" "+ galleryarray[image_setID][5] +" - "+statusLabel+" [ "+currentPage+" of "+numPages+" ] ";
	
}

function constructMainImage(image_setID, image_ID, status, currentPage){
	
	hza = document.getElementById('maincontent');
	hza.innerHTML = '<img src=\'images/gallery/'+galleryarray[image_setID][3]+'_'+galleryarray[image_setID][4]+'_'+galleryarray[image_setID][5]+'_'+status+'_'+image_ID+'.jpg\' alt=\''+galleryarray[image_setID][3]+'\' />';
	
}

function constructThumbnails(image_setID, status, currentPage, numPages, numImagesLastPage){
	
	hza = document.getElementById('content_2');
	var tString='', limit = 0;
	
	if (currentPage < numPages) {
		limit = 6;
	}
	else if (currentPage == numPages) {
		if (numImagesLastPage==0)
			limit = 6;
		else
			limit = numImagesLastPage;
	}
	
//	alert(currentPage+" "+numPages+" "+numImagesLastPage+" "+limit);
	
	for (i=1; i<=limit; i++) {
			tString += '<div id="thumb'+i+'" class="slideshow" onclick="constructMainImage('+image_setID+','+((6*currentPage-6)+i)+','+status+')"><img width="48" height="48" src=\'images/gallery/'+galleryarray[image_setID][3]+'_'+galleryarray[image_setID][4]+'_'+galleryarray[image_setID][5]+'_'+status+'_'+((6*currentPage-6)+i)+'_sm.jpg\' /></div>';
	}
		
	// case: right arrow on all but last page
	if (numPages > 1 && (currentPage < numPages))
		tString += '<div id=\"arrow2\"><a href=\"#\"><img src=\"images/arrow-up-right.jpg\" onclick="constructThumbnails('+image_setID+','+status+','+(currentPage+1)+','+numPages+','+numImagesLastPage+');constructDescription('+image_setID+', '+status+', '+(currentPage+1)+', '+numPages+')" /></a></div>';
		
	// case: left arrow on all but first
	if (numPages > 1 && currentPage > 1)
		tString += '<div id=\"arrow2\"><a href=\"#\"><img src=\"images/arrow-up-left.jpg\" onclick="constructThumbnails('+image_setID+','+status+','+(currentPage-1)+','+numPages+','+numImagesLastPage+');constructDescription('+image_setID+', '+status+', '+(currentPage-1)+', '+numPages+')" /></a></div>';
	
	
	hza.innerHTML = tString;
}
