

var STUDENTS = 	"students";
var EMPLOYERS =	"employers";
var ALUMNI =	"alumni";
var FACULTY =	"faculty";
var CONTED =	"conted";
var PARENTS =	"parents";


var LEVEL_ZERO = 1;
var LEVEL_ONE = 2;
var LEVEL_TWO = 3;
var LEVEL_THREE = 4;
var LEVEL_FOUR = 5;




/******************************* MENU ITEMS ********************************/
var menuItems = new Array(


/* STUDENTS */

	[STUDENTS,	LEVEL_ZERO,	"Students",				"student.html"],
//	[STUDENTS,	LEVEL_ONE, 	"Our Services",			"Students/OurServices/index.html"],
	[STUDENTS,	LEVEL_ONE,	"Students",				"student.html"],
	[STUDENTS,  LEVEL_ONE,	"Employers",			"Employers/index.html"],
	[STUDENTS,	LEVEL_ONE,	"Alumni",				"Alumni/index.html"],
	[STUDENTS,	LEVEL_ONE,	"Faculty",				"Faculty/index.html"],
	[STUDENTS,	LEVEL_ONE,	"Families",				"Parents/index.html"],
	
/* EMPLOYERS */

	[EMPLOYERS,    LEVEL_ZERO,	"Employers",				"Employers/index.html"],

/* ALUMNI */

	[ALUMNI,	LEVEL_ZERO,	"Alumni",				"Alumni/index.html"],
	
/* FACULTY */

	[FACULTY,	LEVEL_ZERO,	"Faculty",				"Faculty/index.html"],
	
/* PARENTS */

	[PARENTS,	LEVEL_ZERO,	"Parents",				"Parents/index.html"],

	



/* END */
	[-1,		-1,		"END",					"END"]
);

/****************************** END MENU ITEMS ******************************/




/******************************* MENU ITEM EZ FUNCTIONS ********************************/

Array.prototype.getSide = function(){
	return this[0];
}
Array.prototype.getLevel = function(){
	return this[1];
}
Array.prototype.getTitle = function(){
	return this[2];
}
Array.prototype.getPath = function(){
	return this[3];
}

Array.prototype.setHilite = function(onoff){
	this[4] = onoff;
}
Array.prototype.getHilite = function(){
	return this[4];
}







/******************************** SIDE FUNCTIONS *****************************************/

/**
 * THIS SECTION OF CODE SETS AND SAVES THE CURRENT SIDE
 *
 */
 
 
 
 
 
 
var CURRENT_SIDE;
var CURRENTURL = document.location.toString();

function getCurrentSide(){
	return CURRENT_SIDE;
}


function setSide(){	
	//GET SIDE FROM QUERY STRING
	var side = convertStringSideToVariable(QueryString("ls"));
	
	//MAKE SURE THE PAGE & THE SIDE MATCH
	side = getSideFromSideAndPage(CURRENTURL, side);
	CURRENT_SIDE = side;
}




/**
 * Takes a string like "students" and returns the
 * matching variable (defined in SiteMap.js)
 * such as STUDENTS
 */
function convertStringSideToVariable(qsside){
	if(qsside){
		qsside = qsside.toLowerCase();
	}
	if(qsside == "students"){
		return STUDENTS;
	}else if(qsside == "employers"){
		return EMPLOYERS;
	}else if(qsside == "alumni"){
		return ALUMNI;
	}else if(qsside == "faculty"){
		return FACULTY;
//	}else if(qsside == "conted"){
//		return CONTED;
	}else if(qsside == "parents"){
		return PARENTS;
	}
	
	//NONE FOUND, DEFAULT TO STUDENTS
	return STUDENTS;
}




/**
 * Gets a side according to page.
 *  1. If side matches page, return side.
 *  2. If side doesn't match page, return a side that does.
 *  3. If nothing matches
 *
 */
function getSideFromSideAndPage(page, side){
	//CHECKS ONLY WITHIN THE GIVEN SIDE
	for(var i=0; i<menuItems.length; i++){
		//IF SIDES AND PATHS MATCH, RETURN THE GIVEN SIDE
		if( side == menuItems[i].getSide() &&  pageMatchesPath(page, menuItems[i].getPath())  )	//ERROR HAPPENS HERE
		{
			return side;
		}			
	}
	
	//NOT FOUND WITHIN THE GIVEN SIDE,
	//SO CHECK EVERYTHING & RETURN THE FIRST MATCH
	for(var i=0; i<menuItems.length; i++){
		//IF SIDES AND PATHS MATCH, RETURN THE GIVEN SIDE
		if( pageMatchesPath(page, menuItems[i].getPath())  )
		{
			return menuItems[i].getSide();
		}			
	}
	
	//PAGE ISN'T IN DATABASE, DEFAULT TO GIVEN SIDE (for pages not registered like "EventInfo.html")
	return side;
}



/**
 * Compares a page  (ie. http://www.ou.edu/career/students/index.html)
 *  with a path	    (ie. students/index.html)
 *  to see if it's the same thing.
 */
function pageMatchesPath(page, path){
	//FORCE TO LOWERCASE
	path = "career/"+path.toLowerCase();
	page = page.toLowerCase();

	//REMOVE QUERY STRING
	var endofpage = page;	
	if(endofpage.indexOf("?") != -1){
		endofpage = endofpage.substring(0, endofpage.lastIndexOf("?"));
	}
	
	
	/** REMOVE index.html FROM PAGE AND PATH IN CASE
	 *  SOMEONE TYPED IN http://www.ou.edu/career/Employers
	 *  'CAUSE THAT WON'T MATCH Employers/index.html
	 */
	if(endofpage.indexOf("index.html") != -1){
		endofpage = endofpage.substring(0, endofpage.lastIndexOf("index.html"));
	}
	if(path.indexOf("index.html") != -1){
		path = path.substring(0, path.lastIndexOf("index.html"));
	}
	
	//REMOVE BEGINNING OF PAGE
	endofpage = endofpage.substring(endofpage.length-path.length);
		
	//RETURN TRUE IF THEY MATCH
	if(endofpage == path){
		return true;
	}
	
	return false;
}

/**
 * Returns something like "ls=students"
 *  used by functions that dynamically create
 *  javascript links.
 */
function getSideQueryString(){
	return "ls="+getCurrentSide();
}

setSide();








/************* SOONER JOB SEARCH URL FUNCTIONS *************/
function getLoginUrlBySide(){
	if(getCurrentSide() == ALUMNI){
		return "https://www.myinterfase.com/ou/student/?ls=alumni";
	}else if(getCurrentSide() == FACULTY){
		return "https://www.myinterfase.com/ou/faculty/";
	}else if(getCurrentSide() == EMPLOYERS){
		return "https://www.myinterfase.com/ou/employer/";
	}
	
	return "https://www.myinterfase.com/ou/student/";
}