var currentPicture = 1;
var totalPictures = 34;

function checkNumeric()
{
	var key = window.event.keyCode;
	theString = String.fromCharCode(key);
	if ( key > 47 && key < 58 ) return;
   	else
   	{
   		changeAlert("<b>'" + theString + "' is <i>NOT</i> a number. Please try again.</b>");
   		window.event.returnValue = null;
   	}
}

function getElement(id)
{
	return document.getElementById ? document.getElementById(id) : document.all ? document.all(id) : null;
}

function changeCounter(counterNumber)
{
	var anElement = getElement("theCounter");
	if (anElement && typeof anElement.innerHTML != 'undefined') 
	{
		anElement.innerHTML = "Engagement Photo #" + counterNumber + " of "+ totalPictures +".";
	}
}

function changeAlert(alertMessage)
{
	var anElement = getElement("anAlert");
	if (anElement && typeof anElement.innerHTML != 'undefined') 
	{
		anElement.innerHTML = alertMessage;
	}
}

function home()
{
	currentPicture = 1;
	document.EngagementPhotos.thePicture.src = "/images/EngagementPhotos/" + currentPicture + ".jpg";
	changeCounter(currentPicture);
	changeAlert("&nbsp;");
	document.EngagementPhotos.jumpTo.value = "";
}

function next()
{
	currentPicture++;
	if(currentPicture > totalPictures) currentPicture = 1;
	document.EngagementPhotos.thePicture.src = "/images/EngagementPhotos/" + currentPicture + ".jpg";
	changeCounter(currentPicture);
	changeAlert("&nbsp;");
	document.EngagementPhotos.jumpTo.value = "";
}

function previous()
{
	currentPicture--;
	if(currentPicture < 1) currentPicture = 34;
	document.EngagementPhotos.thePicture.src = "/images/EngagementPhotos/" + currentPicture + ".jpg";
	changeCounter(currentPicture);
	changeAlert("&nbsp;");
	document.EngagementPhotos.jumpTo.value = "";
}

function jumpToPicture()
{
	var imageNumber = document.EngagementPhotos.jumpTo.value;
	
	// Check to make sure the image is in the correct range.
	if ((imageNumber > totalPictures) || (imageNumber < 1))
	{
		// Easter egg time.
		if(imageNumber == 69)
		{
			easterEgg();
		}
		// Invalid Number!
		else
		{
			changeAlert("<b>Please enter a number between <i>1 and 34</i>.</b>");
			document.EngagementPhotos.jumpTo.value = "";
		}
	}
	else
	{
		document.EngagementPhotos.thePicture.src = "/images/EngagementPhotos/" + imageNumber + ".jpg";
		changeCounter(imageNumber);
		changeAlert("&nbsp;");
		document.EngagementPhotos.jumpTo.value = "";
	}
}

function easterEgg()
{
	var anElement = getElement("theCounter");
	if (anElement && typeof anElement.innerHTML != 'undefined')
	{
		anElement.innerHTML = "Engagement Photo #666 of 34.";
	}
	var anElement = getElement("anAlert");
	if (anElement && typeof anElement.innerHTML != 'undefined')
	{
		anElement.innerHTML = "<b>Follow the wolf!!!!</b>";
	}
	document.EngagementPhotos.thePicture.src = "/images/kingDiamond.jpg";
}