// Menus
var Menus = Array (Array ('mMotivation', 'menuMotivation'), Array ('mInstitute', 'menuInstitute'), Array ('mApplication', 'menuApplications'));

// Menu functions
var MouseOver = false;
var MenuSelected;

function MenuObj_In (menu) {
	//MouseOver = true;
	menuHide();
	MenuSelected = menu;
	menuShow();
}

function MenuObj_Out (obj) {
	MouseOver = false;
	menuHide ();
	MenuSelected = null;
}

function menuShow() {
	if (MenuSelected != null) { 
		document.getElementById(Menus[MenuSelected][1]).style.display = 'block'; 
		document.getElementById(Menus[MenuSelected][0]).className = 'menuItemSelected';
	}
	return true;
}

function menuHide () {
	if (MenuSelected != null && !MouseOver) { 
		document.getElementById(Menus[MenuSelected][1]).style.display = 'none'; 
		document.getElementById(Menus[MenuSelected][0]).className = 'menuItem';
	}
	return true;
}


/* Scrolling functions */
var TimerUp;
var TimerDown;

function doScrollUp () {
	var Text = document.getElementById("pageText");
	var Container = document.getElementById("contentContainer");
	var height = Text.style.top.substr(0, Text.style.top.length - 2);
	if (height.length == 0) { height = 0; }
	if (height < 0) {	
		Text.style.top = (parseInt(height) + 10) + 'px';
	}
	TimerUp = setTimeout("doScrollUp()", 250);
}

function doScrollDown () {
	var Text = document.getElementById("pageText");
	var Container = document.getElementById("contentContainer");
	var Delta = Text.offsetHeight - Container.offsetHeight;
	var height = Text.style.top.substr(0, Text.style.top.length - 2);
	if (height.length == 0) { height = 0; }
	if (height > -(Delta)) {
		Text.style.top = (parseInt(height) - 10) + 'px';
	}
	TimerDown = setTimeout("doScrollDown()", 250);
}

function startUp () {
	TimerUp = setTimeout("doScrollUp()", 250);
}

function stopUp () {
	clearTimeout (TimerUp);
}

function startDown () {
	TimerDown = setTimeout("doScrollDown()", 250);
}

function stopDown () {
	clearTimeout (TimerDown);
}

function jumpUp () {
	var Text = document.getElementById("pageText");
	var Container = document.getElementById("contentContainer");
	var height = Text.style.top.substr(0, Text.style.top.length - 2);
	if (height.length == 0) { height = 0; }
	if (height < 0) {	
		Text.style.top = (parseInt(height) + 25) + 'px';
	}
}

function jumpDown () {
	var Text = document.getElementById("pageText");
	var Container = document.getElementById("contentContainer");
	var Delta = Text.offsetHeight - Container.offsetHeight;
	var height = Text.style.top.substr(0, Text.style.top.length - 2);
	if (height.length == 0) { height = 0; }
	if (height > -(Delta)) {
		Text.style.top = (parseInt(height) - 25) + 'px';
	}
}

/* handle mousewheel scrolling */
function handle(delta) {
        if (delta < 0) {
			// Down
			jumpDown();
        } else {
			// Up
			jumpUp();
		}
}

