//represents the current main environment
//When changing these, they must correspond to the headerScrollingTextDiv's in the topframe.htm
//please number the sub-subsections as 100 times their parent environment ID
var TARGET_HOME = 0;
var TARGET_STEP_UP = 1;
var TARGET_STEP_UP_1 = 101;   //ID for the StepUp sub-submenu
var TARGET_CREDIT_COURSES = 2;
var TARGET_SPEAK_TESTING = 3;
var TARGET_ENGLISH_LANGUAGE_LEARNING = 4;
var TARGET_ESL_STAFF = 5;
var TARGET_GUIDE_FOR_FACULTY = 6;
var TARGET_GUIDE_FOR_FACULTY_1 = 601;   //ID for the Guide sub-submenu 1
var TARGET_GUIDE_FOR_FACULTY_2 = 602;   //ID for the Guide sub-submenu 2
var TARGET_GUIDE_FOR_FACULTY_3 = 603;   //ID for the Guide sub-submenu 3
var TARGET_SPECIAL_PROGRAMS = 7;
var TARGET_ORIENTATION_INFO = 8;
var TARGET_ADMISSIONS = 9;

/*indicates the user's current main section
**do not reference this variable directly, instead use the setCurrentMain(), getCurrentMain() functions*/
var CURRENT_MAIN = 0;

// Scroll delays in miliseconds for the image bar, text bar
var TEXT_DELAY = 3500;
var PIC_DELAY = 2000;

// This variable will track the image bar title as seen on the home page.
// Careful when setting or testing this variable, always use 'top.topframe.' to index it (there will be a unique copy for each frame).
var IMAGE_BAR_ENABLED = false;

// menu constants
var leftDirection = 0;
var rightDirection = 1;
var speedIncrement = 9;
var openMenuLocation = 0;
var collapsedMenuLocation = -117;  //must be a multiple of speedIncrement
var openSubmenuLocation = 14;
var collapsedSubmenuLocation = 140; //should be offscreen of the frameset
var currentMenuItem;

//used to detect browser capabilities
var usesLayers
var usesDocAll
var usesDOM

(document.layers) ? usesLayers=true : usesLayers=false;
(document.all) ? usesDocAll = true: usesDocAll = false;
(document.getElementById) ? usesDOM = true : usesDOM = false;

// this will resolve a javascript command using the browser's detected capabilities
function resolveJavaScript(frameName, elementName, command) {

	if(usesLayers) {
		eval(frameName+".document.layers['"+elementName+"']."+command);
	} else if(usesDocAll) {
		eval(frameName+".document.all['"+elementName+"']."+command);
	} else if(usesDOM) {
		eval(frameName+".document.getElementById('"+elementName+"')."+command);
	}

}

/************************
 * Navigation functions *
 ************************/

 function checkQueryString() {
	if(window.parent.frames.length == 0) {
		window.location.replace('../home/frameset.htm'+'?forwardURL='+window.location.pathname);
	}
 }

 function checkForwardURL() {
	var forwardURL = "../home/home.htm";
	var queryString = window.top.location.search;
	//alert(queryString);
	if(queryString != null && queryString != "") {
		var paramName = '?forwardURL=';
		var loc = queryString.indexOf(paramName) + paramName.length;
		if(loc>-1) {
			forwardURL = queryString.substring(loc);
			//alert(forwardURL);
		}
	}
	return forwardURL;
 }
 
 function doesAForwardURLExist() {
 	var queryString = window.top.location.search;
	//alert(queryString);
	if(queryString != null && queryString != "") {
		var paramName = '?forwardURL=';
		var loc = queryString.indexOf(paramName) + paramName.length;
		return (loc>-1);
	} else {
		return false;
	}
 }

 function replaceCenterframe(forwardURL) {
	window.top.mainframe.centerframe.location.replace(forwardURL);
 }

 function checkFrameLength() {
	if(window.parent.frames.length == 0) {
		window.location.replace('index.htm');
	}
 }

/*this function should only be called on the top.mainframe.leftframe*/
function setCurrentMain( screenID) {
	//alert("setting CURRENT_MAIN to "+screenID);
	top.mainframe.leftframe.CURRENT_MAIN = screenID;
}

/*this function should only be called on the top.mainframe.leftframe*/
function getCurrentMain() {
	return top.mainframe.leftframe.CURRENT_MAIN;
}

//Called by the top.mainframe.centerframe to see if the environment is correct
//This is used to fix the browser back button problem
function checkEnvironment(targetEnvironment) {
	var existingEnvironment = parseInt(getCurrentMain());  
	//alert("existingEnvironment ="+existingEnvironment+", targetEnvironment ="+targetEnvironment);
	//necessary for sub-subsections
	if((existingEnvironment != targetEnvironment) && (targetIsASubSubSection(targetEnvironment) || currentlyInsideASubSubSection())) { 
		//alert('in first if');
		top.mainframe.leftframe.doNavigationReturn();

	}

	if(existingEnvironment != targetEnvironment) {
		//we are not in the correct environment, so go there
		//alert('in second if');
		top.mainframe.leftframe.doNavigationLink(targetEnvironment);
	}
}

//used for only switching the environment
function doNavigationLink(mainTargetID) {
	doNavigationLink(mainTargetID,null);
	return false;  //avoid calling the href attribute
}
//used for switching the environment and the content frame
function doNavigationLink(mainTargetID, subTargetLink) {
	//alert('doNavigationLink');

	var mainMenuObj = top.mainframe.leftframe.document.getElementById('mainNavigation');
	var subMenuObj;
	var mainMenuColoredBlockObj;
	var newClass;
	var defaultFlag = false;
	var existingEnvironment = getCurrentMain();

	//alert('existingEnvironment='+existingEnvironment+', mainTargetID='+mainTargetID);


	//we are in a subsection and are going to a different subsection (not including a sub-sub section)
	//if the subTargetLink is null, then we are here only to change the environment
	if((existingEnvironment != TARGET_HOME) && (existingEnvironment != mainTargetID) && !targetIsASubSubSection(mainTargetID) && !currentlyInsideASubSubSection()) {
		//alert('we are in a subsection and are going to a different subsection');
		top.mainframe.leftframe.doNavigationReturn();

	}


	//These are coordinated with the div id's in leftframe.htm
	if(mainTargetID == TARGET_STEP_UP) {
		subMenuObj = top.mainframe.leftframe.document.getElementById('subNavigation4');
		mainMenuColoredBlockObj = top.mainframe.leftframe.document.getElementById('menuItem4Block');
		newClass = 'lightStepUp';
	} else if(mainTargetID == TARGET_STEP_UP_1) {
		//alert('TARGET_STEP_UP_1');
		if(subTargetLink != null) {
			mainMenuObj = top.mainframe.leftframe.document.getElementById('subNavigation4');
		} else {
			//we are refreshing this page, so keep mainMenuObj as the 'mainNavigation'
		}
		subMenuObj = top.mainframe.leftframe.document.getElementById('subNavigation4_1');
		mainMenuColoredBlockObj = top.mainframe.leftframe.document.getElementById('menuItem4Block');
		newClass = 'lightStepUp';
	} else if(mainTargetID == TARGET_CREDIT_COURSES) {
		subMenuObj = top.mainframe.leftframe.document.getElementById('subNavigation3');
		mainMenuColoredBlockObj = top.mainframe.leftframe.document.getElementById('menuItem3Block');
		newClass = 'lightCreditCourses';
	} else if(mainTargetID == TARGET_SPEAK_TESTING) {
		subMenuObj = top.mainframe.leftframe.document.getElementById('subNavigation6');
		mainMenuColoredBlockObj = top.mainframe.leftframe.document.getElementById('menuItem6Block');
		newClass = 'lightSpeakTesting';
	} else if(mainTargetID == TARGET_ENGLISH_LANGUAGE_LEARNING) {
		subMenuObj = top.mainframe.leftframe.document.getElementById('subNavigation7');
		mainMenuColoredBlockObj = top.mainframe.leftframe.document.getElementById('menuItem7Block');
		newClass = 'lightELLC';
	} else if(mainTargetID == TARGET_ESL_STAFF) {
		subMenuObj = top.mainframe.leftframe.document.getElementById('subNavigation2');
		mainMenuColoredBlockObj = top.mainframe.leftframe.document.getElementById('menuItem2Block');
		newClass = 'lightESLStaff';
	} else if(mainTargetID == TARGET_GUIDE_FOR_FACULTY) {
		subMenuObj = top.mainframe.leftframe.document.getElementById('subNavigation9');
		mainMenuColoredBlockObj = top.mainframe.leftframe.document.getElementById('menuItem9Block');
		newClass = 'lightGuide';
	} else if(mainTargetID == TARGET_GUIDE_FOR_FACULTY_1) {
		if(subTargetLink != null) {
			mainMenuObj = top.mainframe.leftframe.document.getElementById('subNavigation9');
		} else {
			//we are refreshing this page, so keep mainMenuObj as the 'mainNavigation'
		}
		subMenuObj = top.mainframe.leftframe.document.getElementById('subNavigation9_1');
		mainMenuColoredBlockObj = top.mainframe.leftframe.document.getElementById('menuItem9Block');
		newClass = 'lightGuide';
	} else if(mainTargetID == TARGET_GUIDE_FOR_FACULTY_2) {
		if(subTargetLink != null) {
			mainMenuObj = top.mainframe.leftframe.document.getElementById('subNavigation9');
		} else {
			//we are refreshing this page, so keep mainMenuObj as the 'mainNavigation'
		}
		subMenuObj = top.mainframe.leftframe.document.getElementById('subNavigation9_2');
		mainMenuColoredBlockObj = top.mainframe.leftframe.document.getElementById('menuItem9Block');
		newClass = 'lightGuide';
	} else if(mainTargetID == TARGET_GUIDE_FOR_FACULTY_3) {
		if(subTargetLink != null) {
			mainMenuObj = top.mainframe.leftframe.document.getElementById('subNavigation9');
		} else {
			//we are refreshing this page, so keep mainMenuObj as the 'mainNavigation'
		}
		subMenuObj = top.mainframe.leftframe.document.getElementById('subNavigation9_3');
		mainMenuColoredBlockObj = top.mainframe.leftframe.document.getElementById('menuItem9Block');
		newClass = 'lightGuide';
	} else if(mainTargetID == TARGET_SPECIAL_PROGRAMS) {
		subMenuObj = top.mainframe.leftframe.document.getElementById('subNavigation8');
		mainMenuColoredBlockObj = top.mainframe.leftframe.document.getElementById('menuItem8Block');
		newClass = 'lightSpecialPrograms';
	} else if(mainTargetID == TARGET_ORIENTATION_INFO) {
		subMenuObj = top.mainframe.leftframe.document.getElementById('subNavigation1');
		mainMenuColoredBlockObj = top.mainframe.leftframe.document.getElementById('menuItem1Block');
		newClass = 'lightOrientationInfo';
	} else if(mainTargetID == TARGET_ADMISSIONS) {
		subMenuObj = top.mainframe.leftframe.document.getElementById('subNavigation5');
		mainMenuColoredBlockObj = top.mainframe.leftframe.document.getElementById('menuItem5Block');
		newClass = 'lightAdmissions';
	} else {
		//TARGET_HOME
		defaultFlag = true;

	}

	if(!defaultFlag) {
		//alert("menuMagicOnClick("+mainMenuObj.id+","+subMenuObj.id+","+mainMenuColoredBlockObj.id+","+newClass+")");

		//address the leftframe to avoid a race condition when the centerframe reloads
		top.mainframe.leftframe.menuMagicOnClick( mainMenuObj , subMenuObj, mainMenuColoredBlockObj, newClass );
		//alert('processNavigationLink('+mainTargetID+"...");
		processNavigationLink(mainTargetID, subTargetLink);


	} else {
		//alert('going home');
		// Return to the Home page
		//refresh the leftframe, and reset environment to the opening page
		homePageImageBarEnableCallback();
		doNavigationReturn();
		processNavigationLink(TARGET_HOME,'../home/home.htm');
		//alert('after going home');
	}

	return false;  //avoid calling the href attribute
}

// this function relies on getCurrentMain() returning the existing environment, not the new one
function doNavigationReturn() {
	var mainMenuObj = top.mainframe.leftframe.document.getElementById('mainNavigation');
	var openLocation = 0;
	var subMenuObj;
	var mainMenuColoredBlockObj;

	var existingEnvironment = getCurrentMain();
	//alert('existingEnvironment = '+existingEnvironment);


	//These are coordinated with the div id's in leftframe.htm
	if(existingEnvironment == TARGET_STEP_UP) {
		subMenuObj = top.mainframe.leftframe.document.getElementById('subNavigation4');
		mainMenuColoredBlockObj = top.mainframe.leftframe.document.getElementById('menuItem4Block');

	} else if(existingEnvironment == TARGET_STEP_UP_1) {
		//alert('TARGET_STEP_UP_1');
		subMenuObj = top.mainframe.leftframe.document.getElementById('subNavigation4_1');
		mainMenuColoredBlockObj = top.mainframe.leftframe.document.getElementById('menuItem4Block');

	} else if(existingEnvironment == TARGET_CREDIT_COURSES) {
		subMenuObj = top.mainframe.leftframe.document.getElementById('subNavigation3');
		mainMenuColoredBlockObj = top.mainframe.leftframe.document.getElementById('menuItem3Block');

	} else if(existingEnvironment == TARGET_SPEAK_TESTING) {
		subMenuObj = top.mainframe.leftframe.document.getElementById('subNavigation6');
		mainMenuColoredBlockObj = top.mainframe.leftframe.document.getElementById('menuItem6Block');

	} else if(existingEnvironment == TARGET_ENGLISH_LANGUAGE_LEARNING) {
		subMenuObj = top.mainframe.leftframe.document.getElementById('subNavigation7');
		mainMenuColoredBlockObj = top.mainframe.leftframe.document.getElementById('menuItem7Block');

	} else if(existingEnvironment == TARGET_ESL_STAFF) {
		subMenuObj = top.mainframe.leftframe.document.getElementById('subNavigation2');
		mainMenuColoredBlockObj = top.mainframe.leftframe.document.getElementById('menuItem2Block');

	} else if(existingEnvironment == TARGET_GUIDE_FOR_FACULTY) {
		subMenuObj = top.mainframe.leftframe.document.getElementById('subNavigation9');
		mainMenuColoredBlockObj = top.mainframe.leftframe.document.getElementById('menuItem9Block');

	} else if(existingEnvironment == TARGET_GUIDE_FOR_FACULTY_1) {
		subMenuObj = top.mainframe.leftframe.document.getElementById('subNavigation9_1');
		mainMenuColoredBlockObj = top.mainframe.leftframe.document.getElementById('menuItem9Block');

	} else if(existingEnvironment == TARGET_GUIDE_FOR_FACULTY_2) {
		subMenuObj = top.mainframe.leftframe.document.getElementById('subNavigation9_2');
		mainMenuColoredBlockObj = top.mainframe.leftframe.document.getElementById('menuItem9Block');

	} else if(existingEnvironment == TARGET_GUIDE_FOR_FACULTY_3) {
		subMenuObj = top.mainframe.leftframe.document.getElementById('subNavigation9_3');
		mainMenuColoredBlockObj = top.mainframe.leftframe.document.getElementById('menuItem9Block');

	} else if(existingEnvironment == TARGET_SPECIAL_PROGRAMS) {
		subMenuObj = top.mainframe.leftframe.document.getElementById('subNavigation8');
		mainMenuColoredBlockObj = top.mainframe.leftframe.document.getElementById('menuItem8Block');

	} else if(existingEnvironment == TARGET_ORIENTATION_INFO) {
		subMenuObj = top.mainframe.leftframe.document.getElementById('subNavigation1');
		mainMenuColoredBlockObj = top.mainframe.leftframe.document.getElementById('menuItem1Block');

	} else if(existingEnvironment == TARGET_ADMISSIONS) {
		subMenuObj = top.mainframe.leftframe.document.getElementById('subNavigation5');
		mainMenuColoredBlockObj = top.mainframe.leftframe.document.getElementById('menuItem5Block');

	} else {
		//TARGET_HOME
		//do nothing

	}

//alert('menuMagicReturnClick( '+mainMenuObj.id+","+openLocation+","+subMenuObj.id+","+mainMenuColoredBlockObj.id+","+newClass+")");

	//call the menu function to handle processing
	menuMagicRefresh( mainMenuObj, openLocation, subMenuObj, mainMenuColoredBlockObj );
	changeCornerPics(TARGET_HOME);


	return false;  //avoid calling the href attribute
}

/* This function is only used by doNavigationLink */
function processNavigationLink(mainTargetID, subTargetLink) {

	var existingEnvironment = getCurrentMain();

	// only switch the environment if its different
	if(existingEnvironment != mainTargetID) {

		//check if its a sub-sub section
		//if(!targetIsASubSubSection(mainTargetID)) {

			//see if we are departing from the main home page
			if(getCurrentMain() == TARGET_HOME) {

				//disable the image bar
				homePageImageBarDisableCallback();

				//hide the home page graphic
				resolveJavaScript("top.topframe","subheaderMainDiv","style.display='none'");

				//show the ESL title
				resolveJavaScript("top.topframe","headerTitleDiv","style.display='inline'");
			}

			//changeContentColorScheme(mainTargetID);
			changeSubTitle(mainTargetID);
			changeHeaderScrollingText(mainTargetID);
			changeCornerPics(mainTargetID);

		//}

		//set new current main section
		//alert('setCurrentMain('+mainTargetID+')');
		setCurrentMain(mainTargetID);
	}
	forwardToSubTarget(subTargetLink);
}

function forwardToSubTarget(subTargetLink) {

	if(subTargetLink != null) {
		top.mainframe.centerframe.location.href = subTargetLink;
	}/* else {
		top.mainframe.centerframe.location.href = "../home/centerFrame.htm";
	}*/
}

function changeSubTitle(mainTargetID) {
	var pictureSrc = "../home/images/";

	if(mainTargetID == TARGET_STEP_UP) {
		pictureSrc += "subheader-stepup.jpg";
	} else if(mainTargetID == TARGET_STEP_UP_1) {
		pictureSrc += "subheader-stepup.jpg";
	} else if(mainTargetID == TARGET_CREDIT_COURSES) {
		pictureSrc += "subheader-credit_courses.jpg";
	} else if(mainTargetID == TARGET_SPEAK_TESTING) {
		pictureSrc += "subheader-speak_testing_program.jpg";
	} else if(mainTargetID == TARGET_ENGLISH_LANGUAGE_LEARNING) {
		pictureSrc += "subheader-english_language_learning_center.jpg";
	} else if(mainTargetID == TARGET_ESL_STAFF) {
		pictureSrc += "subheader-esl_staff.jpg";
	} else if(mainTargetID == TARGET_GUIDE_FOR_FACULTY) {
		pictureSrc += "subheader-guide_for_faculty.jpg";
	} else if(mainTargetID == TARGET_GUIDE_FOR_FACULTY_1) {
		pictureSrc += "subheader-guide_for_faculty.jpg";
	} else if(mainTargetID == TARGET_GUIDE_FOR_FACULTY_2) {
		pictureSrc += "subheader-guide_for_faculty.jpg";
	} else if(mainTargetID == TARGET_GUIDE_FOR_FACULTY_3) {
		pictureSrc += "subheader-guide_for_faculty.jpg";
	} else if(mainTargetID == TARGET_SPECIAL_PROGRAMS) {
		pictureSrc += "subheader-special_programs.jpg";
	} else if(mainTargetID == TARGET_ORIENTATION_INFO) {
		pictureSrc += "subheader-orientation_information.jpg";
	} else if(mainTargetID == TARGET_ADMISSIONS) {
		pictureSrc += "subheader-admissions.jpg";
	} else {
		//TARGET_HOME
		pictureSrc += "subheader-main.gif";
		resolveJavaScript("top.topframe","subheaderMainDiv","style.display='inline'");
		resolveJavaScript("top.topframe","headerTitleDiv","style.display='none'");
	}
	//set the new image source for the subtitle
	resolveJavaScript("top.topframe","subtitle","src='"+pictureSrc+"'");
}

function changeCornerPics(mainTargetID) {
	var pictureSrc = "../home/images/";

	if(mainTargetID == TARGET_STEP_UP) {
		pictureSrc += "toprightcorner-StepUp.jpg";
	} else if(mainTargetID == TARGET_STEP_UP_1) {
		pictureSrc += "toprightcorner-StepUp.jpg";
	} else if(mainTargetID == TARGET_CREDIT_COURSES) {
		pictureSrc += "toprightcorner-CreditCourses.jpg";
	} else if(mainTargetID == TARGET_SPEAK_TESTING) {
		pictureSrc += "toprightcorner-Speak.jpg";
	} else if(mainTargetID == TARGET_ENGLISH_LANGUAGE_LEARNING) {
		pictureSrc += "toprightcorner-ELLC.jpg";
	} else if(mainTargetID == TARGET_ESL_STAFF) {
		pictureSrc += "toprightcorner-ESLStaff.jpg";
	} else if(mainTargetID == TARGET_GUIDE_FOR_FACULTY) {
		pictureSrc += "toprightcorner-GuideForStaff.jpg";
	} else if(mainTargetID == TARGET_GUIDE_FOR_FACULTY_1) {
		pictureSrc += "toprightcorner-GuideForStaff.jpg";
	} else if(mainTargetID == TARGET_GUIDE_FOR_FACULTY_2) {
		pictureSrc += "toprightcorner-GuideForStaff.jpg";
	} else if(mainTargetID == TARGET_GUIDE_FOR_FACULTY_3) {
		pictureSrc += "toprightcorner-GuideForStaff.jpg";
	} else if(mainTargetID == TARGET_SPECIAL_PROGRAMS) {
		pictureSrc += "toprightcorner-SpecialPrograms.jpg";
	} else if(mainTargetID == TARGET_ORIENTATION_INFO) {
		pictureSrc += "toprightcorner-OrientationInfo.jpg";
	} else if(mainTargetID == TARGET_ADMISSIONS) {
		pictureSrc += "toprightcorner-Admissions.jpg";
	} else {
		//TARGET_HOME
		pictureSrc += "toprightcorner-home.jpg";

	}
	//set the new image source for the toprightcorner image
	resolveJavaScript("top.topframe","toprightcorner","src='"+pictureSrc+"'");
}
function reloadNavbar() {
	top.mainframe.leftframe.location.href = "../home/leftFrame.htm";
}

function changeHeaderScrollingText(mainTargetID) {

	//hide all divs
	resolveJavaScript("top.topframe","headerScrollingTextDiv"+TARGET_HOME,"style.display='none'");
	resolveJavaScript("top.topframe","headerScrollingTextDiv"+TARGET_STEP_UP,"style.display='none'");
	resolveJavaScript("top.topframe","headerScrollingTextDiv"+TARGET_STEP_UP_1,"style.display='none'");
	resolveJavaScript("top.topframe","headerScrollingTextDiv"+TARGET_CREDIT_COURSES,"style.display='none'");
	resolveJavaScript("top.topframe","headerScrollingTextDiv"+TARGET_SPEAK_TESTING,"style.display='none'");
	resolveJavaScript("top.topframe","headerScrollingTextDiv"+TARGET_ENGLISH_LANGUAGE_LEARNING,"style.display='none'");
	resolveJavaScript("top.topframe","headerScrollingTextDiv"+TARGET_ESL_STAFF,"style.display='none'");
	resolveJavaScript("top.topframe","headerScrollingTextDiv"+TARGET_GUIDE_FOR_FACULTY,"style.display='none'");
	resolveJavaScript("top.topframe","headerScrollingTextDiv"+TARGET_GUIDE_FOR_FACULTY_1,"style.display='none'");
	resolveJavaScript("top.topframe","headerScrollingTextDiv"+TARGET_GUIDE_FOR_FACULTY_2,"style.display='none'");
	resolveJavaScript("top.topframe","headerScrollingTextDiv"+TARGET_GUIDE_FOR_FACULTY_3,"style.display='none'");
	resolveJavaScript("top.topframe","headerScrollingTextDiv"+TARGET_SPECIAL_PROGRAMS,"style.display='none'");
	resolveJavaScript("top.topframe","headerScrollingTextDiv"+TARGET_ORIENTATION_INFO,"style.display='none'");
	resolveJavaScript("top.topframe","headerScrollingTextDiv"+TARGET_ADMISSIONS,"style.display='none'");

	//show the specified div
	resolveJavaScript("top.topframe","headerScrollingTextDiv"+mainTargetID,"style.display='inline'");
}


/********************
 * Header functions *
 ********************/

function headerScrollingTextCallback(currentTextID, newTextID) {
	resolveJavaScript("top.topframe","headerScrollingTextDiv"+currentTextID,"style.display = 'none'");
	resolveJavaScript("top.topframe","headerScrollingTextDiv"+newTextID,"style.display = 'inline'");
	var nextCallStr = "headerScrollingTextCallback("+(currentTextID+1)%3+","+(newTextID+1)%3+")";
	setTimeout(nextCallStr,TEXT_DELAY);
}

function homePageImageBarCallback(currentPicID) {
	//alert('homePageImageBarCallback');
	if(top.topframe.IMAGE_BAR_ENABLED) {

		//alert('homePageImageBarCallback inside');
		//set newPicID to currentPicID to satisfy the while condition
		var newPicID = (currentPicID+1)%7;

		resolveJavaScript("top.topframe","headerImageBarDiv"+currentPicID,"style.display = 'none'");
		resolveJavaScript("top.topframe","headerImageBarDiv"+newPicID,"style.display = 'inline'");
		var nextCallStr = "homePageImageBarCallback("+newPicID+")";
		setTimeout(nextCallStr,PIC_DELAY);
	}
}

function homePageImageBarDisableCallback() {
	//alert('homePageImageBarDisableCallback()');
	top.topframe.IMAGE_BAR_ENABLED = false;

	//hide all ImageBar pics
	var i = 0;
	while(i<7) {
		resolveJavaScript("top.topframe","headerImageBarDiv"+i,"style.display = 'none'");
		i++;
	}

}

function homePageImageBarEnableCallback() {
	//alert('homePageImageBarEnableCallback()');
	if(!top.topframe.IMAGE_BAR_ENABLED) {
		top.topframe.IMAGE_BAR_ENABLED = true;

		//fire off a callback
		homePageImageBarCallback(6);
	}
}

/******************
 * Menu functions *
 ******************/

function hide(obj) {
	obj.style.visibility='hidden';
}

function show(obj) {
	obj.style.visibility='visible';
}
function menuMagicOnClick( mainMenu , subMenu, mainMenuColoredBlock, newClass ){

	mainMenuColoredBlock.className=newClass;
	moveDiv(mainMenu.id,collapsedMenuLocation,leftDirection,-speedIncrement);
	show(subMenu);
	moveDiv(subMenu.id,openSubmenuLocation,leftDirection,-speedIncrement);
}

function menuMagicReturnClick(mainMenu, openLocation,  subMenu, mainMenuColoredBlock, newClass ){

	if(currentlyInsideASubSubSection()) {
		//this is a bandaid for a browser refresh while in a sub-submenu and then clicking "return to main"
		//alert("currentlyInsideASubSubSection");
		show(mainMenu);
	}
	
	menuMagicSlideLeft(mainMenu, openLocation,  subMenu, mainMenuColoredBlock, newClass);



	if(!currentlyInsideASubSubSection()) {
		//alert('we are inside an ordinary subsection');
		//we are inside an ordinary subsection
		homePageImageBarEnableCallback();

		// only switch the environment if we're not returning from a sub-sub section)
		processNavigationLink(TARGET_HOME,'../home/home.htm');
		changeCornerPics(TARGET_HOME);
	} else {
		//we are inside a sub-subsection
		//alert('we are inside a sub-subsection');
		var targetEnvironment = parseInt(getCurrentMain()/100);
		setCurrentMain(parseInt(targetEnvironment)); //set the CURRENT_MAIN to the section ID

		//fix for the step up sub-submenu
		//if more sub-sub menus are added, this must be changed
		if(targetEnvironment == TARGET_STEP_UP) {
			//inside TARGET_STEP_UP_1
			forwardToSubTarget('../StepUp/home.htm');
		} else if(targetEnvironment == TARGET_GUIDE_FOR_FACULTY) {

			forwardToSubTarget('../Guide/home.htm');
		}
	}

	return false;  //avoid calling the href attribute
}

function menuMagicSlideLeft(mainMenu, openLocation,  subMenu, mainMenuColoredBlock, newClass) {
	mainMenuColoredBlock.className=newClass;
	moveDiv(mainMenu.id,openLocation,rightDirection,speedIncrement);
	moveDiv(subMenu.id,collapsedSubmenuLocation,rightDirection,speedIncrement);
}

function menuMagicRefresh(mainMenu, openLocation,  subMenu, mainMenuColoredBlock) {
	mainMenuColoredBlock.className='whiteCell';
	eval(mainMenu.style.left = openLocation);
	eval(subMenu.style.left = collapsedSubmenuLocation);
}

function moveDiv(menuItem,location,direction,increment) {

	var menuItemElement;

	if(usesLayers) {
		menuItemElement = eval("top.mainframe.leftframe.document.layers['"+menuItem+"']");
	} else if(usesDocAll) {
		menuItemElement = eval("top.mainframe.leftframe.document.all['"+menuItem+"']");
	} else if(usesDOM) {
		menuItemElement = eval("top.mainframe.leftframe.document.getElementById('"+menuItem+"')");
	}


	if ( direction == 0){
		continu = eval(parseInt(menuItemElement.style.left) <= location);
	}
	else{
		continu = eval(parseInt(menuItemElement.style.left) >= location);
	}

	if (continu) {
		eval(menuItemElement.style.left = location);  //to correct the distance multiple problem
		//n=0;
	}
	else{
		eval(menuItemElement.style.left = parseInt(menuItemElement.style.left) + increment);
		setTimeout("moveDiv('"+menuItem+"',"+location+","+direction+","+increment+");", 30);
	}
 }

function mainLinkMouseOver(parentObj, newClassName) {
	parentObj.style.cursor='hand';
	parentObj.className=newClassName;
}

function mainLinkMouseOut(parentObj, oldClassName) {
	parentObj.className=oldClassName;
}

function targetIsASubSubSection(targetID) {
	//alert("targetIsASubSubSection("+currentID+","+targetID+")");
	//alert(!(targetID<100 || (currentID != parseInt(targetID/100))) && (currentID<100 || (parseInt(currentID/100) != targetID)));	
	//alert("!("+targetID+"<100 || ("+currentID+" != parseInt("+targetID+"/100))) && ("+currentID+"<100 || (parseInt("+currentID+"/100) != "+targetID+"))");	
	
	//return !(targetID<100 || (currentID != parseInt(targetID/100))) && (currentID<100 || (parseInt(currentID/100) != targetID));	
	return(targetID>100);
}

function currentlyInsideASubSubSection() {
	//alert(getCurrentMain());
	return (parseInt(getCurrentMain())>100);
}