addLoadListener(initPopups);
addLoadListener(initPaging);

function initPopups(){
	
	if (document.getElementById) {
		
		//attach a click event to all of the thumbnails which will make the hyperlink appear as the large image
		if (document.getElementById("galleryThumbs")){
			
			Thumbnails = document.getElementById("galleryThumbs").getElementsByTagName("a");
			for (i=0;  i <= Thumbnails.length; i++){	
				attachEventListener(Thumbnails[i], "click", popUp, false);
			}			
		}		
	}
	
}


function initPaging(){
	
	if (document.getElementById) {
		
		// attached paging click events if paging is required
		if (document.getElementById("galleryNavigation")) {
		
		PagingTargets = document.getElementById("galleryNavigation").getElementsByTagName("a");
		for (i=0;  i <= PagingTargets.length; i++){	
			attachEventListener(PagingTargets[i], "click", pageNow, false);
			}
		}
		
	}
	
}

function popUp(event){
	stopDefaultAction(event);
	callingElement = getCallingElement(event,"a");
	callingImage = getCallingElement(event,"img");
	document.getElementById("largeImage").src = callingElement;
	document.getElementById("galleryCaption").innerHTML = callingImage.getAttribute("alt");
}

function pageNow(event){
	stopDefaultAction(event);
	callingElement = getCallingElement(event,"a");
	var offset = (((callingElement.innerHTML*10)-10));
	document.getElementById("offset").value = offset;
	document.getElementById("frmPaging").submit();
}

