// JavaScript Document
with((window.frames["mainCnt"])?window.frames["mainCnt"]:window){
	var phPointer;
	var photoObj;
}
function loadGallery(photosSrc, base, ctnerID){
	with((window.frames["mainCnt"])?window.frames["mainCnt"]:window){
		for(i in photosSrc){
			ctner = document.getElementById(ctnerID);
			var photo = document.createElement('IMG');
			var act = document.createElement('A');
			var frame = document.createElement('DIV');
			photo.setAttribute('src', base+'thumbs/'+photosSrc[i]);
			if(document.all)
				act.onclick = new Function("parent.enlarge(this);return false");
			else
				act.setAttribute('onClick', 'parent.enlarge(this);return false');
			act.setAttribute('href', base+photosSrc[i]);
			frame.setAttribute((document.all)?'className':'class', 'photo');
			act.innerHTML += "\n"; //vertical align in middle hack
			act.appendChild(photo);
			act.innerHTML += "\n";//vertical align in middle hack
			frame.appendChild(act);
			ctner.appendChild(frame);
		}
	}
}
function enlarge(srcPhoto){
	with((window.frames["mainCnt"])?window.frames["mainCnt"]:window){
		phPointer = srcPhoto;
		if(document.all){
			var bodyWidth = screen.availWidth;
			var bodyHeight = screen.availHeight-window.screenTop;
		}else{
			var bodyWidth = window.innerWidth;
			var bodyHeight = window.innerHeight;		
		}
		var photoBG = document.createElement("DIV");
		photoBG.setAttribute("id", "photoBG");
		photoBG.style.height = bodyHeight+"px";
		photoBG.style.width = bodyWidth+"px";
		var photoFrame = document.createElement("DIV");
		photoFrame.setAttribute("id", "photoFrame");
		photoFrame.style.height = bodyHeight+"px";
		photoFrame.style.width = bodyWidth+"px";
		var photoCon = document.createElement("DIV");
		photoCon.setAttribute("id", "photoCon");
		photoCon.style.top = document.body.scrollTop+"px";
		photoCon.style.marginTop = parseInt(document.body.clientHeight*0.15)+"px";
		photoCon.style.width = "35%";
		photoCon.style.height = "45%";
		var loading = document.createElement("IMG");
		loading.setAttribute("id", "photoLoading");
		loading.setAttribute("src", "image/loading.gif");
		loading.setAttribute("title", "Loading...(Click to close)");
		if(document.all)
			loading.onclick = closePhoto;
		else
			loading.setAttribute("onClick", "closePhoto();");
		var photo = document.createElement("IMG");
		photo.setAttribute("id", "photoInstn");
		photo.style.display = "none";
		var control = document.createElement("DIV");
		control.setAttribute("id", "photoControl");
		control.style.display = "none";
		control.innerHTML = "<a href='#' onclick='nextPhoto(-1);return false'>&lt;&lt;</a> | <a href='"+window.location+"' onclick='closePhoto();return false'>Close</a> | <a href='#' onclick='nextPhoto(1);return false'>&gt;&gt;</a>";
		photoCon.appendChild(loading);
		photoCon.appendChild(photo);
		photoBG.appendChild(photoCon);
		photoBG.appendChild(control);
		photoBG.appendChild(photoFrame);
		document.body.appendChild(photoBG);
	}
	loadPhoto();
}
function loadPhoto(){
	with((window.frames["mainCnt"])?window.frames["mainCnt"]:window){
		var photo = document.getElementById("photoInstn");
		photoObj = new Image();
		photoObj.onload = adjustPhoto;
		photoObj.src = phPointer.href
		photo.src = photoObj.src;
	}
}
function adjustPhoto(){
	with((window.frames["mainCnt"])?window.frames["mainCnt"]:window){
		var srcPhoto = document.getElementById("photoInstn");
		var phRatio = srcPhoto.width/srcPhoto.height;
		var scRatio = document.body.clientWidth/document.body.clientHeight;
		var loading = document.getElementById("photoLoading");
		var photoConO = document.getElementById("photoCon");
		var control = document.getElementById("photoControl");
		//if(phRatio > scRatio)
		//	srcPhoto.width = (srcPhoto.width>document.body.clientWidth*0.7)? document.body.clientWidth*0.7:srcPhoto.width;
		//else
		//	srcPhoto.height = (srcPhoto.height>document.body.clientHeight*0.7)? document.body.clientHeight*0.7:srcPhoto.height;
		photoConO.style.width = parseInt(photoObj.width + 70)+"px";
		photoConO.style.height = parseInt(photoObj.height + 40)+"px";
		control.style.width = photoConO.style.width;
		loading.style.display = "none";
		srcPhoto.style.display = "block";
		control.style.display = "block";
	}
}
function nextPhoto(step){
	with((window.frames["mainCnt"])?window.frames["mainCnt"]:window){
		document.getElementById("photoLoading").style.display = "block";
		document.getElementById("photoInstn").style.display = "none";
		document.getElementById("photoControl").style.display = "none";
		if(step>0){
			do{
				if(phPointer.parentNode.nextSibling.tagName=="DIV")
					phPointer = phPointer.parentNode.nextSibling.childNodes[0];
				else {
					var tmp = phPointer.parentNode.parentNode.getElementsByTagName("div");
					phPointer = tmp[0].childNodes[0];
				}
			}while(--step>0);
		}else if(step < 0){
			do{
				if(phPointer.parentNode.previousSibling.tagName=="DIV")
					phPointer = phPointer.parentNode.previousSibling.childNodes[0];
				else {
					var tmp = phPointer.parentNode.parentNode.getElementsByTagName("div");
					phPointer = tmp[tmp.length-1].childNodes[0];
				}
			}while(++step<0);
		}
	}
	loadPhoto();
}
function closePhoto(){
	with((window.frames["mainCnt"])?window.frames["mainCnt"]:window){
		document.body.removeChild(document.getElementById("photoBG"));
	}
}
