/* PhotoGalleryThumb Class */ 


function PhotoGalleryThumb(pictureContainerDiv,thumbContainerDiv) {
	this.photoContainerDivObject=document.getElementById(pictureContainerDiv);
	this.thumbContainerDivObject=document.getElementById(thumbContainerDiv);
	this.thumbnailFileNames=new Array();
	this.thumbnailPictureObjects= new Array();
	this.photoFileNames=new Array();
	this.currentPhoto=null;
	this.numberOfPhotos=0;
}

PhotoGalleryThumb.prototype.addPicture= function (thumbFileName,photoFileName) {
	this.thumbnailFileNames[this.numberOfPhotos]=thumbFileName;
	this.photoFileNames[this.numberOfPhotos]=photoFileName;
	this.numberOfPhotos++;
}

PhotoGalleryThumb.prototype.init= function () {
	this.initThumbs();
}

PhotoGalleryThumb.prototype.getCurrentPhoto= function () {
	return this.currentPhoto; 
}

PhotoGalleryThumb.prototype.initThumbs= function () {
	var photoGalleryThumbObj;
	photoGalleryThumbObj=this;
	DivUtils.clear(this.thumbContainerDivObject);
	for (var i=0;i<this.numberOfPhotos;i++) {
		this.thumbnailPictureObjects[i]=document.createElement("IMG");
		this.thumbnailPictureObjects[i].num=i+1;
		this.thumbnailPictureObjects[i].setAttribute("src",this.thumbnailFileNames[i]);
		this.thumbnailPictureObjects[i].style.cursor="pointer";
		this.thumbContainerDivObject.appendChild(this.thumbnailPictureObjects[i]);
		this.thumbnailPictureObjects[i].onclick=function () {
			photoGalleryThumbObj.displayPhoto(this.num);
		}
	}
}

PhotoGalleryThumb.prototype.displayPhoto=function(photoNum) {
	DivUtils.clear(this.photoContainerDivObject);
	var obj=this;
	var img=new Image();
	img.onload=function () {
		obj.resizePage(this.width);
		DivUtils.clear(obj.photoContainerDivObject);
		var photoElement=document.createElement("IMG");
		photoElement.setAttribute("src",this.src);
		obj.photoContainerDivObject.appendChild(photoElement);
		obj.resizePage(this.width);
	}
	img.src=this.photoFileNames[photoNum-1];
	this.currentPhoto=photoNum;
}

/* for this site specific methods */

PhotoGalleryThumb.prototype.resizePage=function(photoWidth) {
	this.photoContainerDivObject.style.width=photoWidth+26+"px";
	var contentNode=document.getElementById("content");
	contentNode.style.width=photoWidth+41+document.getElementById("leftpage").offsetWidth+"px";
}

PhotoGalleryThumb.prototype.centerOnPage=function() {
	DivUtils.centerVerically(document.getElementById("content"));
}

/**************************************************************************/

function PhotoGallerySet(forwardButtonId,backwardButtonId) {
	this.galleries=new Array();
	this.numOfGalleries=0;
	this.currentGallery=0;
	this.forwardButtonObj=document.getElementById(forwardButtonId);
	this.backwardButtonObj=document.getElementById(backwardButtonId);	
}

PhotoGallerySet.prototype.addGallery=function(galleryObj) {
	this.galleries[this.numOfGalleries]=galleryObj;
	this.numOfGalleries++;
}

PhotoGallerySet.prototype.init=function() {
	this.initGallerySetButtons(this.currentGallery);
}

PhotoGallerySet.prototype.initGallerySetButtons=function(currentGalleryNum) {
	var obj=this;
	this.galleries[this.currentGallery].init();
	if (currentGalleryNum!=0) {
		this.showBackwardButton();
		this.backwardButtonObj.onclick=function() {
			if (obj.galleries[currentGalleryNum].zoomPictureAreaVisible) {
				obj.setZoomPictureAreaVisible();
			} else {
				obj.setZoomPictureAreaInvisible();
			}
			obj.currentGallery--;
			obj.initGallerySetButtons(obj.currentGallery);
		}
	} else {
		this.hideBackwardButton();
	}
	
	if (currentGalleryNum+1==this.numOfGalleries) {
		this.hideForwardButton();
	} else {
		this.showForwardButton();
		this.forwardButtonObj.onclick=function() {
			if (obj.galleries[currentGalleryNum].zoomPictureAreaVisible) {
				obj.setZoomPictureAreaVisible();
			} else {
				obj.setZoomPictureAreaInvisible();
			}
			obj.currentGallery++;
			obj.initGallerySetButtons(obj.currentGallery);
		}
	}
}

/* for this site specific methods */

PhotoGallerySet.prototype.setZoomPictureAreaVisible=function() {
	for (var i=0; i < this.numOfGalleries; i++) {
		this.galleries[i].zoomPictureAreaVisible=true;
	}
}

PhotoGallerySet.prototype.setZoomPictureAreaInvisible=function() {
	for (var i=0; i < this.numOfGalleries; i++) {
		this.galleries[i].zoomPictureAreaVisible=false;
	}
}

PhotoGallerySet.prototype.hideForwardButton=function() {
	this.forwardButtonObj.style.display="none";
	this.backwardButtonObj.style.marginRight="0px";	
}

PhotoGallerySet.prototype.showForwardButton=function() {
	this.forwardButtonObj.style.display="block";
	this.backwardButtonObj.style.marginRight="13px";	
}

PhotoGallerySet.prototype.hideBackwardButton=function() {
	this.backwardButtonObj.style.display="none";	
}

PhotoGallerySet.prototype.showBackwardButton=function() {
	this.backwardButtonObj.style.display="block";	
}



/**********************************************************/

function displayAboutText(anyPhotoGalleryObject) {
	var rightPageContainerObj=document.getElementById("rightpagecontent");
	var aboutTextDivObj=document.getElementById("about");
	DivUtils.clear(rightPageContainerObj);
	rightPageContainerObj.appendChild(aboutTextDivObj.cloneNode(true));
	var insertedDiv=rightPageContainerObj.getElementsByTagName("DIV")[0];
	insertedDiv.style.display="block";
	anyPhotoGalleryObject.resizePage(insertedDiv.offsetWidth);
}