// return the name of the sub menu (from the title string)
function getSubMenu(){
var fulltitle = parent.document.title;
//alert ("check menu" + fulltitle );	
	titleArray = fulltitle.split(" - ");
	arrayLength=titleArray.length;
//alert ("menu length " + arrayLength );

if (arrayLength >= 3) {
thisMenuStr = titleArray[2];
//alert ("thisMenuStr " + thisMenuStr );

thisMenuidList=thisMenuStr.split(" "); 

thisMenu=thisMenuidList[0];

//alert ("the menu" + thisMenu);

	if (arrayLength >= 2) {
mainSection = titleArray[1];
//alert ("mainSection" + mainSection);}
}
}else {
//alert ("NO sub menu!");
return 0;
}
	return thisMenu;
}

// return the name of the main section (from the title string)
function getMainSection(){
var fulltitle = parent.document.title;
//alert ("check menu" + fulltitle );	
	titleArray = fulltitle.split(" - ");
	arrayLength=titleArray.length;
//alert ("menu length " + arrayLength );

	if (arrayLength >= 2) {
mainSection = titleArray[1];
}
//alert ("mainSection" + mainSection);}
else {
//alert ("NO sub menu!");
return 0;
}
	return mainSection;
}

// hilite the top menu
function hiliteTopMenu(){
// get the name of the main section
thisMainSection=getMainSection();
if (thisMainSection != 0) {
//alert ("thisMainSection" + thisMainSection);
if ((thisMainSection == "Education") || (thisMainSection == "Entertainment") || (thisMainSection == "REAL WORLDS")){
// -- top menu
// get the element with the id = thisMainSection
var obj=getElementID(thisMainSection);
//alert("I am a " + obj.tagName + " element");
//var source=obj.getAttribute("src");
//alert("my source is " + source);
// set new scr for the img object
onScr="images/menu/top/btn_" + thisMainSection + "-on.gif";
//alert ("on scr" + onScr);
// set new src on the image object
obj.setAttribute("src",onScr);

//-- immersion logo

onScr="images/menu/top/logo_imm-" + thisMainSection + ".gif";
var setLogo=1;
}
else if (thisMainSection == "Welcome"){
onScr="images/menu/top/logo_pwl-basic.gif";
var setLogo=1;
} else {
onScr="images/menu/top/logo_pwl-admin.gif";
var setLogo=1;
}
if (setLogo) {
var obj=getElementID("immLogo");
obj.setAttribute("src",onScr);
}
}
}

// hilite the submenu on the left of the page
function hiliteLeftMenu(){
// get the submenu name
thisMenu = getSubMenu();
// get the main section name : we need it for the color of the menu
thisMainSection=getMainSection();
if (thisMenu != 0) {
//alert (thisMenu);/
//alert ("thisMenu == " + thisMenu);
var id = thisMenu;

//alert(document.getElementById);
obj = getElementID(id)

obj.style.visibility= "visible";
textColor=getColorBySection(thisMainSection);
//alert ("text color" + textColor);		
obj.style.color=textColor;

}
}

// return the appropriate color of the hilite depending on the section
function getColorBySection(mainSection){
if (mainSection == "Education") {return "#04BEDF";}
if (mainSection == "REAL WORLDS") {return "#DB5B35";}
if (mainSection == "Entertainment") {return "#6F0F6F";}
if (mainSection == "What we do is unique") {return "#865969";}
}


// return element id 
function getElementID(id) {
if (document.layers) {
//alert("document.layers");
		var obj = document.layers[id];
		obj.visibility= "visible";
	}
	
	else if (document.getElementById) {
//alert("document.getElementById");
			var obj = document.getElementById(id);
//alert("I am a " + obj.tagName + " element");
	}
else if (document.all && !window.opera) {
//alert("document.all window.opera");
		var obj = document.all[id];
		obj.style.visibility= "visible";
	}
return obj;
}

// Preload Images function
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImage() { //v3.0
	var i,j=0,x,a=MM_swapImage.arguments;
	document.MM_sr=new Array;
	for (i=0;i<(a.length-2);i+=3) { if ((x=MM_findObj(a[i]))!=null) { document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2]; } }
}

function MM_findObj(n, d) { //v4.01
	var p,i,x; if (!d) d=document;
	if ((p=n.indexOf("?"))>0&&parent.frames.length) { d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p); }
	if (!(x=d[n])&&d.all) x=d.all[n];
	for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	for (i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
	if(!x && d.getElementById) x=d.getElementById(n);
	return x;
}
