var subMenus = new Array();

function ShowPopup(a)
{
	var _x = a.offsetLeft + 20;
	var _y = 90;
	if(a.popup) { delete a.popup; a.popup = null; }
	switch(a.id)
	{
		case "menu_1":
			a.popup = new Popup(a);
			a.popup.AddItem(subMenus[0][0], "proyectos.php");
			a.popup.AddItem(subMenus[0][1], "concursos.php");
			a.popup.SetPosition(_x, _y);
			a.popup.Show();
			break;
		case "menu_2":
			a.popup = new Popup(a);
			a.popup.AddItem(subMenus[1][0], "premios.php");
			a.popup.AddItem(subMenus[1][1], "obras.php");
			a.popup.SetPosition(_x, _y);
			a.popup.Show();
			break;
		case "menu_3":
			a.popup = new Popup(a);
			a.popup.AddItem(subMenus[2][0], "noticias.php");
			a.popup.AddItem(subMenus[2][1], "hemeroteca.php");
			a.popup.SetPosition(_x, _y);
			a.popup.Show();
			break;
		case "menu_4":
			a.popup = new Popup(a);
			a.popup.AddItem(subMenus[3][0], "escultura.php");
			a.popup.AddItem(subMenus[3][1], "patentes.php");
			a.popup.AddItem(subMenus[3][2], "ladrillos.php");
			a.popup.AddItem(subMenus[3][3], "otros.php");
			a.popup.SetPosition(_x, _y);
			a.popup.Show();
			break;
		case "menu_5":
			a.popup = new Popup(a);
			a.popup.AddItem(subMenus[4][0], "direccion.php");
			a.popup.AddItem(subMenus[4][1], "equipo.php");
			a.popup.AddItem(subMenus[4][2], "contacto.php");
			a.popup.SetPosition(_x, _y);
			a.popup.Show();
			break;
	}
}

function Popup(parent)
{
	var self = this;
	var isOver = false;
	var isLinkOver = false;
	var start = null;
	var timer = null;
	var Hide = function() { setTimeout(function() { self.Hide(); }, 100); };
	var popup = document.createElement("div");
	popup.className = "popup";
	popup["onmouseover"] = function() { isOver = true; };
	popup["onmouseout"] = function() { isOver = false; Hide(); };
	parent["onmouseout"] = function() { Hide(); };
	document.getElementById("container").appendChild(popup);

	this.AddItem = function(title, url)
	{
		var a = document.createElement("a");
		a["onmouseover"] = function() { isLinkOver = true; };
		a["onmouseout"] = function() { isLinkOver = false; };
		a.href = url;
		a.appendChild(document.createTextNode(title));
		popup.appendChild(a);
	}
	this.SetPosition = function(x, y)
	{
		popup.style.left = x + "px";
		popup.style.top = y + "px";
	}
	var FadeIn = function()
	{
		var delta = ((new Date()).getTime() - start.getTime()) * 0.001 * 3;
		if(delta < 1)
		{
			var opacity = 100 * delta;
			popup.style.filter = "alpha(opacity=" + opacity + ")";
			popup.style.opacity = opacity * 0.01;
		}
		else
		{
			fading = false;
			clearInterval(timer);
		}
	}
	var FadeOut = function()
	{
		var delta = ((new Date()).getTime() - start.getTime()) * 0.001 * 6;
		if(delta < 1)
		{
			var opacity = 100 - 100 * delta;
			popup.style.filter = "alpha(opacity=" + opacity + ")";
			popup.style.opacity = opacity * 0.01;
		}
		else
		{
			try { document.getElementById("container").removeChild(popup); } catch(e) { }
			clearInterval(timer);
		}
	}
	this.Show = function()
	{
		start = new Date();
		popup.style.filter = "alpha(opacity=0.0)";
		popup.style.opacity = "0";
		timer = setInterval(function() { FadeIn(); }, 10);
	}
	this.Hide = function()
	{
		if(isOver || isLinkOver) return;
		start = new Date();
		timer = setInterval(function() { FadeOut(); }, 10);
	}
}

