
function imgprev() {
	imgcurrent--;
	if( imgcurrent < 0 ) {
		imgcurrent = 0;
	} else {
		imgload( img[imgcurrent] );
	}
}

function imgnext() {
	imgcurrent++;
	if( imgcurrent > (img.length-1) ) {
		imgcurrent = img.length - 1;
	} else {
		imgload( img[imgcurrent] );
	}
}

function imgjump(id,num) {
	if( num != imgcurrent ) {
		imgcurrent = num;
		imgload(id);
	}
}

function imgload(id) {
	dojo.query( '.p_nav').forEach( function(e, ind) {
		e.className = 'p_nav';
	});
	dojo.query( '.p_nav_a').forEach( function(e, ind) {
		e.className = 'p_nav';
	});

	dojo.fadeOut({
		node: dojo.byId('id_photo'),
		duration: 300,
		onEnd:function() {
			dojo.byId('p_nav_' + imgcurrent).className = 'p_nav_a';
			dojo.xhrGet({
				url: "/a_photo.php?id=" + id,
				handleAs: "json",
				timeout: 7000,
				load: function( response, ioArgs ) {
					dojo.byId('id_caption').innerHTML = response.photo_description;
					
					var n = dojo.byId('id_photo');
					n.src = '/photographs/' + response.filename + '.jpg';
					dojo.byId('id_photo_link').href = '/gallery.php?photo=' + response.id;
					dojo.connect( n, "onload", function(e) {
						dojo.fadeIn({
							node: dojo.byId('id_photo'),
							duration: 300
						}).play();
					});

					return response;
				},
				error: function( response, ioArgs ) {
					return response;
				}
			});
		}
	}).play();
	
}
