function initImageSet(image_setID){
	numImages = galleryarray[image_setID][0];
	numPages = Math.ceil(numImages/6);
	numImagesLastPage = numImages % 6;
	currentPage = 1;
	
	constructDescription(image_setID, currentPage, numPages);
	constructMainImage(image_setID, 1, currentPage);
	constructThumbnails(image_setID, 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, currentPage, numPages){
	
	hza = document.getElementById('desc');
	hza.innerHTML = galleryarray[image_setID][1] +" "+ galleryarray[image_setID][2] +" "+ galleryarray[image_setID][3] +" [ "+currentPage+" of "+numPages+" ] <a href=\"index.php\">Back ></a>";
	
}

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

function constructThumbnails(image_setID, 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;
	}
	
	for (i=1; i<=limit; i++) {
			tString += '<div id="thumb'+i+'" class="slideshow" onclick="constructMainImage('+image_setID+','+((6*currentPage-6)+i)+')"><img width="48" height="48" src=\'images/gallery/'+galleryarray[image_setID][1]+'_'+galleryarray[image_setID][2]+'_'+galleryarray[image_setID][3]+'_3_'+((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+','+(currentPage+1)+','+numPages+','+numImagesLastPage+');constructDescription('+image_setID+', '+(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+','+(currentPage-1)+','+numPages+','+numImagesLastPage+');constructDescription('+image_setID+', '+(currentPage-1)+', '+numPages+')" /></a></div>';
	
	
	hza.innerHTML = tString;
}