//****************************************************************************************
// Item 
// Usage: a = new dItem({id:2, clase:'clase', caption:'caption', ....});
//****************************************************************************************
function dItem(arrayProps) {
	//campos obligatorios
	this.id;          
	this.caption;
    this.tipo;
    //campos opcionales
	this.url;         //url to open
	this.target;      //target to open url
	this.onClick;     //javascript to execute onclick
	this.profundidad = 0;

	this._children = []; 
	this._parent; 
	this._mymnu; 
    
	for (i in arrayProps)	{
		if (i.charAt(0) != '_')		{
			eval('this.'+i+' = arrayProps[\''+i+'\'];');
		}
	}
}
//****************************************************************************************
//****************************************************************************************
//****************************************************************************************
//****************************************************************************************
//****************************************************************************************
// Mi_mnu 
//Usage: t = new dMi_mnu({name:t, style:''});
//****************************************************************************************
function dMi_mnu(arrayProps) {
	//campos obligatorios
	this.name;
	//campos privados
	this._root; 
	this._aItems = [];
	for (i in arrayProps)	{
		if (i.charAt(0) != '_')		{
			eval('this.'+i+' = arrayProps[\''+i+'\'];');
		}
	}
}
//****************************************************************************************
// Busca el nodo en el array y devuelve su posicion
//****************************************************************************************
dMi_mnu.prototype._searchItem = function(id) {
	var a=0;
	for (a;a<this._aItems.length;a++) 	{
		if (this._aItems[a].id == id) 	{
			return a;
		}
	}
	return false;
}
//****************************************************************************************
//add item
//****************************************************************************************
dMi_mnu.prototype.add = function(item,pid) {
	var auxPos;
	var addItem = false;
	if (typeof (auxPos = this._searchItem(item.id)) != "number") 	{
        //Compruebo que no exista ya un nodo con ese mismo id
		if (typeof (auxPos = this._searchItem(pid)) == "number")		{
                        // Busco el padre y lo encuentro con lo que lo aņado como hijo
			item._parent = this._aItems[auxPos];
			item.profundidad = item._parent.profundidad +1;
			this._aItems[auxPos]._children[this._aItems[auxPos]._children.length] = item;
			addItem = true;
		}	else  {
                        //Como el padre no ha podido ser encontrado depender  del root
			if (this._root == null)	{
				this._root = item;
				this.profundidad = 1;
				addItem = true;
			}
		}
		if (addItem)		{
			this._aItems[this._aItems.length] = item;
			item._mymnu = this;
		}
	} 
}
//****************************************************************************************
//****************************************************************************************
dMi_mnu.prototype.draw = function() {
	if (!getObjectById("dmimnu_"+this.name))	{
		document.write('<div id="dmimnu_'+this.name+'"></div>');
	}
	if (this._root != null) 	{
    	this._root._draw();
		this._drawBranch(this._root._children);
	}
}
//****************************************************************************************
// Funciones axiliares
//****************************************************************************************
//For multi-browser compatibility
//****************************************************************************************
function getObjectById(name) {   
    if (document.getElementById)   {
        return document.getElementById(name);
    }   else if (document.all)   {
        return document.all[name];
    }  else if (document.layers)   {
        return document.layers[name];
    }
    return false;
}
//****************************************************************************************
//****************************************************************************************
function PonerItems(capa,id_item) {
    var raiz;
    var contenido = "";
    if (id_item=='0') id_item = mimnu._aItems[0].id;
    raiz = mimnu._searchItem(id_item);
    for (a=0;a<mimnu._aItems[raiz]._children.length;a++) {
        contenido = contenido + '<div style="margin-top:5px; margin-left:10px; margin-right:5px;">';
        if (mimnu._aItems[raiz]._children[a].tipo=='c') {
            if (mimnu._aItems[raiz]._children[a]._children.length > 0) {
                contenido = contenido + '<a href="" class="link" OnClick=\'PonerItems('+ (mimnu._aItems[raiz]._children[a].profundidad + 1) + ',"' + mimnu._aItems[raiz]._children[a].id +'"); return false;\'><img src="/99_img/flecha_derecha.gif" border="0" /> ' + mimnu._aItems[raiz]._children[a].caption + '</a>';
            } else {
                contenido = contenido + mimnu._aItems[raiz]._children[a].caption;
            }
        } else {
            contenido = contenido + '<a href="/02_proyectos/proyecto.jsp?id_proyecto=' + mimnu._aItems[raiz]._children[a].id.substring(1) + '" class="linklight">&bull; ' + mimnu._aItems[raiz]._children[a].caption + '</a>';
        }
        contenido = contenido + '</div>';
    }
    document.getElementById("mnu"+ capa ).innerHTML = contenido;
    VerMnu(capa);    
}
//****************************************************************************************
function VerMnu(opcion) {
    //Primero borramos las que esten abiertas
    for (i=3;i>opcion;i--) {
        eval("fadeOut('mnu"+i+"',85,0);");
    }
    //Ahora venos los menus seleccionados
    for (i=1;i<opcion+1;i++) {
        eval("fadeIn('mnu"+i+"',0,85);");
    }
}
//****************************************************************************************
function CrearMnu(base) {
    div = document.createElement('div');
    div.id = 'top_mnu1';
    div.style.position = 'absolute';
    div.style.height = '14px';
    div.style.width = '268px';
    div.style.left='0px';
    div.style.top='0px';
    div.style.backgroundColor="#FFFFFF";
    if (ie5) div.style.filter = "alpha(opacity=85)";
    if (ns6) div.style.MozOpacity = '.85';
    div.style.visibility='hidden';
    //div.innerHTML='<a href="" style="margin-left:10px;" OnClick="VerMnu(1); return false;" class="link">Nombre 1</a>';
    document.getElementById(base).appendChild(div);
    //******************
    div = document.createElement('div');
    div.id = 'mnu1';
    div.style.position = 'absolute';
    div.style.height = '209px';
    div.style.width = '268px';
    div.style.left='0px';
    div.style.top='15px';
    div.style.overflow='auto';
    div.style.backgroundColor="#FFFFFF";
    div.style.visibility='hidden';
    if (ie5) div.style.filter = "alpha(opacity=0)";
    if (ns6) div.style.MozOpacity = '.0';
    document.getElementById(base).appendChild(div);
    //***************************************************
    //***************************************************
    //***************************************************
    div = document.createElement('div');
    div.id = 'top_mnu2';
    div.style.position = 'absolute';
    div.style.height = '14px';
    div.style.width = '268px';
    div.style.left='272px';
    div.style.top='0px';
    div.style.backgroundColor="#FFFFFF";
    div.innerHTML='';
    if (ie5) div.style.filter = "alpha(opacity=85)";
    if (ns6) div.style.MozOpacity = '.85';
    div.style.visibility='hidden';
    document.getElementById(base).appendChild(div);
    //******************
    div = document.createElement('div');
    div.id = 'mnu2';
    div.style.position = 'absolute';
    div.style.height = '209px';
    div.style.width = '268px';
    div.style.left='272px';
    div.style.top='15px';
    div.style.overflow='auto';
    div.style.backgroundColor="#FFFFFF";
    if (ie5) div.style.filter = "alpha(opacity=0)";
    if (ns6) div.style.MozOpacity = '.0';
    document.getElementById(base).appendChild(div);
    //****************************************************
    div = document.createElement('div');
    div.id = 'top_mnu3';
    div.style.position = 'absolute';
    div.style.height = '14px';
    div.style.width = '270px';
    div.style.left='544px';
    div.style.top='0px';
    div.style.backgroundColor="#FFFFFF";
    div.innerHTML='';
    if (ie5) div.style.filter = "alpha(opacity=85)";
    if (ns6) div.style.MozOpacity = '.85';
    div.style.visibility='hidden';
    document.getElementById(base).appendChild(div);
    //******************
    div = document.createElement('div');
    div.id = 'mnu3';
    div.style.position = 'absolute';
    div.style.height = '209px';
    div.style.width = '270px';
    div.style.left='544px';
    div.style.top='15px';
    div.style.overflow='auto';
    div.style.backgroundColor="#FFFFFF";
    if (ie5) div.style.filter = "alpha(opacity=0)";
    if (ns6) div.style.MozOpacity = '.0';
    document.getElementById(base).appendChild(div);
}