var mainbook = new Image;
var curr_img = 0;
var img_cnt = 0;	 
var img_offset = 4;	 

function update_tmb(id, sw) {
	id = id + img_offset;
	if(!sw) document.images[id].style.borderWidth='0px';
	else document.images[id].style.borderWidth='5px';
}
function get_full(id) {
	var idx = document.images[id].src.indexOf("gal/th_") + 7;
	return "gal/" + document.images[id].src.substring(idx,55);
}
function loadimage(nxt_img) {
	var wdth = 450;
	var hgt = 450;
	var maxhgt = 450;
	var id = nxt_img + img_offset;

	hgt = Math.round((document.images[id].height/document.images[id].width)*wdth);
	if(hgt > maxhgt) {hgt = maxhgt; wdth = Math.round((document.images[id].width/document.images[id].height)*hgt);}
  
	document.mainbook.src = get_full(id);
	document.mainbook.style.width = wdth + 'px';
	document.mainbook.style.height = hgt  + 'px';

	update_tmb(curr_img, 0);
	curr_img = nxt_img;
	update_tmb(curr_img, 1);
} 
function chg_img(direction) {
	var nxt_img = curr_img;

	nxt_img += direction;
	if(nxt_img>=img_cnt) { 
			nxt_img=0; }
	else if(nxt_img<0) { 
			nxt_img=img_cnt-1; }

	loadimage(nxt_img);		
}
function dsp_img()
{
window.open(document.mainbook.src, "disp");
}
function init()
{
var id, i = 0;
var temp = new Array();
loadimage(0);
img_cnt = document.images.length - img_offset;
for(id=0; id<img_cnt; id++) {
	temp[id] = new Image;
	temp[id].src = get_full(id+img_offset);
	}
}


