// ------------------------------------------------------------------------------------------------------------
//	writeGalleryNavAndContact
// ------------------------------------------------------------------------------------------------------------
function writeGalleryNavAndContact()
{
	/* writeGalleryNavAndContact() writes an unordered list of links in the form:
			
		<ul id="gallery_list">
			<li><a href="javascript:showFoto(0, 0)">name of first gallery	</a></li>
			<li><a href="javascript:showFoto(1, 0)">name of second gallery	</a></li>
			<li><a href="javascript:showFoto(2, 0)" id="currentGallery">name of third gallery	</a></li> // <- this is the current gallery
			<li><a href="javascript:showFoto(3, 0)">name of fourth gallery	</a></li>
			<li><a href="javascript:showContactInfo()">Contact	</a></li>
		</ul>
	*/



	var galleryNavAndContactString = '<ul id="gallery_list">'
	
	galleryNavAndContactString += galleryNavListItems()
	galleryNavAndContactString += hasBio() ? bioStringForGalleryNav() : ""
	galleryNavAndContactString += contactStringForGalleryNav()

	galleryNavAndContactString += '</ul>'

	document.write(galleryNavAndContactString)
}

// ------------------------------------------------------------------------------------------------------------
//	galleryNavListItems
// ------------------------------------------------------------------------------------------------------------
function galleryNavListItems(includeContact)
{
	/* galleryNavString() returns a string in the form:
				
			<li><a href="javascript:showFoto(0, 0)">name of first gallery	</a></li>
			<li><a href="javascript:showFoto(1, 0)">name of second gallery	</a></li>
			<li><a href="javascript:showFoto(2, 0)" id="currentGallery">name of third gallery	</a></li> // <- this is the current gallery
			<li><a href="javascript:showFoto(3, 0)">name of fourth gallery	</a></li>
	*/
	
	// the galleries nav
	
	var galleryNavListItems = "";
	
	var galleryCount = document.toc.galleries.length
	for (var g = 0; g < galleryCount; g++) 
	{
		var linkText = '<span>' + document.toc.galleries[g].name + '</span>'
		
		var liOpenTag = '<li>';
		
		if (g == galleryCount - 1)
		{
			liOpenTag = '<li class="last">'
		}
		
		var actionText = 'javascript:showFoto(' + g + ', 0)'
		if (g == document.galleryIndex)
		{
			linkText = liOpenTag + '<a href="' + actionText + '" id="currentGallery">' + linkText + '</a></li>'
		}
		else
		{
			
			linkText = liOpenTag + '<a href="' + actionText + '">' + linkText + '</a></li>'
		}
		
		galleryNavListItems += linkText
	}

	return galleryNavListItems
}

// ------------------------------------------------------------------------------------------------------------
//	contactStringForGalleryNav
// ------------------------------------------------------------------------------------------------------------
function contactStringForGalleryNav()
{
	// Contact info is a "pseudo gallery" with index = -1
	if (document.galleryIndex == -1)
	{
		return '<li class="contactItem"><a id="currentGallery" href="javascript:showContactInfo()">Contact</a></li>'
	}
	else
	{
		return '<li class="contactItem"><a href="javascript:showContactInfo()">Contact</a></li>'
	}
}

// ------------------------------------------------------------------------------------------------------------
//	bioStringForGalleryNav
// ------------------------------------------------------------------------------------------------------------
function bioStringForGalleryNav()
{
	// BIo is a "pseudo gallery" with index = -2
	if (document.galleryIndex == -2)
	{
		return '<li><a id="currentGallery" href="javascript:showBio()">' + document.siteDetails.bioTitle + '</a></li>'
	}
	else
	{
		return '<li><a href="javascript:showBio()">' + document.siteDetails.bioTitle + '</a></li>'
	}
}


// ------------------------------------------------------------------------------------------------------------
//	showContactInfo
// ------------------------------------------------------------------------------------------------------------
function showContactInfo()
{
	// Contact info is a "pseudo gallery" with index = -1.

	if (document.galleryIndex != -1)
	{
		var baseURL 	= document.URL.split("?")[0]
		var newURL 		= baseURL + "?" + String(-1 * 1000)
		
		top.location.href = newURL
	}
}


// ------------------------------------------------------------------------------------------------------------
//	fotoLoaded
// ------------------------------------------------------------------------------------------------------------
function fotoLoaded(inElementId)
{	
	if (document.getElementById)
	{
		var theElement = document.getElementById(inElementId)
		if (theElement)
		{
			if (theElement.src != "fotoslug.png")
			{
				theElement.style.opacity = 0;
				
				var f = new Fader(theElement, null, 750);
				f.fadeIn();
			
				document.f = f;
			}
			else
			{
				setOpacity(theElement, 0);
			}
		}
	}
	preloadNextFoto()
}

// ------------------------------------------------------------------------------------------------------------
//	preloadNextFoto
// ------------------------------------------------------------------------------------------------------------
function preloadNextFoto()
{
	if (document.galleryIndex >= 0)
	{
		var fotoCount = document.toc.galleries[document.galleryIndex].entries.length
		if (fotoCount > 0)
		{
			var nextImage = new Image
			nextImage.src=document.toc.galleries[document.galleryIndex].entries[(document.fotoIndex + 1) % fotoCount].fotopath
		}
	}
}

// ------------------------------------------------------------------------------------------------------------
//	handleFotoClick
// ------------------------------------------------------------------------------------------------------------
function handleFotoClick(inEvent)
{
	if (document.galleryIndex >= 0)
	{
		var theEvent	= inEvent ? inEvent:event	
		var element		= theEvent.target ? theEvent.target:theEvent.srcElement
		
		var clickX = 0
		if (inEvent.layerX)
		{
			clickX = inEvent.layerX 
		}
		else if (inEvent.offsetX)
		{
			clickX = inEvent.offsetX 
		}
		inEvent.cancelBubble = true

		if (element.clientWidth/2 - clickX > 0)
		{
			showPreviousFoto()
		}
		else
		{
			showNextFoto()
		}
	}
}


