// ----- Popup Control ---------------------------------------------------------
//global da língua (por causa do submenu voltas)
var myLang = "PT";

function initSubMenus(situation, lang)
{ 
	myCurrent = ""
	myLang = lang;
	switch (situation) {
    case "none":
      attachSubMenus("ocios", "subMenuOcios", "hover");
	  attachSubMenus("voltas", "subMenuVoltas", "hover");
	  attachSubMenus("contactos", "subMenuContactos", "hover");
      break;
    case "ocios":
	  attachSubMenus("ocios", "subMenuOcios", "current");
	  attachSubMenus("voltas", "subMenuVoltas", "hover");
	  attachSubMenus("contactos", "subMenuContactos", "hover");
	  myCurrent = "subMenuOcios"
	  addOnLoad(function() {showNow("ocios", "subMenuOcios");});
      break;
	 case "voltas":
	  attachSubMenus("ocios", "subMenuOcios", "hover");
	  attachSubMenus("voltas", "subMenuVoltas", "current");
	  attachSubMenus("contactos", "subMenuContactos", "hover");
	  myCurrent = "subMenuVoltas"
	  addOnLoad(function() {showNow("voltas", "subMenuVoltas");});
      break;
	  case "contactos":
	  attachSubMenus("ocios", "subMenuOcios", "hover");
	  attachSubMenus("voltas", "subMenuVoltas", "hover");
	  attachSubMenus("contactos", "subMenuContactos", "current");
	  myCurrent = "subMenuContactos"
	  addOnLoad(function() {showNow("contactos", "subMenuContactos");});
      break;
  }
}

// ----- Attach to menu and submenu -----

function attachSubMenus(parent, child, showtype)
{
  p = document.getElementById(parent);
  c = document.getElementById(child);

  p["pai"] = parent;
  p["filho"] = child;
  
  c["pai"] = parent;
  c["filho"] = child;

  c.style.position   = "absolute";
  c.style.visibility = "hidden";

  switch (showtype)
  {
    case "hover":
	  p.onmouseover = prepareShow;
      p.onmouseout  = hideSubMenu;
      c.onmouseover = prepareShow;
      c.onmouseout  = hideSubMenu;
      break;
    case "current":
      p.onmouseover = prepareShow;
      c.onmouseover = prepareShow;
      break;	  
  }

}

// ----- Prepare Show -----

function prepareShow()
{
  hideAll();

  showNow(this["pai"], this["filho"]);

  clearTimeout(c["subMenuTimeout"]);
}

function showNow(qualPai, subMenu)
{
  var c = document.getElementById(subMenu);

	switch (qualPai) {
		
    	case "ocios":
			//nada
      		break;
    	case "voltas":	  
	  		//esquerda, depende língua (hardcoded):
	  		switch (myLang) {
    			case "PT":
					c.style.left = 300 + 'px';
					break;
				case "EN":
					c.style.left = 277 + 'px';
					break;
				case "FR":
					c.style.left = 241 + 'px';
					break;
				case "ES":
					c.style.left = 319 + 'px';
					break;
  			}
  
	  		c.style.top = 388+'px';
      		break;
	 	case "contactos":
	 		//nada
      		break;
  }
  
  	//já modifiquei as posições, agora já posso mostrar:
    c.style.visibility = "visible";	
}

// ----- Hide -----

function hideSubMenu()
{
  filho = this["filho"];
  c["subMenuTimeout"] = setTimeout("document.getElementById('"+filho+"').style.visibility = 'hidden'; showNowAfterTimeout()", 333);
}

function showNowAfterTimeout(){
	//apenas se tiver myCurrent (ex: se não for a homepage)
	if (myCurrent != ""){
      pai = this["pai"];
      showNow('"+pai+"', myCurrent);
	}
}

function hideAll(){
	 var c1 = document.getElementById("subMenuOcios");
	 c1.style.visibility = "hidden";
	 
	 var c2 = document.getElementById("subMenuVoltas");
	 c2.style.visibility = "hidden";
	 
	 var c3 = document.getElementById("subMenuContactos");
	 c3.style.visibility = "hidden"; 
}