var seccion = null;
var texto_selecciado = null;
var iniseccion = null;
var sec_selected = null;

function _iniover(str) {
	iniseccion = str;
	_over(str);
}

function _over(str) {
	var obj = document.getElementById(str);

	if (seccion == null || str != seccion)	{
		var img = document.getElementById("img_" + str);

		if (img.src.substr(img.src.length-6, 2) == "on") {
			img.src = img.src.substr(0, img.src.length-6) + "off.png";
		} else {
			img.src = img.src.substr(0, img.src.length-6) + "n.png";
		}
	}
}

function _show(str) {
	if (str != seccion && str != sec_selected) {
		var old_sec = seccion;
		seccion = null;
		sec_selected = null;

		if (old_sec != null) {
			if (old_sec != iniseccion) {
				_over(old_sec);
			}
			var obj_last = document.getElementById("mn_" + old_sec);
			obj_last.className = "menu hidden";
		}

		var obj = document.getElementById("mn_" + str);
		obj.className = "menu";
		if (str != iniseccion) {
			_over(str);
		}
		seccion = str;
	}
}

function _hide(force) {
	if (force || !_overMenu()) {
		var old_sec = seccion;

		if (old_sec != null) {
			if (force || old_sec != sec_selected) {
				seccion = null;
				sec_selected = null;

				if (old_sec != iniseccion) {
					_over(old_sec);
				}
				var obj_last = document.getElementById("mn_" + old_sec);
				obj_last.className = "menu hidden";
			}
		}
	}
}

function _select(str) {
	sec_selected = str;
}

function _menuover(str) {
	var obj = document.getElementById(str);

	if (str != texto_selecciado) {
		if (obj.className == "opcion on") {
			obj.className = "opcion off";
		} else {
			obj.className = "opcion on";
		}
	}
}

function _goto(seccion) {
	document.location = "/esp/" + seccion + ".html";
}

function clearif() {
	document.getElementById("ifdownload").src = "about:blank";
}

function cambiarhref() {
	var obj = document.getElementById("bot_download");
	obj.href = "pdfdownload.php?id=" + document.getElementById("slct_difusion").value;
}

function descargar() {
	/*
	var obj = document.getElementById("slct_difusion");
	var id = obj.value;

	if (id != '0') {
		document.getElementById("ifdownload").src = "download.php?id=" + id;
	} else {
		alert("No hay archivos para descargar");
	}
	*/
}

function _on(txt) {
	texto_selecciado = txt;
	document.getElementById(txt).className = "opcion off";
}

/* - - - posiciones de objetos - - - */
function _overMenu() {
	var obj = document.getElementById("mn_" + seccion);
	if (obj) {
		var x = findPosX(obj);
		var y = findPosY(obj);
		var w = obj.offsetWidth;
		var h = obj.offsetHeight;

		retValue = mouseX >= x && mouseX <= (x + w);
		retValue = retValue && mouseY >= (y - 21) && mouseY <= (y + h);

		return retValue;
	} else { return false; }
}

function findPosX(obj) {
	var curleft = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curleft += obj.offsetLeft;
			obj = obj.offsetParent;
		}
	} else if (obj.x) curleft += obj.x;
	return curleft;
}

function findPosY(obj) {
	var curtop = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curtop += obj.offsetTop;
			obj = obj.offsetParent;
		}
	} else if (obj.y) curtop += obj.y;
	return curtop;
}

var IE = document.all?true:false
if (!document.all) document.captureEvents(Event.MOUSEMOVE);
document.onmousemove = getMouseXY;
var mouseX = 0; var mouseY = 0;
var hide_timer = setInterval("_hide()", 50);

function getMouseXY(e) {
  if (IE) { // grab the x-y pos.s if browser is IE
    mouseX = event.clientX + document.body.scrollLeft
    mouseY = event.clientY + document.body.scrollTop
  } else {  // grab the x-y pos.s if browser is NS
    mouseX = e.pageX
    mouseY = e.pageY
  }  
  // catch possible negative values in NS4
  if (mouseX < 0){ mouseX = 0; }
  if (mouseY < 0){ mouseY = 0; }

  return true;
}