
var gallery_curid=-1;
var gallery_window;
var gallery_imgs;
var gallery_descs;
var gallery_imgpath;

function gallery_open(name,file) {
	gallery_window = window.open(file,name,"height=740,width=1000,resizable=yes,scrollbars=yes");
}

function gallery_init(imgs,descs,imgpath) {
	gallery_imgs = imgs;
	gallery_descs = descs;
	gallery_imgpath = imgpath;

	if(gallery_imgs.length > 0) {
		gallery_curid=0;
		
		links = document.getElementById("list");
		for(i=0; i<gallery_imgs.length; i++) {
			link = document.createElement("a");
			link.appendChild(document.createTextNode(i+1));
			link.href = "javascript:gallery_show("+i+")";
			links.appendChild(link)
		}
		
		gallery_update();
	}
}

function gallery_next() {
	
	if(gallery_curid < gallery_imgs.length-1) {
		gallery_curid++;
	} else {
		gallery_curid = 0;
	}

	gallery_update();
}

function gallery_prev() {
	
	if(gallery_curid > 0) {
		gallery_curid--;
	} else {
		gallery_curid = gallery_imgs.length-1;
	}
	
	gallery_update();
}

function gallery_show(id) {
	gallery_curid = id;
	
	gallery_update();
}

function gallery_update() {
	img = document.getElementById("image");
	tmpimg = new Image();
	tmpimg.src = gallery_imgpath+"/"+gallery_imgs[gallery_curid];
	img.src = tmpimg.src;
	
	desc = document.getElementById("description");
	while(desc.hasChildNodes()) {
		desc.removeChild(desc.firstChild);
	}
	txtnode = document.createTextNode(gallery_descs[gallery_curid]);
	desc.appendChild(txtnode);
}

