//This file contains JavaScript functionality related to photo pop-up functionality of http://www.projecttree.com
//This code maybe reused and modified so long as this note remains here
//Copyright 2003-2004 Mike Radin

var newphoto = null;
var newphotoid = null
var newphotobit = null;
var photowindow = null;
var phototimer = null;
var imgroot = "./img/photo/";

function togglephoto(target, name, window, dir){ // this used to be called from the click on an image in photo.html to bring up that image and all subsequent image links in a popup
	if(phototimer != null){ return; }
	if(target != null){
		var photodiv = document.getElementById('photo' + target);
		newphotoid = target;
	}
	//this wont work, needs support for directories
    /*if(photowindow){
		//update pic in window, not in div, call get focus on it
		if(name == null){
			var photo = document.getElementById('img' + target);
			var exp = new RegExp("([a-z0-9_-]*\.jpg)$");
			var result = exp.exec(photo.src);
			name = result[0];
		}
		photowindow.close();
		photowindow = self.open('pic.html?pic=' + imgroot + name, 'photo', 'width=500,height=375,status=no,scrollbars=no,resizable=no,screenX=30,screenY=30,left=30,top=30');
		//photowindow.location.replace("pic.html?pic=" + name); //above 2 lines replace this because otherwise we dont know if the user closed the pic window or we did
		photowindow.focus();
	}else if(window == 1){
		//open external photo window, save reference, call get focus on it
		var photo = document.getElementById('img' + target);
		var exp = new RegExp("([a-z0-9_-]*\.jpg)$");
		var result = exp.exec(photo.src);
		var picsrc = result[0];
		photowindow = self.open('pic.html?pic=' + imgroot + picsrc, 'photo', 'width=500,height=375,status=no,scrollbars=no,resizable=no,screenX=30,screenY=30,left=30,top=30');
		var photodiv = document.getElementById('photo' + target);
		photodiv.style.display = "none";
		photowindow.focus();
	}else{*/
		var currentphoto = document.getElementById('img' + target);
		if(currentphoto.src == ""){
			currentphoto.src = ".\/img\/photo\/" + dir + "\/" + name;
			//currentphoto.onclick = "togglephoto(" + target + ", '" + name + "', 1, '" + dir + "')";
			phototimer = setInterval("showpic(0," + target + ")", 100);
			newphotobit = 0;
		}else{
			newphoto = new Image();
			newphoto.src = ".\/img\/photo\/" + dir + "\/" + name;
			phototimer = setInterval("showpic(1," + target + ")", 100);
			newphotobit = 1;
		}
	//}
	return;
}
function showpic(loadnext, target){
	var currentphoto = document.getElementById('img' + target);
	var photodiv = document.getElementById('photo' + target);
	var photosec = document.getElementById('section_content' + target);
	if(loadnext == 1 && newphoto.complete){
		clearInterval(phototimer);
		phototimer = null;
		document.getElementById('img' + target).src = newphoto.src;
		photodiv.style.display = "";
		currentphoto.style.visibility = "visible";
		self.scrollTo(0,photosec.offsetTop);
	}else if(loadnext == 0 && document.getElementById('img' + target).complete){
		clearInterval(phototimer);
		phototimer = null;
		photodiv.style.display = "";
		currentphoto.style.visibility = "visible";
		self.scrollTo(0, photosec.offsetTop);
	}
	return;
}
