// ------------------------------------------------------------- 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(10);
galleryImgPath[0][0]    = "images/gallery/cover25/2501.jpg";
galleryImgPath[0][1]    = "images/gallery/cover25/2502.jpg";
galleryImgPath[0][2]    = "images/gallery/cover25/2503.jpg";
galleryImgPath[0][3]    = "images/gallery/cover25/2504.jpg";
galleryImgPath[0][4]    = "images/gallery/cover25/2505.jpg";
galleryImgPath[0][5]    = "images/gallery/cover25/2506.jpg";
galleryImgPath[0][6]    = "images/gallery/cover25/2507.jpg";
galleryImgPath[0][7]    = "images/gallery/cover25/2508.jpg";
galleryImgPath[0][8]    = "images/gallery/cover25/2509.jpg";
galleryImgPath[0][9]    = "images/gallery/cover25/2510.jpg";



galleryImgCaption[0]    = new Array(10);
galleryImgCaption[0][0] = "另類市區更新展覽";
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] = "另類市區更新展覽";


//------------------------------------------------------------- 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');
}

