// ------------------------------------------------------------- Start of Variable Setting -----------------------------------------
var delay = 5000 //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(16);
galleryImgPath[0][0]    = "images/gallery/cover2/0267.jpg";
galleryImgPath[0][1]    = "images/gallery/cover2/0287.jpg";
galleryImgPath[0][2]    = "images/gallery/cover2/0259.jpg";
galleryImgPath[0][3]    = "images/gallery/cover2/0254.jpg";
galleryImgPath[0][4]    = "images/gallery/cover2/0255.jpg";
galleryImgPath[0][5]    = "images/gallery/cover2/0253.jpg";
galleryImgPath[0][6]    = "images/gallery/cover2/107.jpg";
galleryImgPath[0][7]    = "images/gallery/cover2/108.jpg";
galleryImgPath[0][8]    = "images/gallery/cover2/109.jpg";
galleryImgPath[0][9]    = "images/gallery/cover2/110.jpg";
galleryImgPath[0][10]    = "images/gallery/cover2/111.jpg";
galleryImgPath[0][11]    = "images/gallery/cover2/112.jpg";
galleryImgPath[0][12]    = "images/gallery/cover2/113.jpg";
galleryImgPath[0][13]    = "images/gallery/cover2/114.jpg";
galleryImgPath[0][14]    = "images/gallery/cover2/115.jpg";
galleryImgPath[0][15]    = "images/gallery/cover2/116.jpg";



galleryImgCaption[0]    = new Array(16);
galleryImgCaption[0][0] = "市區更新匯意坊位於灣仔太原街38號";
galleryImgCaption[0][1] = "市區更新匯意坊入口";
galleryImgCaption[0][2] = "市區更新匯意坊室內環境";
galleryImgCaption[0][3] = "市區更新匯意坊討論區";
galleryImgCaption[0][4] = "市區更新匯意坊電腦閣";
galleryImgCaption[0][5] = "市區更新匯意坊室內環境";
galleryImgCaption[0][6] = "《市區重建策略》檢討的最新資料";
galleryImgCaption[0][7] = "《市區重建策略》檢討的最新資料";
galleryImgCaption[0][8] = "《市區重建策略》檢討的最新資料";
galleryImgCaption[0][9] = "《市區重建策略》檢討的最新資料";
galleryImgCaption[0][10] = "《市區重建策略》檢討的最新資料";
galleryImgCaption[0][11] = "《市區重建策略》檢討的最新資料";
galleryImgCaption[0][12] = "《市區重建策略》檢討的最新資料";
galleryImgCaption[0][13] = "《市區重建策略》檢討的最新資料";
galleryImgCaption[0][14] = "《市區重建策略》檢討的最新資料";
galleryImgCaption[0][15] = "《市區重建策略》檢討的最新資料";
//------------------------------------------------------------- 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');
}

