var pic_index = 0;

function windowgallery(story_id, range, order_no) {
var arr = range.split('-');
var new_i = parseInt(arr[0])+parseInt(order_no) - 1;
	//window.open("/gallery.php?story_id=" + story_id + "&range=" + range + "&no=" + order_no, "gallery" + story_id, "width=500,height=400,status=no,toolbar=no,menubar=no,scrollbars=yes,resizable=yes");
	window.open("/story_picture/show/romance/" + story_id + "/" + range + "/" + new_i+"");

}

function next() {
	if (pic_index == num_array - 1) {
		pic_index = 0;
	}
	else {
		pic_index++;
	}
	insertpic();
}

function prev() {
	if (pic_index == 0) {
		pic_index = num_array - 1;
	}
	else {
		pic_index--;
	}
	insertpic();
}

function insertpic() {
	start = pic_index;
	for (i=0; i<pic_col; i++) {
		my_pic = eval("document.images.gal_img" + i);
		my_pic.src = Arraypics[start++];
		if (start == num_array) {
			start = 0;
		}
	}
}

function display(story_id, range, clickno) {
	start = pic_index + clickno;
	if (start > num_array - 1) {
		start = start - num_array;
	}
	windowgallery(story_id, range, start + 1);
}

function chkbig(story_id, clickno) {
	start = pic_index + clickno;
	if (start > num_array - 1) {
		start = start - num_array;
	}
	document.images.gal_big.src = replaceChars(replaceChars(Arraypics[start], '/s/', '/b/'), '/m/', '/b/');
}

function replaceChars(entry, out, sadd) {
	temp = entry;
	while (temp.lastIndexOf(out) > -1) {
		pos = temp.lastIndexOf(out);
		temp = "" + (temp.substring(0, pos) + sadd + temp.substring((pos + out.length), temp.length));
	}
	return temp;
}


