function appendGallery(galleryID,thumbPath,fullPath,description,photoCredit) {
	var thumbDiv = document.createElement("div");
	thumbDiv.className = "thumbDiv";
	
	var thumbImg = document.createElement("img");
	thumbImg.setAttribute("src", "gifs/gallery/" + thumbPath);
	thumbImg.setAttribute("border", "0");
	
	var thumbLink = document.createElement("a");
	thumbLink.onclick = function() { showThumb(fullPath,description,photoCredit) };
	thumbLink.setAttribute("href","javascript:void(0);");
	
	thumbLink.appendChild(thumbImg);
	thumbDiv.appendChild(thumbLink);
	$("galleryThumbs").appendChild(thumbDiv);
}

function closeGallery() {
	$("galleryDisplay").style.display = "none";
	clearText($("galleryDisplay"));
}

function dspGallery(request) {
	var getGallery = request.responseText;
	// alert(getGallery);
	var thumbObject = $("galleryThumbs");
	clearText(thumbObject);

	var XMLTableOutput = request.responseXML;
	var listThumbs = XMLTableOutput.documentElement.getElementsByTagName("gallerylist");
	var galleryID;
	var thumbPath;
	var fullPath;
	var description;
	var photoCredit;

	for (n = 0;  n < listThumbs.length; n++) {
		galleryID = listThumbs[n].getElementsByTagName("galleryid")[0].firstChild.nodeValue;
		thumbPath = listThumbs[n].getElementsByTagName("thumb")[0].firstChild.nodeValue;
		fullPath = listThumbs[n].getElementsByTagName("full")[0].firstChild.nodeValue;
		description = listThumbs[n].getElementsByTagName("desc")[0].firstChild.nodeValue;
		photoCredit = listThumbs[n].getElementsByTagName("credit")[0].firstChild.nodeValue;

		appendGallery(galleryID,thumbPath,fullPath,description,photoCredit);
	}
	
}

function getGallery() {
	var url = "ajax_gallery.cfm";
	var pars = "&timestamp=" + new Date().getTime();

	var myAjax = new Ajax.Request(
		url,
		{
			method: 'get',
			parameters: pars,
			onComplete: dspGallery
		});
}

function editMailingList() {
	var listActionRes;
	
	for (i=0;i < document.forms.mListForm.listAction.length; i++) {
		if (document.forms.mListForm.listAction[i].checked) {
			listActionRes = document.forms.mListForm.listAction[i].value;
		}
	}

	var url = "ajax_mailingList.cfm";
	var pars = "emailAddie=" + escape(document.forms.mListForm.emailAddie.value) + "&listAction=" + escape(listActionRes) + "&timestamp=" + new Date().getTime();

	var myAjax = new Ajax.Request(
		url,
		{
			method: 'post',
			postBody: pars,
			onSuccess: postMailingList
		});
}

function postMailingList() {
	var postText = "Thank You!";
	var postDiv = $("mailingList");
	replaceText(postDiv, postText);
}

function refreshGallery() {
	closeGallery();
	getGallery();	
}

function showMailingList() {
	Effect.Appear($("mailingList"));
}

function showThumb(fullPath,description,photoCredit) {
	clearText($("galleryDisplay"));
	
	var closeLink = document.createElement("a");
	closeLink.onclick = function() { closeGallery(); };
	closeLink.setAttribute("href","javascript:void(0);");
	closeLink.className = "closeLink";
	closeLink.appendChild(document.createTextNode("close"));
	
	var showPic = document.createElement("img");
	showPic.setAttribute("src", "gifs/gallery/" + fullPath);
	
	$("galleryDisplay").appendChild(closeLink);
	$("galleryDisplay").appendChild(document.createElement("br")); 
	$("galleryDisplay").appendChild(showPic); 
	$("galleryDisplay").style.display = "block";
	
	if (description.length > 3) {
		$("galleryDisplay").appendChild(document.createElement("br")); 
		var descDiv = document.createElement("div");
		descDiv.appendChild(document.createTextNode(description));
		$("galleryDisplay").appendChild(descDiv); 
	}

	if (photoCredit.length > 3) {
		$("galleryDisplay").appendChild(document.createElement("p")); 
		var descDiv = document.createElement("div");
		descDiv.className = "photoCredit";
		descDiv.appendChild(document.createTextNode("Photo courtesy of " + photoCredit));
		$("galleryDisplay").appendChild(descDiv); 
	}
	
	$("galleryDisplay").appendChild(document.createElement("br")); 
	
}




