
/**
*Shows current letter
*/
function currentLetter()
{
    if (!document.getElementById("currLetter")) { 
        return false;		
    }
	var currLetterDiv = document.getElementById("currLetter");
	var gallery = document.getElementById("letterGallery");
	var currentLetter = gallery.firstChild;
	currLetterDiv.innerHTML = currentLetter.innerHTML;
}
/**
*Shows chosen letter
*/
function showLetter(theLetter) {
    if (!document.getElementById("currLetter")) { 
        return false;		
    }
	
    var currLetter = document.getElementById("currLetter");
    var aLetter=document.getElementById(theLetter);
	
	//Swaps inner HTML of chosen letter with current letter
	currLetter.innerHTML=aLetter.innerHTML;
	return false;
}
/**
*Finds selected letter in the document
*/
function jump(menu)
{
ref=menu.choice.options[menu.choice.selectedIndex].value;
//if letterGallery(All Letters), show all letters
if (ref == "letterGallery")
{
showLetter("letterGallery");
}
else
{
//Loop through divs
	var letters = document.getElementById("letterGallery");
    var divs = letters.getElementsByTagName("div");
for (var i=0; i<divs.length; i++)
{
	//Finds div that has the same id as the chosen letter
	if (divs[i].id == ref)
	{	
		//Calls showLetter function
		showLetter(divs[i].id);	
	}
	
}
}
}

/**
 * Binds the jump function as the onclick event for "goButton"
 */
function bindJump(){
	

	if (!document.getElementById("goButton")) {
	return false;
	}
	var goButton = document.getElementById("goButton");
	goButton.onclick = function(){
		jump(this.form);
	};
}

/** 
 * Checks that the required methods, getElementById and
 * getElementsByTagName, are available.
 * 
 * Returns true if the methods are available, false if they aren't.
 */ 
function detectMethods() {
	if (!document.getElementById) {
        return false;
    }
    if (!document.getElementsByTagName) {
        return false;
    }
	return true;
}

/** 
 * Performs method detection, then binds the form 
 * validation event handler and loads the email address
 * cookie, if there is one.
 */ 
function bindCommonEventHandlers() {
    if (!detectMethods()) {
		return false;
	}

	bindJump();
	currentLetter();
	
	
}

/**
 * Binds function bindEventHandlers to window's onload event:
 * when browser finishes loading the page, it will 
 * call bindEventHandlers
 */    

window.onload = bindCommonEventHandlers;
