var path_to_photos = "http://www.coolidgephotography.com/photos/";

function swapPhoto(photo,section,link) {

// Reset all selected boxes
var myArray = document.getElementById("thumbnails").getElementsByTagName("a");
var i = 0;

		while(i < myArray.length)
			{
			myArray[i].className = "";
			i++;
			}

// Set selected box
if(link != "") {
	link.className = "selected";
	}

//alert(photo.images[0].src);
document.getElementById("largephoto").src = path_to_photos + section + "/" + photo;

//alert(document.getElementById("largephoto").src);
return false;

}





function moveThumbs(direction,section) {

	var myArray = document.getElementById("thumbnails").getElementsByTagName("div");
	var myLength = myArray.length;
	var i = 0;
	var currentOffset = myArray[0].style.top;
	//alert(myArray[0].innerHTML);
	var newOffset = 0;
	var boxSize = 88;
	var myHeight = Math.round(myLength/2) * boxSize;
	
	
	//alert(currentOffset);
	//alert(boxSize);
	
	
if(section != "") {
		
		
		
		
		var k = 0;
				while(k < myArray.length)
				{
					if(myArray[k].className == "section" && myArray[k] == document.getElementById(section)) {
						//alert(k);
						newOffset = 0 - (Math.round((k-1)/2) * boxSize);
					}
				k++;
				}
		

		}
	


else {
	
	newOffset = 440;
	
	if(!currentOffset || currentOffset == "") {currentOffset = "0px";}
	
	currentOffset = currentOffset.substring(0,currentOffset.length-2) - 0;
	
	//alert("Current offset 2: " + currentOffset);

	if(direction == "up") {
		newOffset = currentOffset + newOffset;
		if(newOffset > 0) {
			newOffset = 0;
			//alert("yes");
			}
		else {
			newOffset = newOffset;
			//alert("no");
			}
	}
	
	if(direction == "down") {
		newOffset = currentOffset - newOffset;
		}
	
	
	
}

//alert(currentOffset);

//alert("New offset: " + newOffset);
	if(currentOffset == 0 && direction == "up") {
		alert("You are at the top of the gallery.");
		return false;
	}	
	else if(Math.abs(newOffset) >= myHeight) {
		alert("You are at the bottom of the gallery.");
		return false;
		}
	/*
	else if(Math.abs(newOffset) >= myHeight) {
		alert("There are no more photos.");
		return false;
		}
	*/
	else {
		while(i < myLength)
			{
			myArray[i].style.top = newOffset + "px";
			i++;
			}
		}

return false;
			

}


function checkGallery() {
	

	//alert(window.outerHeight);
	
	
	//alert(window.location.search.substr(1));
	
	switch(window.location.search.substr(1)) {
		
		case "babies":
			moveThumbs('','babies'); return false;
		break;
		
		case "children":
			moveThumbs('','children'); return false;
		break;
		
		case "siblings":
			moveThumbs('','siblings'); return false;
		break;
		
		case "families":
			moveThumbs('','families'); return false;
		break;
		
	}
		
		
	
	//alert(window.location.hash);
	
}
