// ------------------------------------------------------------- Start of Variable Setting -----------------------------------------
var delay = 6000 //set delay in miliseconds

var curImgGroupIndex = 0;
var curImgIndex = 0;
var maxImgIndex = 0;
var lock = true;
var run;

var galleryImgPath    = new Array();
var galleryImgCaption = new Array();

galleryImgPath[0]       = new Array(6);
galleryImgPath[0][0]    = "../tch/images/gallery/cover47/4701.jpg";
galleryImgPath[0][1]    = "../tch/images/gallery/cover47/4702.jpg";
galleryImgPath[0][2]    = "../tch/images/gallery/cover47/4703.jpg";
galleryImgPath[0][3]    = "../tch/images/gallery/cover47/4704.jpg";
galleryImgPath[0][4]    = "../tch/images/gallery/cover47/4705.jpg";
galleryImgPath[0][5]    = "../tch/images/gallery/cover47/4706.jpg";



galleryImgCaption[0]    = new Array(6);
galleryImgCaption[0][0] = "跳出『公營』『市區』『重建』框框研討會";
galleryImgCaption[0][1] = "跳出『公營』『市區』『重建』框框研討會";
galleryImgCaption[0][2] = "跳出『公營』『市區』『重建』框框研討會";
galleryImgCaption[0][3] = "跳出『公營』『市區』『重建』框框研討會";
galleryImgCaption[0][4] = "跳出『公營』『市區』『重建』框框研討會";
galleryImgCaption[0][5] = "跳出『公營』『市區』『重建』框框研討會";

//------------------------------------------------------------- End of Variable Setting -----------------------------------------


function initImage() {
	curImgGroupIndex = 0;
	curImgIndex = 0;
	maxImgIndex = galleryImgPath[curImgGroupIndex].length - 1;
	lock = false;
	
	document.getElementById("galleryImg").src = galleryImgPath[curImgGroupIndex][curImgIndex];
  	document.getElementById("galleryImgCaption").innerHTML = galleryImgCaption[curImgGroupIndex][curImgIndex];

  	autoImage();
}

function autoImage() {
	if (lock == true) {
		lock = false;
		window.clearInterval(run);
	} else if (lock == false) {
		lock = true;
		run = setInterval("rotateImage()", delay);
   }
}

function rotateImage() {
	nextImage();
}

function previousImage() {
	var prevImgIndex = curImgIndex - 1;
	if (prevImgIndex < 0) {
		prevImgIndex = maxImgIndex;
	}
	curImgIndex = prevImgIndex;
	
	document.getElementById("galleryImg").src = galleryImgPath[curImgGroupIndex][curImgIndex];
  	document.getElementById("galleryImgCaption").innerHTML = galleryImgCaption[curImgGroupIndex][curImgIndex];
}

function nextImage() {
	var nextImgIndex = curImgIndex + 1;
	if (nextImgIndex > maxImgIndex) {
		nextImgIndex = 0;
	}
	curImgIndex = nextImgIndex;
	
	document.getElementById("galleryImg").src = galleryImgPath[curImgGroupIndex][curImgIndex];
  	document.getElementById("galleryImgCaption").innerHTML = galleryImgCaption[curImgGroupIndex][curImgIndex];
}

function changeImageGroup(groupIndex) {
	curImgGroupIndex = groupIndex;
	curImgIndex = 0;
	maxImgIndex = galleryImgPath[groupIndex].length - 1;
	
	document.getElementById("galleryImg").src = galleryImgPath[curImgGroupIndex][curImgIndex];
  	document.getElementById("galleryImgCaption").innerHTML = galleryImgCaption[curImgGroupIndex][curImgIndex];
}

function popupImage() {
	document.getElementById("hiddenGalleryImg").src = galleryImgPath[curImgGroupIndex][curImgIndex];
	document.getElementById("hiddenGalleryImgCaption").innerHTML = galleryImgCaption[curImgGroupIndex][curImgIndex];

	window.open('gallery_photo_popup.html', '', 'scrollbars=yes, width=400, height=350');
}

