var caption_count = 0;

var blank_img_url = '/i/z5/illo/nw/hardware/misc/blank.gif';


function refresh_images() {

	// each of the positions
	for(i=1;i<=5;i++) {

		image_elem = document.getElementById('inav'+ i);

		if( image_elem ) {


			image_index = i - 3 + (image_pos - 1);

			// put the thumbnail in there
			if(thumbs[image_index]) {
				image_elem.src = thumbs[image_index];
			} else {
				image_elem.src = blank_img_url;
			}


			// mark the selected item class
			if( image_index == image_selected ) {
				image_elem.className = 'ithumb selected';
				image_elem.parentNode.parentNode.className = 'eachThumb selected';
			} else {
				image_elem.className = 'ithumb';
				image_elem.parentNode.parentNode.className = 'eachThumb';
			}
		}
	}
}

function refresh_captions(cpos) {
	// each of the positions
	for(i=0;i<=caption_count;i++) {

		caption_elem = document.getElementById('icaption'+ i);

		if( caption_elem ) {

			// make the selected item visible:
			if( i == cpos ) {
				caption_elem.style.display = 'block';
			} else {
				caption_elem.style.display = 'none';
			}
		}
	}
}

function show_image(pos) {

	// work out which image to display
	image_index = image_pos + pos - 4;

	url =  base_gallery_url.replace("-999,", "-"+ (image_index + 1) +",");

	if (thumbs[image_index]) {
		location.href = url;
	}
}

function prev_image() {
	if( image_pos > 1 ) {
		image_pos--;
	}
	refresh_images();
}


function next_image() {
	if( image_pos < thumbs.length ) {
		image_pos++;
	}
	refresh_images();
}