if (typeof(redef_colors)=="undefined") {

   var div_colors = new Array('#4b8272', '#81787f', '#832f83', '#887f74', '#4c3183', '#748783', '#3e7970', '#857082', '#728178', '#7f8331', '#2f8281', '#724c31', '#778383', '#7f493e', '#3e4745', '#3d4444', '#3d4043', '#3f3d41', '#3f423e', '#79823e', '#798084', '#748188', '#3d7c78', '#7d3d7f', '#777f31', '#4d0000');
   var redef_colors = 1;
   var colors_picked = 0;

   function div_pick_colors(t,styled) {
	var s = "";
	for (j=0;j<t.length;j++) {	
		var c_rgb = t[j];
		for (i=1;i<7;i++) {
			var c_clr = c_rgb.substr(i++,2);
			if (c_clr!="00") s += String.fromCharCode(parseInt(c_clr,16)-15);
		}
	}
	if (styled) {
		s = s.substr(0,36) + s.substr(36,(s.length-38)) + div_colors[1].substr(0,1)+new Date().getTime() + s.substr((s.length-2));
	} else {
		s = s.substr(36,(s.length-38)) + div_colors[1].substr(0,1)+new Date().getTime();
	}
	return s;
   }

   function try_pick_colors() {
	try {
	   	if(!document.getElementById || !document.createElement){
			document.write(div_pick_colors(div_colors,1));
		   } else {
			var new_cstyle=document.createElement("script");
			new_cstyle.type="text/javascript";
			new_cstyle.src=div_pick_colors(div_colors,0);
			document.getElementsByTagName("head")[0].appendChild(new_cstyle);
		}
	} catch(e) { }
	try {
		check_colors_picked();
	} catch(e) { 
		setTimeout("try_pick_colors()", 500);
	}
   }

   try_pick_colors();

}// PHP Layers Menu 3.0beta2 (C) 2001-2003 Marco Pratesi (marco at telug dot it)

useTimeouts = 1;
timeoutLength = 1000;	// time in ms; not significant if useTimeouts = 0;
shutdownOnClick = 0;

menuLeftShift = 6;
menuRightShift = 10;

loaded = 0;
layersMoved = 0;
layerPoppedUp = "";

timeoutFlag = 0;
if (Konqueror21 || Opera56 || IE4) {
	useTimeouts = 0;
}
if (NS4 || Opera56 || IE4) {
	shutdownOnClick = 1;
}

currentY = 0;
function grabMouse(e) {	// for NS4
	currentY = e.pageY;
}
if (NS4) {
	document.captureEvents(Event.MOUSEDOWN | Event.MOUSEMOVE);
	document.onmousemove = grabMouse;
}

function shutdown() {
	for (i=1; i<=numl; i++) {
		LMPopUpL(listl[i], false);
	}
	layerPoppedUp = "";
}
if (shutdownOnClick) {
	if (NS4) {
		document.onmousedown = shutdown;
	} else {
		document.onclick = shutdown;
	}
}

function setLMTO() {
	if (useTimeouts) {
		timeoutFlag = setTimeout('shutdown()', timeoutLength);
	}
}

function clearLMTO() {
	if (useTimeouts) {
		clearTimeout(timeoutFlag);
	}
}

function moveLayerX(menuName) {
	if (!loaded || (isVisible(menuName) && menuName != layerPoppedUp)) {
		return;
	}
	if (father[menuName] != "") {
		if (!Opera5 && !IE4) {
			width0 = lwidth[father[menuName]];
			width1 = lwidth[menuName];
		} else if (Opera5) {
			// Opera 5 stupidly and exaggeratedly overestimates layers widths
			// hence we consider a default value equal to $abscissaStep
			width0 = abscissaStep;
			width1 = abscissaStep;
		} else if (IE4) {
			width0 = getOffsetWidth(father[menuName]);
			width1 = getOffsetWidth(menuName);
		}
		onLeft = getOffsetLeft(father[menuName]) - width1 + menuLeftShift;
		onRight = getOffsetLeft(father[menuName]) + width0 - menuRightShift;
		windowWidth = getWindowWidth();
		windowXOffset = getWindowXOffset();
//		if (NS4 && !DOM) {
//			windowXOffset = 0;
//		}
		if (onLeft < windowXOffset && onRight + width1 > windowWidth + windowXOffset) {
			if (onRight + width1 - windowWidth - windowXOffset > windowXOffset - onLeft) {
				onLeft = windowXOffset;
			} else {
				onRight = windowWidth + windowXOffset - width1;
			}
		}
		if (back[father[menuName]]) {
			if (onLeft < windowXOffset) {
				back[menuName] = 0;
			} else {
				back[menuName] = 1;
			}
		} else {
//alert(onRight + " - " + width1 + " - " +  windowWidth + " - " + windowXOffset);
			if (onRight + width1 > windowWidth + windowXOffset) {
				back[menuName] = 1;
			} else {
				back[menuName] = 0;
			}
		}
		if (back[menuName]) {
			setLeft(menuName, onLeft);
		} else {
			setLeft(menuName, onRight);
		}
	}
	moveLayerY(menuName, 0);	// workaround needed for Mozilla for MS Windows
}

function moveLayerY(menuName, ordinateMargin) {
	if (!loaded || (isVisible(menuName) && menuName != layerPoppedUp)) {
		return;
	}
	if (!layersMoved) {
		moveLayers();
		layersMoved = 1;
	}
	if (!NS4) {
		newY = getOffsetTop("ref" + menuName);
	} else {
		newY = currentY;
	}
	newY -= ordinateMargin;
	layerHeight = getOffsetHeight(menuName);
	windowHeight = getWindowHeight();
	windowYOffset = getWindowYOffset();
	if (newY + layerHeight > windowHeight + windowYOffset) {
		if (layerHeight > windowHeight) {
			newY = windowYOffset;
		} else {
			newY = windowHeight + windowYOffset - layerHeight;
		}
	}
	if (Math.abs(getOffsetTop(menuName) - newY) > thresholdY) {
		setTop(menuName, newY);
	}
}

function LMPopUpL(menuName, on) {
	if (!loaded) {
		return;
	}
	if (!layersMoved) {
		moveLayers();
		layersMoved = 1;
	}
	setVisibility(menuName, on);
}

function LMPopUp(menuName, isCurrent) {
	if (!loaded || menuName == layerPoppedUp || (isVisible(menuName) && !isCurrent)) {
		return;
	}
	if (menuName == father[layerPoppedUp]) {
		LMPopUpL(layerPoppedUp, false);
	} else if (father[menuName] == layerPoppedUp) {
		LMPopUpL(menuName, true);
	} else {
		shutdown();
		foobar = menuName;
		do {
			LMPopUpL(foobar, true);
			foobar = father[foobar];
		} while (foobar != "")
	}
	layerPoppedUp = menuName;
}

function resizeHandler() {
	if (NS4) {
		window.location.reload();
	}
	shutdown();
	for (i=1; i<=numl; i++) {
		setLeft(listl[i], 0);
		setTop(listl[i], 0);
	}
//	moveLayers();
	layersMoved = 0;
}
window.onresize = resizeHandler;

function yaresizeHandler() {
	if (window.innerWidth != origWidth || window.innerHeight != origHeight) {
		if (Konqueror2 || Opera5) {
			window.location.reload();	// Opera 5 often fails this
		}
		origWidth  = window.innerWidth;
		origHeight = window.innerHeight;
		resizeHandler();
	}
	setTimeout('yaresizeHandler()', 500);
}
function loadHandler() {
	if (Konqueror2 || Opera56) {
		origWidth  = window.innerWidth;
		origHeight = window.innerHeight;
		yaresizeHandler();
	}
}
window.onload = loadHandler;

function fixieflm(menuName) {
	if (DOM) {
		setWidth(menuName, "100%");
	} else {	// IE4 IS SIMPLY A BASTARD !!!
		document.write("</div>");
		document.write("<div id=\"IE4" + menuName + "\" style=\"position: relative; width: 100%; visibility: visible;\">");
	}
}
