var selectedPerson = false;

/**
 * Constructor for creating a person "object" for use on the About Us page
 * @param String nick Nickname for this person, used in IDs etc so make it unique. Also used for in-linking anchors
 * @param String name The full name of the person
 * @param String img HTML reference to the image to use for this person
 * @param String position The occupational position of the person
 * @param String about Full text to display for this person
 * @param String email Email address for this person
**/
function person(nick, name, img, position, about, email) {
    this.nick     = nick;
    this.name     = name;
    this.img      = img;
    this.position = position;
    this.about    = about;
    this.email    = email;
}

/**
 * Retrieve the index in an array of people which references the person who's nickname is passed in.
 * @param Array people Array of people objects
 * @param String nick The nickname of the person we're looking for
 * @return Int index for the person, or FALSE if not matche
**/
function getPersonId(people, nick) {
    for (p = 0; p < people.length; p++) {
        if (people[p].nick == nick) {
            return p;
        }
    }
    return false;
}

/**
 * Set all borders on the images of people as if they weren't enabled.
**/
function unshowPeople(people) {
    for (p = 0; p < people.length; p++) {
        $('#' + people[p].nick + 'Img').css({
            borderColor:'#7E7E7E'
        });
    }
}

/**
 * Handles everything involved in "showing" a person's details
 * @param Array people The array of possible people
 * @param String nick The nickname of the person to display
**/
function showPerson(people, nick) {
	selectedPerson = nick;
	unshowPeople(people);
	id = getPersonId(people, nick);
	$('#personName').html(people[id].name);
	$('#personPosition').html(people[id].position);
	$('#personAbout').html(people[id].about);
	$('#personEmail').html('<a href="mailto:' + people[id].email + '" class="contact">Contact ' + people[id].name + '</a>');
	$(nick + 'Img').css({borderColor:'#880101'});

}

/**
 * Highlight a person's image via their border.
 * @param String nick The nickname (also the 'id') of the person to highlight
**/
function highlightPerson(nick) {
    $('#' + nick + 'Img').css({
        borderColor:'#880101'
    });
}

/**
 * un-Highlight a person's border
 * @param String nick The nickname (also the 'id') of the person to highlight
**/
function unhighlightPerson(nick) {
    if (nick != selectedPerson) {
        $('#' + nick + 'Img').css({
            borderColor:'#7E7E7E'
        });
    }
}

/**
 * Wraps calls to writing the thumbnail for each person, to create the list of clickable items for showing each one.
 * @param Array people Array containing all the people objects
**/
function listPeople(people) {
    for (p = 0; p < people.length; p++) {
        writePersonThumb(people[p]);
    }
}

/**
 * Writes and individual person's thumbnail into a list ready for clicking.
 * @param PersonObject person The object for this person
**/
function writePersonThumb(person) {
    $('.wildline-team').append('<li id="' + person.nick + '"><a href="javascript:showPerson(people, \'' + person.nick + '\');" onmouseover="javascript:highlightPerson(\'' + person.nick + '\');" onmouseout="javascript:unhighlightPerson(\'' + person.nick + '\');"><img src="' + person.img + '" alt="' + person.name + '" id="' + person.nick + 'Img"/></a></li>');
}
