function resize_window(){
  winWidth=document.all?document.body.clientWidth:window.innerWidth;
  winHeight=document.all?document.body.clientHeight:window.innerHeight;   

  x = (document.getElementById('large_image').width + 320) - winWidth
  y = (document.getElementById('large_image').height + 80) - winHeight
  
  if (x <= 0) x = 0
  if (y <= 0) y = 0 
  
  window.resizeBy(x,y)
}

var gallery_pos = 0;

function change_image(new_position) {
	gallery_pos = new_position;
	document.large_image.src = gallery[new_position].file;
	document.getElementById('caption').innerHTML = gallery[new_position].caption;
}

function browse(direction) {
	if (direction == 'next') {
		var new_position = (gallery_pos + 1 < gallery_lenght) ? gallery_pos + 1 : 0;
	} else {
		var new_position = (gallery_pos > 0) ? gallery_pos - 1 : gallery_lenght - 1;
	}
	change_image(new_position);
}
