
//***************************************************
//popup_close
//
//Makes the popup div hidden
//***************************************************
function popup_close(){

	var divImg = document.getElementById('divImg');
	
	if (divImg.style.display == "block"){
		divImg.style.display = "none";
	}
}

//***************************************************
//popup_setup
//
//Alters the style properties of the img div to
//be specific to the image that is trying to be
//displayed
//***************************************************
function popup_show(image){
	
	var divImg = document.getElementById('divImg');
	var mainImg = document.mainImg;
	var mainHeight = 0;
	var mainWidth = 0;

	if (document.innerHeight){
		mainHeight = document.innerHeight;
		mainWidth = document.innerWidth;
	}else if (document.body.clientHeight){
		mainHeight = document.body.clientHeight;
		mainWidth = document.body.clientWidth;
	}

	mainImg.src = image.src;

	popup_previous_next(image);
	
	divImg.style.background = document.bgColor;
	
	//netscape compliant
	if(typeof (window.pageXOffset) == "number"){
		divImg.style.left = (Math.round(mainWidth / 2) - Math.round(image.width / 2)) + window.pageXOffset + "px";
		divImg.style.top = (Math.round(mainHeight / 2) - Math.round(image.height / 2)) + window.pageYOffset + "px";
		
	//DOM compliant
	}else if (document.body){
		divImg.style.left = (Math.round(mainWidth / 2) - Math.round(image.width / 2)) +  document.body.scrollLeft + "px";
		divImg.style.top = (Math.round(mainHeight / 2) - Math.round(image.height / 2)) + document.body.scrollTop + "px";
		
	//IE6 compliant
	}else if (document.documentElement){
		divImg.style.left = (Math.round(mainWidth / 2) - Math.round(image.width / 2)) + document.documentElement.scrollLeft + "px";
		divImg.style.top = (Math.round(mainHeight / 2) - Math.round(image.height / 2)) + document.documentElement.scrollTop + "px";
	}
	
	divImg.style.width = image.width;
	divImg.style.height = image.height+20;
	divImg.style.textAlign = "center";
	divImg.style.display = "block";
}

//***************************************************
//popup_previous_nexy
//
//Sets the location that the 'Previous' and 'Next'
//links should point to, as well as making them
//inactive if when there is no previous or next image
//***************************************************
function popup_previous_next(image){

	var imgSrc = image.src;
	var pictureNumber = parseInt(image.src.charAt(image.src.lastIndexOf('.') - 1));

	if (pictureNumber == 1){
		document.getElementById("previous").style.color = "#666666";
		
		document.getElementById("next").style.color = "#000000";
		document.getElementById("next").onclick = function(){
			popup_close();
			popup_show(img2);
		};
	}else if (pictureNumber == 2){
		document.getElementById("previous").style.color = "#000000";
		document.getElementById("previous").onclick = function(){
			popup_close();
			popup_show(img1);	
		};
		
		document.getElementById("next").style.color = "#000000";
		document.getElementById("next").onclick = function(){
			popup_close();
			popup_show(img3);
		};
	}else if (pictureNumber == 3){
		document.getElementById("previous").style.color = "#000000";
		document.getElementById("previous").onclick = function(){
			popup_close();
			popup_show(img2);
		};
		
		document.getElementById("next").style.color = "#666666";
	}
}