/****************************
Copyright MAGACOR 2006
****************************/
addEvent( window, 'load', load );
var popID;
var tID;
var flash;
function load() {
inMenu = false;
flash = getNode( "flash" );
body = document.getElementsByTagName( "body" )[0];
last = null;
if( getNode( "inicio" ) == null ) return;
var ini  = new MenuP( getNode( "inicio" ));
var lac  = new MenuP( getNode( "lacompania" ));
var esp	  = new MenuP( getNode( "espectaculos" ));
var otr  = new MenuP( getNode( "otroseventos" ));
var gir   = new MenuP( getNode( "gira" ));
var mis   = new MenuP( getNode( "miscelaneas" ));
var con  = new MenuP( getNode( "contacto" ));

ini.create();
lac.add( new Menu( "Historia", "bambalua/la_historia.htm" ) );
lac.add( new Menu( "Lineas teatrales", "bambalua/la_lineas.htm" ) );
lac.add( new Menu( "El equipo", "bambalua/la_elequipo.htm" ) );
lac.add( new Menu( "Ferias y Festiv.", "bambalua/la_ferias.htm" ) );
lac.create();
esp.add( new Menu( "Teatro de Sala", "bambalua/es_sala.htm" ) );
esp.add( new Menu( "Teatro de Calle", "bambalua/es_calle.htm" ) );
esp.add( new Menu( "Teatro en Patrimonio", "bambalua/es_patri.htm" ) );
esp.add( new Menu( "Cabalgatas", "bambalua/es_cabalgatas.htm" ) );
esp.add( new Menu( "Cuenta Cuentos", "bambalua/es_cuenta.htm" ) );
esp.create();
otr.add( new Menu( "Parque de Mero", "bambalua/ot_parque.htm" ) );
otr.add( new Menu( "Carpa de Humor", "bambalua/ot_carpa.htm" ) );
otr.add( new Menu( "Emisarios Reales", "bambalua/otros.htm" ) );
otr.add( new Menu( "Espacion no convencionales", "bambalua/ot_noconvencionales.htm" ) );
otr.create( );
gir.add( new Menu( "Aņo 2010", "bambalua/gi_2010.htm" ) );
gir.add( new Menu( "Aņo 2009", "bambalua/gi_2009.htm" ) );
gir.add( new Menu( "Aņo 2008", "bambalua/gi_2008.htm" ) );
gir.add( new Menu( "Aņo 2007", "bambalua/gi_2007.htm" ) );

gir.create( );
mis.add( new Menu( "Noticias", "bambalua/mi_noticias.htm" ) );
mis.add( new Menu( "Fotos recuerdo", "bambalua/mi_fotos.htm" ) );
mis.add( new Menu( "Dosier Prensa", "bambalua/mi_prensa.htm" ) );
mis.add( new Menu( "Descargas", "bambalua/mi_descargas.htm" ) );
mis.add( new Menu( "Enlaces", "bambalua/mi_enlaces.htm" ) );
mis.add( new Menu( "Mapa Web", "bambalua/mi_mapa.htm" ) );
mis.add( new Menu( "Legalidad", "bambalua/mi_legalidad.htm" ) );
mis.add( new Menu( "Accesibilidad", "bambalua/mi_accesibilidad.htm" ) );
mis.add( new Menu( "WEB-MAIL", "http://www.bambaluateatro.com:2095/3rdparty/roundcube/?_task=mail") );

mis.create( );
con.add( new Menu( "Datos", "bambalua/co_datos.htm" ) );
con.add( new Menu( "Formulario", "bambalua/co_formulario.htm" ) );
con.create();

}
function MenuP ( node ) {
this.node = node;
this.menuItems = new Array();
MenuP.prototype.add = function( menuItem ) {
this.menuItems[ this.menuItems.length ] = menuItem;	
}
MenuP.prototype.create = function( ) {
var dNode = document.createElement( "div" );
dNode.className = "jsMenu";
var str = "_" + this.node.id;
dNode.setAttribute( "id", str );
var w = this.node.offsetWidth;
dNode.style.width = w > 160 ? w+"px" : "160px";
dNode.style.top = ( this.node.offsetTop + this.node.offsetHeight ) + "px";
dNode.style.left = this.node.offsetLeft + "px";
addEvent( this.node, "mouseover", function() { showMenuInTime(str, 150) } );
addEvent( this.node, "mouseout", function() { setInMenu(false) } );
dNode.setAttribute( "pItemID", this.node.id );
addEvent( dNode, "mouseover", function() { setInMenu(true) } );
addEvent( dNode, "mouseout", function() { setInMenu(false) } );
var html = "<ul>";
for( var i=0; i<this.menuItems.length; i++ ) {
	html += this.menuItems[i].getLinkHTML();
}
body.appendChild( dNode );
dNode.innerHTML = html + "</ul>";
}
}
function Menu( value, href ) {
this.value = ( value == null ) ? "" : value;
this.href = ( href == null ) ? "" : href;
if( this.href != "" && typeof useAbsPath != "undefined" )
	if( useAbsPath && this.href.indexOf( "http://" ) == -1 && this.href.indexOf( "https://" ) == -1 )
		this.href = "http://www.bambaluateatro.com" + this.href;
Menu.prototype.getLinkHTML = function () {
	if( this.value != "" && this.href != "" )
		return "<li><a onclick=\"setInMenu(false); hideMenu(); return true;\" href=\"" + this.href + "\">" + this.value + "</a></li>";
	else if( this.value != "" && this.href == "" )
		return "<li class='heading'>" + this.value + "</li>";
	else
		return "<li class='separator'>&nbsp;</li>";
}
}
function showMenuInTime( node, time ) {
popID = setTimeout( "showMenu('" + node + "')", time );
}
function showMenu( node ) {
clearTimeout( popID );
if( typeof node == "string" )
	node = getNode( node );
if( last != null && last != node )
	hideMenu( last );
else if( last == node ) {
	setInMenu( true );
	return;
}
var pItem = getNode( node.getAttribute( "pItemID" ) );
var menuLeft = 0;
var menuTop = pItem.offsetHeight;
var tmp = pItem;
while(tmp!=null && tmp.tagName!="BODY") {
	if( tmp.tagName == "html:body" ) break;
	
	menuLeft += tmp.offsetLeft;
	menuTop  += tmp.offsetTop;
	tmp = tmp.offsetParent;
}
node.style.left = menuLeft + "px";
node.style.top = menuTop + "px";
var w = pItem.offsetWidth;
node.style.width = w > 160 ? w+"px" : "160px";
node.style.display = "block";	
setInMenu( true );
last = node;
if( flash != null )	flash.style.visibility = "hidden";
tID = setTimeout( "hideMenu( last )", 100 );
}
function hideMenu( node ) {
if( node == null ) {
	setInMenu( false );
	hideMenu( last );
	return;
}
if( typeof node == "string" )
	node = getNode( node );
if( !inMenu ) {
	node.style.display = "none";
	var pItem = getNode( node.getAttribute( "pItemID" ) );
	last = null;
	clearTimeout( tID );
	if( flash != null )	flash.style.visibility = "visible";
} else
	tID = setTimeout( "hideMenu( last )", 100 );	
}
function setInMenu( value ) {
inMenu = value;	
if( !value ) clearTimeout( popID );
}
function addEvent( node, evtType, func ) {
if( node.addEventListener ) {
	node.addEventListener( evtType, func, false );
	return true;
} else if( node.attachEvent )
	return node.attachEvent( "on" + evtType, func );
else
	return false;
}
function getNode( nodeId ) {
if( document.getElementById )
	return document.getElementById( nodeId );
else if( document.all && document.all( nodeId ) )
	return document.all( nodeId );
else if( document.layers && document.layers[ nodeId ] )
	return document.layers[ nodeId ];
else
	return false;
}

