// JavaScript Document

//create a Slideshow if there are multiple images on the page

//get the slideshow container div
var slideshowContainer = document.getElementById("projectImages");

if (slideshowContainer && slideshowContainer.hasChildNodes()){
	//get the divs holding the images, captions and image thumbails
	var slideshowImageDivs = slideshowContainer.childNodes;
	
	//loop through the slideshow divs to create an array of objects representing each image
	var slides_arr = [];
	//declare variables to be filled for each slide
	var slide;
	var slideChildren;
	var slideChildNode;
	var slideImage;
	var slideCaption;
	var slideThumbnail;
	
	for (var s in slideshowImageDivs){
		slide = slideshowImageDivs[s];
		if (slide.nodeType==1 && slide.hasChildNodes()){
			slideChildren = slide.childNodes;
			slideImage = "";
			slideCaption = "";
			slideThumbnail = "";
			for (var sc in slideChildren){
				slideChildNode = slideChildren[sc];
				if (slideChildNode.nodeType== 1){
					if (slideChildren[sc].getAttribute("id") == "projectImage"){
						slideImage = slideChildren[sc].getElementsByTagName("img")[0].src;
					}
					if (slideChildren[sc].getAttribute("id") == "projectImageCaption"){
						slideCaption = slideChildren[sc].firstChild.nodeValue;
					}
					if (slideChildren[sc].getAttribute("id") == "projectImageThumbnail"){
						slideThumbnail = slideChildren[sc].getElementsByTagName("img")[0].src;
					}
				}
			}
			slides_arr.push({
							src: slideImage,
							caption: slideCaption,
							thumbnail:slideThumbnail
							});
		
		}
	}
	
	if (slides_arr.length > 1){
		showSlideshow("projectImages", 542, 620, slides_arr);
	}
}
