// bros.js Created by Dan Roche, 4.30.06
// This code provides a simple pseudo-database for chapter brothers.
// The key is the addBrother function

var ximuBros = new Array();
var ximuNumber = 4910000;

// Brothers associated with the chapter but not initiated here (e.g. Derek)
var otherBros = new Array();

var facultyBros = new Array();
var honoraryBros = new Array();

// Holds the head of each clan
var clans = new Array();

// The pledge classes will be numbered (from zero) and put in this array.  Each
// entry in this array will simply be an array of brother objects
var pledgeClasses = new Array();

var classNames = new Array(
	"Charter Class", // 0
	"Alpha", // 1
	"Beta", // 2
	"Gamma", // 3
	"Delta", // 4
	"Epsilon", // 5
	"Zeta", // 6
	"Eta", // 7
	"Theta", // 8
	"Iota", // 9
	"Kappa", // 10
	"Lambda", // 11
	"Mu", // 12
	"Nu", // 13
	"Xi", // 14
	"Omicron", // 15
	"Pi", // 16
	"Rho", // 17
	"Sigma", // 18
	"Tau", // 19
	"Upsilon", // 20
	"Phi", // 21
	"Chi", // 22
	"Psi", // 23
	"Omega", // 24
	"Alpha;&Beta", // 25
	"Alpha;&Gamma", // 26
	"Alpha;&Delta", // 27
	"Spring2008", // 28
	"Alpha;&Epsilon", // 29
	"Alpha;&Zeta", // 30
	"Alpha;&Eta", // 31
	"Alpha;&Theta", // 32
	"Alpha;&Iota", // 33
	"Alpha;&Kappa", // 34
	"Alpha;&Lambda", // 35
	"Alpha;&Mu" // 36
);

for( var i = 1; i < classNames.length; ++i ) {
	classNames[i] = "&" + classNames[i] + ";";
}


// Get the class initiation date
function getClassInitDate( pclass ) {
	if( pclass == 0 ) return "March 19, 1994";
	var toRet;
	if( pclass % 2 == 0 ) toRet = "Spring ";
	else toRet = "Fall ";
	toRet = toRet.concat( 1994 + Math.floor(pclass/2) );
	return toRet;
}

var EXPELLED = -1;
var ALUMNI = 0;
var ACTIVE = 1;
var FACULTY = 2;
var RETFACULTY = 3;
var HONORARY = 4;

// Takes a brother object and returns the depth of that object in the family line
function broDepth( bro ) {
	var current;
	var toRet = 0;
	for( current = bro; current != null && ++toRet; current = current.big );
	return toRet-1;
}

// Creates a brother with the given first name, last name,
// membership number, pledge class (number), and big brother (number)
// Membership numbers for xi mu bros should just be entered as the last
// four digits.
// A big brother number of 0 means no big brother
// ALL BIG BROTHERS MUST BE ADDED BEFORE THEIR LITTLES
// the status values can be ACTIVE, ALUMNI, FACULTY, HONORARY, or EXPELLED
// default status is ALUMNI
function addBrother( first, last, numb, pclass, big, status ) {
	var newBro = new Object();
	newBro.first = first;
	newBro.last = last;
	newBro.numb = numb;
	newBro.pclass = pclass;
	newBro.littles = new Array();

	if( status == null ) newBro.status = 0;
	else newBro.status = status;

	if( pclass >= 0 && newBro.status < FACULTY ) addToClass( newBro, pclass );

	newBro.big = null;

	if( big > 0 && big < 10000 ) {
		ximuBros[big].littles.push(newBro);
		newBro.big = ximuBros[big];
	}
	if( big >= 10000 ) {
		for( x = 0; x < otherBros.length; ++x ) {
			if( otherBros[x].numb == big ) break;
		}
		newBro.big = otherBros[x];
		otherBros[x].littles.push(newBro);
	}	

	if( newBro.numb < 10000 ) { // if it's a xi mu-initiated bro
		ximuBros[newBro.numb] = newBro;
	}
	else {
		otherBros.push(newBro);
	}

	if( newBro.status == FACULTY || newBro.status == RETFACULTY ) facultyBros.push(newBro);
	else if( newBro.status == HONORARY ) honoraryBros.push(newBro);

	return newBro;
}

function addToClass( brother, classNum ) {
	if( pledgeClasses[classNum] == null ) pledgeClasses[classNum] = new Array();
	pledgeClasses[classNum].push( brother );
}

