// JavaScript Document
var timerID = 0;
var timerValueInMiliseconds = 2000;

function flevDivPositionValue(sDiv, sProperty) { // v2.1, Marja Ribbers-de Vroed, FlevOOware
	this.opera = (window.opera); // Opera 5+
	this.ns4 = (document.layers); // Netscape 4.x
	this.ns6 = (document.getElementById && !document.all && !this.opera); // Netscape 6+
	this.ie = (document.all);  // Internet Explorer 4+
    var sValue = ""; docObj = eval("MM_findObj('" + sDiv + "')"); if (docObj == null) {return 0;}
	if ((sProperty == "left") || (sProperty == "top")) {
		if (!this.ns4) {docObj = docObj.style;} 
		sValue = eval("docObj." + sProperty);
		if ((this.ie) && (sValue == "")) { // IE (on PC) bug with nested layers
			if (sProperty == "top") { sValue = eval(sDiv + ".offsetTop"); } 
			else { sValue = eval(sDiv + ".offsetLeft"); } 
		};
	}
	else {
		if (this.opera) {
			docObj = docObj.style;
			if (sProperty == "height") { sValue = docObj.pixelHeight; } 
			else if (sProperty == "width") { sValue = docObj.pixelWidth; } 
		}
		else if (this.ns4) {sValue = eval("docObj.clip." + sProperty);} 
		else if (this.ns6) {sValue = document.defaultView.getComputedStyle(docObj, "").getPropertyValue(sProperty); } 
	    else if (this.ie) { 
			if (sProperty == "width") { sValue = eval(sDiv + ".offsetWidth"); } 
			else if (sProperty == "height") { sValue = eval(sDiv + ".offsetHeight"); } 
		}
   	}
	sValue = (sValue == "") ? 0 : sValue; 
	if (isNaN(sValue)) { if (sValue.indexOf('px') > 0) { sValue = sValue.substring(0,sValue.indexOf('px')); } } 
	return parseInt(sValue); 
}

function flevPersistentLayer() { // v3.3, Marja Ribbers-de Vroed, FlevOOware
	var sD = arguments[0], oD = eval("MM_findObj('" + sD + "')"), iWW, iWH, iSX, iSY, iT = 10, sS = "";
	if (!document.layers) {oD = oD.style;}
//	if (oD.tmpTimeout != null) {clearTimeout(oD.tmpTimeout);}
	var sXL = arguments[1], sXC = arguments[2], sXR = arguments[3], sYT = arguments[4], sYC = arguments[5], sYB = arguments[6];
	var iS = (arguments.length > 7) ? parseInt(arguments[7]) : 0, iPx = (arguments.length > 8) ? parseInt(arguments[8]) : 0;
	if (window.innerWidth) { // NS4, NS6 and Opera
		var oW = window; iWW = oW.innerWidth; iWH = oW.innerHeight; iSX = oW.pageXOffset; iSY = oW.pageYOffset; }
	else if (document.documentElement && document.documentElement.clientWidth) { // IE6 in standards compliant mode
		var oDE = document.documentElement; iWW = oDE.clientWidth; iWH = oDE.clientHeight; iSX = oDE.scrollLeft; iSY = oDE.scrollTop; }
	else if (document.body) { // IE4+
		var oDB = document.body; iWW = oDB.clientWidth; iWH = oDB.clientHeight; iSX = oDB.scrollLeft; iSY = oDB.scrollTop; }
	else {return;}
	var iCX = iNX = flevDivPositionValue(sD, 'left'), iCY = iNY = flevDivPositionValue(sD, 'top');
	if (sXL != "") {iNX = iSX + parseInt(sXL);} 
	else if (sXC != "") {iNX = Math.round(iSX + (iWW/2) - (flevDivPositionValue(sD, 'width')/2));}
	else if (sXR != "") {iNX = iSX + iWW - (flevDivPositionValue(sD, 'width') + parseInt(sXR));}
	if (sYT != "") {iNY = iSY + parseInt(sYT);}
	else if (sYC != "") {iNY = Math.round(iSY + (iWH/2) - (flevDivPositionValue(sD, 'height')/2));}
	else if (sYB != "") {iNY = iSY + (iWH - flevDivPositionValue(sD, 'height') - parseInt(sYB));}
	if ((iCX != iNX) || (iCY != iNY)) {
		if ((parseInt(navigator.appVersion)>4 || navigator.userAgent.indexOf("MSIE")>-1) && (!window.opera)) {sS="px";}
		eval("oD.left = '" + iNX + sS + "'");
		eval("oD.top = '" + iNY + sS + "'");
	}	
	var sF = "flevPersistentLayer('" + sD + "','" + sXL + "','" + sXC + "','" + sXR + "','" + sYT + "','" + sYC + "','" + sYB + "'," + iS + "," + iPx + ")";
	//oD.tmpTimeout = setTimeout(sF,10);
}

function flevInitPersistentLayer() { // v3.3, Marja Ribbers-de Vroed, FlevOOware
	if (arguments.length < 8) {return;}
	var sD = arguments[0]; if (sD == "") {return;}
	var	oD = eval("MM_findObj('" + sD + "')"); if (!oD) {return;}
	var iCSS = parseInt(arguments[1]);
	var sXL = arguments[2], sXC = arguments[3], sXR = arguments[4], sYT = arguments[5], sYC = arguments[6], sYB = arguments[7];
	var iS = (arguments.length > 8) ? parseInt(arguments[8]) : 0, iPx = (arguments.length > 9) ? parseInt(arguments[9]) : 0;
	if (iCSS != 0) { if (!document.layers) {oD = oD.style;} sXL = parseInt(oD.left), sYT = parseInt(oD.top);}
	var sF = "flevPersistentLayer('" + sD + "','" + sXL + "','" + sXC + "','" + sXR + "','" + sYT + "','" + sYC + "','" + sYB + "'," + iS + "," + iPx + ")";
	eval(sF);
}

function hideAllLayers (  ) {
	MM_showHideLayers('aboutUs','','hide');
	MM_showHideLayers('program','','hide');
	MM_showHideLayers('activities','','hide');
	MM_showHideLayers('locationDiv','','hide');	
}

function getXYcoord ( nvn ) {
   var elm = document.images[nvn]; 
   if ( document.layers ) return elm;
           // NS4 images contain x and y values
   var rd = { x:0 ,y:0 };
   do { rd.x += parseInt( elm.offsetLeft );
        rd.y += parseInt( elm.offsetTop );
        elm = elm.offsetParent;
   } while ( elm );
   return rd
}

function showMenu(menu) {
	hideAllLayers();

	var layerName = '';
	var imageName = '';
	switch(menu) {
		case 0: //aboutUs
			layerName = 'aboutUs';
			imageName = 'titleNavAboutUs';
			break;
		case 1: //program
			layerName = 'program';
			imageName = 'titleNavProgram';
			break;
		case 2: //activities
			layerName = 'activities';
			imageName = 'titleNavActivities';
			break;
		case 3: //location
			layerName = 'locationDiv';
			imageName = 'titleNavLocation';
			break;
	}

	setMenuPosition(imageName, layerName);	
	triggerTimeoutToHideMenu();
}

function triggerTimeoutToHideMenu() {	
	if (timerID != 0) clearTimeout(timerID);
	timerID = window.setTimeout('hideAllLayers()', timerValueInMiliseconds);
}

function setMenuPosition(imageName, layerName) {
	pos = getXYcoord(imageName);
	MM_showHideLayers(layerName, '', 'show');
	if (screen.height != 600 && screen.width != 800) { 	// patch!!
		flevInitPersistentLayer(layerName,0,pos.x,'','',pos.y+30,'','');
	}
}

function onResizeHandler() {
	var currentVisibleLayer = MM_findObj('aboutUs');
	if (currentVisibleLayer.style.visibility == 'visible') {
		setMenuPosition('titleNavAboutUs', 'aboutUs');
	}

	currentVisibleLayer = MM_findObj('program');
	if (currentVisibleLayer.style.visibility == 'visible') {
		setMenuPosition('titleNavProgram', 'program');
	}

	currentVisibleLayer = MM_findObj('activities');
	if (currentVisibleLayer.style.visibility == 'visible') {
		setMenuPosition('titleNavActivities', 'activities');
	}

	currentVisibleLayer = MM_findObj('locationDiv');
	if (currentVisibleLayer.style.visibility == 'visible') {
		setMenuPosition('titleNavLocation', 'locationDiv');
	}
}

function changeObjectStyle(obj, style) {	
	obj.className = style;
	triggerTimeoutToHideMenu();
}

window.onresize = onResizeHandler;
