// Main menu scripts:
function showOverStyle (button) {
	button = document.getElementById (button);
	button.className = "menuitemMO";
}
function showOffStyle (button) {
	button = document.getElementById (button);
	button.className = "menuitem";
}
function showSubOverStyle (button) {
	button = document.getElementById (button);
	button.className = "submenuButtonMO";
}
function showSubOffStyle (button) {
	button = document.getElementById (button);
	button.className = "submenuButton";
}
function showHide (menuItem, display) {
	menuItem.style.visibility = display;
}
function showSubLevel1 (menuid, show) {
	if (show == 1) {
		display = "visible";
	} else {	 
		display = "hidden";
	}
	var a = 0;
	var menuItem = document.getElementById ('subMenu[' + menuid + '][' + a + ']');
	while (menuItem) {
		showHide (menuItem, display);
		a ++;
		menuItem = document.getElementById ('subMenu[' + menuid + '][' + a + ']');
	}
}
function showSubLevel2 (menuid, submenuid, show) {
	button = document.getElementById ('subMenu[' + menuid + '][' + submenuid + ']');
	if (show == 1) {
		display = "visible";
		button.className = "submenuButtonMO";
	} else {	 
		display = "hidden";
		button.className = "submenuButton";
	}
	var a = 0;
	var menuItem = document.getElementById ('subMenu[' + menuid + '][' + submenuid + '][' + a + ']');
	while (menuItem) {
		showHide (menuItem, display);
		a ++;
		menuItem = document.getElementById ('subMenu[' + menuid + '][' + submenuid + '][' + a + ']');
	}
}

// Other scripts:
function imgswap (elementid, newsrc) {
	document.getElementById (elementid).src = 'furniture/' + newsrc;
}
function preLoadImages () {
	var preloaded = new Array;
	for (index = 0; index < preLoadImages.arguments.length; index++) {
		preloaded[index] = new Image;
		preloaded[index].src = 'furniture/' + preLoadImages.arguments[index];
	}
}
// Function for the Resource Centre drop-downs:
function swapsubcategorylist (newcategoryid) {
	var i;
	var subcatidlist = eval ("subcatlistid" + newcategoryid);
	var subcatnamelist = eval ("subcatlistname" + newcategoryid);
	var dropdown = document.resourceform["sc"];
	dropdown.length = 0;
	for (i = 0; i < subcatidlist.length; i ++) {
		dropdown[i] = new Option (subcatnamelist[i], subcatidlist[i]);
	}
	dropdown.selectedIndex = 0;
}
// Resource Centre moving div
var initialPos = 0; // Sets upper limit to movement
var lowerPos = -430; // Lower number means menu rests higher up screen
var thispos = 0;
var moving = 0; // Action flag

function positiononlineadvisor () {
	if ((thispos != Math.max ((document.body.scrollTop + lowerPos), initialPos)) && (!moving) ) {
		var launch = new Date ();
		start = launch.valueOf ();
		target = Math.max((document.body.scrollTop + lowerPos), initialPos);
		C = thispos - target;
		moving = 1;
		moveonlineadvisor ();
		positiononlineadvisor ();
	}
	setTimeout ("positiononlineadvisor ()", 1000);
}
function moveonlineadvisor () {
	var going = new Date ();
	now = going.valueOf ();
	t = (now - start) / 1000;
	with (Math) { thispos = target + C*exp(-10*t)*sin(3*t+(PI/2)); }
	document.getElementById ("onlineadvisor").style.top = thispos;
	if (t > 0.7) {
		if (Math.abs (thispos - Math.max ((document.body.scrollTop + lowerPos), initialPos)) < 3) document.getElementById ("onlineadvisor").style.top = Math.max ((document.body.scrollTop + lowerPos), initialPos);
		thispos = parseInt (document.getElementById ("onlineadvisor").style.top);
		moving = 0;
		return 1;
	} else {
		setTimeout ("moveonlineadvisor ()", 5);
	}
}
