// ------------------------------------------------------------- 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(8);
galleryImgPath[0][0]    = "images/gallery/cover17/1701.jpg";
galleryImgPath[0][1]    = "images/gallery/cover17/1702.jpg";
galleryImgPath[0][2]    = "images/gallery/cover17/1703.jpg";
galleryImgPath[0][3]    = "images/gallery/cover17/1704.jpg";
galleryImgPath[0][4]    = "images/gallery/cover17/1705.jpg";
galleryImgPath[0][5]    = "images/gallery/cover17/1706.jpg";
galleryImgPath[0][6]    = "images/gallery/cover17/1707.jpg";
galleryImgPath[0][7]    = "images/gallery/cover17/1708.jpg";





galleryImgCaption[0]    = new Array(8);
galleryImgCaption[0][0] = "青年立法會 - 議政訓練證書課程";
galleryImgCaption[0][1] = "青年立法會 - 議政訓練證書課程";
galleryImgCaption[0][2] = "青年立法會 - 議政訓練證書課程";
galleryImgCaption[0][3] = "青年立法會 - 議政訓練證書課程";
galleryImgCaption[0][4] = "青年立法會 - 議政訓練證書課程";
galleryImgCaption[0][5] = "青年立法會 - 議政訓練證書課程";
galleryImgCaption[0][6] = "青年立法會 - 議政訓練證書課程";
galleryImgCaption[0][7] = "青年立法會 - 議政訓練證書課程";




//------------------------------------------------------------- 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');
}

