/*** Imagallery
Author : Warren Harding
Department : Information Technology
Company : Tourism Development Company
*/
function Imgallery  (strImg, strGal, strFul, strThm, imgarr, splane, interval, displayArea, progress, animator, animation, endpoint, name) {
	this.strImg = strImg;
	this.strGal = strGal;
	this.strFul = strFul;
	this.strThm = strThm;
	this.imgarr = imgarr;
	this.interval = interval;
	this.splane = document.getElementById(splane);
	this.displayArea = document.getElementById(displayArea);
	this.progress = document.getElementById(progress);
	this.animator = document.getElementById(animator);
	this.ani_stop = false;
	this.thumbs = Imgallery_ldImg (strImg + '/' + strGal + '/' + strThm + '/', imgarr);
	this.imgs = null;
	this.animation = animation;
	this.endpoint = document.getElementById(endpoint);
	this.current = 0;
	this.Imgallery_frame = Imgallery_frame;
	this.Imgallery_check_progress = Imgallery_check_progress;
	this.Imgallery_load_gallery = Imgallery_load_gallery;
	this.Imgallery_genGalleryStr = Imgallery_genGalleryStr;
	this.Imgallery_changeImg = Imgallery_changeImg;
	this.name = name;
}

function ImgalleryCaption (strImg, strGal, strFul, strThm, imgarr, caparr, splane, interval, displayArea, captionArea, progress, animator, animation, endpoint, name) {
	this.strImg = strImg;
	this.strGal = strGal;
	this.strFul = strFul;
	this.strThm = strThm;
	this.imgarr = imgarr;
	this.interval = interval;
	this.splane = document.getElementById(splane);
	this.displayArea = document.getElementById(displayArea);
	this.captionArea = document.getElementById(captionArea);
	this.progress = document.getElementById(progress);
	this.animator = document.getElementById(animator);
	this.ani_stop = false;
	this.thumbs = Imgallery_ldImg (strImg + '/' + strGal + '/' + strThm + '/', imgarr);
	this.imgs = null;
	this.animation = animation;
	this.endpoint = document.getElementById(endpoint);
	this.current = 0;
	this.Imgallery_frame_cap = Imgallery_frame_cap;
	this.Imgallery_check_progress = Imgallery_check_progress;
	this.Imgallery_load_gallery_caption = Imgallery_load_gallery_caption;
	this.Imgallery_genGalleryCapStr = Imgallery_genGalleryCapStr;
	this.Imgallery_changeImgCap = Imgallery_changeImgCap;
	this.Imgallery_changeImg = Imgallery_changeImg;
	this.name = name;
	this.captions = caparr;
}

function Imgallery_ldImg (path, imgarr) {
	var temparr = new Array ();
	for (i = 0; i < imgarr.length; i++) {
		var temp = new Image();
		temp.src = path + imgarr[i];
		temparr[i] = temp;
	}
	return temparr;
}

function Imgallery_genGalleryStr (thumbnailPath, imgarr) {
	strGalleryTemp = "";
	for (i = 0; i < imgarr.length; i++) {
		if (strGalleryTemp != "")
			strGalleryTemp += '&nbsp;';
		strGalleryTemp += '<a href="javascript:;" onclick="' + this.name + '.Imgallery_changeImg(' + i + ')"><img src="' + thumbnailPath + imgarr[i] + '" style="border:none" /></a>';
	}
	return strGalleryTemp;
}

function Imgallery_genGalleryCapStr (thumbnailPath, imgarr) {
	strGalleryTemp = "";
	for (i = 0; i < imgarr.length; i++) {
		if (strGalleryTemp != "")
			strGalleryTemp += '&nbsp;';
		strGalleryTemp += '<a href="javascript:;" onclick="' + this.name + '.Imgallery_changeImgCap(' + i + ')"><img src="' + thumbnailPath + imgarr[i] + '" style="border:none" /></a>';
	}
	return strGalleryTemp;
}

function Imgallery_load_gallery () {
	this.ani_stop = true;
	this.splane.innerHTML = this.Imgallery_genGalleryStr (this.strImg + '/' + this.strGal + '/' + this.strThm + '/', this.imgarr);
	this.imgs = Imgallery_ldImg (this.strImg + '/' + this.strGal + '/' + this.strFul + '/',  this.imgarr);	
}

function Imgallery_load_gallery_caption () {
	this.ani_stop = true;
	this.splane.innerHTML = this.Imgallery_genGalleryCapStr (this.strImg + '/' + this.strGal + '/' + this.strThm + '/', this.imgarr);
	this.imgs = Imgallery_ldImg (this.strImg + '/' + this.strGal + '/' + this.strFul + '/',  this.imgarr);	
}

function Imgallery_changeImgCap (capIndex) {
	this.captionArea.innerHTML = this.captions[capIndex];
	this.Imgallery_changeImg (capIndex);
}

function Imgallery_changeImg (imgIndex) {
	this.displayArea.src = this.strImg + '/' + this.strGal + '/' + this.strFul + '/' + this.imgarr[imgIndex];
	this.endpoint.focus();
}

function Imgallery_frame () {
	this.animator.innerHTML = this.animation [this.current % this.animation.length];
	this.current++;
	if (this.Imgallery_check_progress(this.thumbs) == this.thumbs.length)
		setTimeout(this.name + ".Imgallery_load_gallery()", 0);
	else 
		setTimeout (this.name + ".Imgallery_frame()", this.interval);	
}

function Imgallery_frame_cap () {
	this.animator.innerHTML = this.animation [this.current % this.animation.length];
	this.current++;
	if (this.Imgallery_check_progress(this.thumbs) == this.thumbs.length)
		setTimeout(this.name + ".Imgallery_load_gallery_caption()", 0);
	else 
		setTimeout (this.name + ".Imgallery_frame_cap()", this.interval);	
}

function Imgallery_check_progress (imgArray) {
	j = 0;
	while (j < imgArray.length && imgArray[j].complete)
		j++;
	this.progress.innerHTML = (Math.floor(((j + 1)/ (imgArray.length + 1)) * 100)) +'%';
	return j;
}