window.onload = montre;
var activeElement;
var oE;
document.onmousemove = doSomething;

function findPosX(obj) {
	var curleft = 0;
	if (obj.offsetParent)
		while (1) {
			curleft += obj.offsetLeft;
			if (!obj.offsetParent)
				break;
			obj = obj.offsetParent;
		}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj) {
	var curtop = 0;
	if (obj.offsetParent)
		while (1) {
			curtop += obj.offsetTop;
			if (!obj.offsetParent)
				break;
			obj = obj.offsetParent;
		}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

function doSomething(e) {
	var posx = 0;
	var posy = 0;
	var menuDiv = document.getElementById('menu');
	if (menuDiv != null) {
		var menuHeight = menuDiv.offsetHeight;
		var menuwidth = menuDiv.offsetWidth;

		if (!e)
			var e = window.event;
		if (e.pageX || e.pageY) {
			posx = e.pageX;
			posy = e.pageY;
		} else if (e.clientX || e.clientY) {
			posx = e.clientX + document.body.scrollLeft
					+ document.documentElement.scrollLeft;
			posy = e.clientY + document.body.scrollTop
					+ document.documentElement.scrollTop;
		}
		// posx and posy contain the mouse position relative to the document
		// Do something with this information
		// oE=document.elementFromPoint(posx,posy);
		// if ((oE.className != "menuImg") && (oE.tagName != "A"))
		// window.status=posx+":"+posy+":"+menuDiv.offsetWidth+":"+
		// menuDiv.offsetHeight+":"+findPosX(menuDiv)+":"+findPosY(menuDiv);

		if ((posx < findPosX(menuDiv)) || (posy < findPosY(menuDiv))
				|| (posy > (findPosY(menuDiv) + menuHeight))
				|| (posx > (findPosX(menuDiv) + menuwidth)))
			collapseAll();
	}
}

function collapseAll() {
	var menuRoot = document.getElementById('menu');
	if (menuRoot) {
		var divs = menuRoot.getElementsByTagName("DIV");
		for ( var k = 0; k < divs.length; k++)
			if (divs[k].className == "collapsed")
				divs[k].style.display = 'none';
	}
}

function collapseAllOther(d) {
	var menuRoot = document.getElementById('menu');
	if (menuRoot) {
		var divs = menuRoot.getElementsByTagName("DIV");
		for ( var k = 0; k < divs.length; k++)
			if (divs[k].className == "collapsed" && divs[k].id != d.id)
				divs[k].style.display = 'none';
	}
}

function montre(id, action) {
	var d = document.getElementById(id);
	var act = action
	if (d) {
		//if(activeElement)
		// alert(act+":"+activeElement.id+":"+d.id);
		if (act == 0) {
			if (activeElement) {
				if (activeElement.id != d.id) {
					//alert("here"+activeElement.id+":"+d.id);
					activeElement.style.display = 'none';
					activeElement = d;
				}
			} else {
				d.style.display = 'none';
				activeElement = d;
			}
		}

		if (act == 1) {
			d.style.display = 'block';
			collapseAllOther(d);

		}
		if (act == 2) {

			d.style.display = 'none';
			activeElement = d;
		}
	}
}

function changeImgOver(imgObj) {
	var imgUrl = imgObj.src;
	var start = (imgObj.src).lastIndexOf('/');
	var end = (imgObj.src).lastIndexOf('.');
	var newUrl = imgUrl.substring(0, start + 1)
			+ imgUrl.substring(start + 1, end) + "_over"
			+ imgUrl.substring(end);
	imgObj.src = newUrl;
}

function changeImgOut(imgObj) {
	var imgUrl = imgObj.src;
	var start = (imgObj.src).lastIndexOf('/');
	var end = (imgObj.src).lastIndexOf('_');
	var ext = (imgObj.src).lastIndexOf('.');
	var newUrl = imgUrl.substring(0, start + 1)
			+ imgUrl.substring(start + 1, end) + imgUrl.substring(ext);
	imgObj.src = newUrl;
}
