var pos = new Array();



//alert("len es " + len);
for(var i=0; i<blocsArray.length; i++){
	if(blocsArray[i]!="") pos[i] = blocsArray[i];
}
var totalNiveles = pos.length;


function menuTitol() {
	var st = '';
	st += '<table height="22" cellpadding="0" cellspacing="0" border="0">';
	st += '<tr>';
	st += '<td><img src="img/cp.gif" width="20" height="1"><img src="img/title_menu_'+pos[0]+'.gif" border="0"></td>';
	st += '</tr>';
	st += '</table>';
	return(st);
}

function primerObj(obj) {
	var i
	for (i in obj) {
		if (i!='_nom') return i
	}
	return false;
}

function menuRec(lobj,lniv,lpref) {

	// Característica del menu:
	// cuando estamos en el ter nivel, el nivel 2 padre ha de poder ser linkable,
	// porque en sí mismo ya es contenido.
	// Es decir, aqui :
	// menu
	//  - submenu 1
	//      - subsubmenu 1 (link clicado)
	//      - subsubmenu 2
	//  - submenu 2
	//
	// Hemos de poder clicar en "submenu1"
	
	
	var niv = 0; // "niv" representa el nivel actual de profundidad del menu en el que nos encontramos.
	var i = 0;
	var pre = '';
	var pref = '';
	var nivf = '';
	var st = '';
	var obj = ps;

		
	if (lobj) obj = lobj;
	if (lniv) niv = lniv;
	if (lpref) { pref = lpref; }
	for (i=0; i<niv; i++) pre += '-';
	//alert("Antes del for")
	for (i in obj) {
		//alert(i+" :: "+niv)
		if (i!="_nom") {
			//alert("Entro en el if")
			var sobj = ps[i];
			
			if (niv==1){
				st += '<table width="220" cellpadding="0" cellspacing="0" border="0">';
				st += '<tr>';
			 }
			if (niv==0) {
				st += '<table width="220" cellpadding="0" cellspacing="0" border="0">';
				st += '<tr>';
				nivf = niv + 1;
			}
			if (niv==2) {
				st += '<table width="220" cellpadding="0" cellspacing="0" border="0">';
				st += '<tr>';
			}

			switch (niv) {
				case 0:
					
					var posit = 0;
					for(var j in obj[i]){
						posit++;
						if(posit == 2) var primero = j; 
					}
					if (i==pos[niv]) {
						st += '<td width="0%" height="21" bgcolor="#003893" align="center"><img src="img/cp.gif" height="1" width="5"><img src="img/flecha_blanca.gif" border="0"></td>';
						st += '<td width="100%" height="21" class="S10" bgcolor="#003893"><img src="img/cp.gif" height="1" width="5"><span class="S10bl"><b>' + obj[i]._nom + '</b></span></td>';
						st += '<tr><td height="1"><img src="img/cp.gif" height="1" width="1"></td></tr>';

					}else{
						// Hemos de mirar si el objeto a inspeccionar tiene "hijos" o no.
						// En caso de que no tenga hijos, queremos que el link vaya a su propia pagina,
						// En caso de que tenga algún "hijo", queremos que direccione hacia el primer
						// item del menú.
						var existePrimero=primerObj(obj[i]);
						if((pref+i) == "ini"){
							// correccion para el index, en este caso extraordinario, el link lo queremos
							// direccionar a index.htm
						 	dest = "index";
						 }else if(existePrimero){
							 // Si existe primero hacemos el link convinado con el primer elemento "hijo"
						 	dest = i + "_" + existePrimero;
						 }else{
							 // Si no existe primero, linkamos a "el mismo"
 						 	dest = (pref + i);
						 }
						st += '<td width="0%" height="21" bgcolor="#779EC7" align="center"><img src="img/cp.gif" height="1" width="5"><img src="img/flecha_blanca.gif" border="0"></td>';
						st += '<td width="100%" height="21" class="S10" bgcolor="#779EC7"><img src="img/cp.gif" height="1" width="5"><a href="'+dest+'.htm" class="linkMenuInerior" ><b>' + obj[i]._nom + '</b></a></td>';
						st += '<tr><td height="1"><img src="img/cp.gif" height="1" width="1"></td></tr>';
					}
					break;
				case 1:
					if (i==pos[niv]) {
					//alert("totalNiveles " + totalNiveles);
					
						if(totalNiveles==3){
							st += '<td width="20" bgcolor="#FFFFFF" height="18" ><img src="img/cp.gif" width="10"></td>';
							st += '<td width="10" height="18"><img src="img/flecha_roja.gif" border="0"></td>';
							st += '<td width="4" height="18"><img src="img/cp.gif" width="4"></td>';
							st += '<td width="100%" class="S10" height="18"><a href="'+(pref+i)+'.htm" class="linkMenuInerior2_ac"><b>' + obj[i]._nom + '</b></a></td>';
						}else{
							st += '<td bgcolor="#FFFFFF" height="18" ><img src="img/cp.gif" width="10"></td>';

							if (obj[i]._nom.indexOf('Pie')<=0){	
								st += '<td width="10" height="18"><img src="img/flecha_roja.gif" border="0"></td>';
								st += '<td width="4" height="18"><img src="img/cp.gif" width="4"></td>';
								st += '<td width="100%" class="S10" height="18"><span class="S10ro"><b>' + obj[i]._nom + '</b></span></td>';
							}
							else{	
								st += '<td width="10" height="30" valign="top"><img src="img/flecha_roja.gif" border="0" STYLE="margin-top:5px;"></td>';
								st += '<td width="4" height="18"><img src="img/cp.gif" width="4"></td>';
								st += '<td STYLE="padding-top:3px;" width="100%" valign="top" class="S10" height="25"><span class="S10ro" ><b>' + obj[i]._nom + '</b></span></td>';
							}

						}
					}else{
						st += '<td width="20" bgcolor="#FFFFFF" height="18" ><img src="img/cp.gif" width="10"></td>';
						
						if (obj[i]._nom.indexOf('Pie')<=0){	
							st += '<td width="10" height="18"><img src="img/flecha_roja.gif" border="0"></td>';
							st += '<td width="4" height="18"><img src="img/cp.gif" width="4"></td>';
							st += '<td width="100%" class="S10" height="18"><a href="'+(pref+i)+'.htm" class="linkMenuInerior2">' + obj[i]._nom + '</a></td>';							
						}
						else{	
							st += '<td width="10" valign="top" height="30" valign="top"><img src="img/flecha_roja.gif" border="0" STYLE="margin-top:5px;"></td>';
							st += '<td width="4" height="18"><img src="img/cp.gif" width="4"></td>';
							st += '<td STYLE="padding-top:3px;" width="100%" valign="top" class="S10" height="25"><a href="'+(pref+i)+'.htm" class="linkMenuInerior2" STYLE="margin-top:10px;">' + obj[i]._nom + '</a></td>';
						}						
						
					}
					break;
				case 2:
					if (i==pos[niv]) {
						st += '<td bgcolor="#FFFFFF" height="18" ><img src="img/cp.gif" width="10"></td>';
						st += '<td width="10" height="18"><img src="img/cp.gif" width="15"></td>';
						st += '<td width="100%" class="S10" height="18"><b><span class="S12ro">· </span></b><span class="S10ro">' + obj[i]._nom + '</span></td>';
					}else{
						st += '<td width="100" bgcolor="#FFFFFF" height="18" ><img src="img/cp.gif" width="10"></td>';
						st += '<td width="10" height="18"><img src="img/cp.gif" width="15"></td>';
						st += '<td width="100%" class="S10" height="18"><b><span class="S12ne">· </span></b><a href="'+(pref+i)+'.htm" class="linkMenuInerior2">' + obj[i]._nom + '</a></td>';
					}
					break;
			}
			if(niv==0) st += '</tr></table>';
			if(niv==1) st += '</tr></table>';
			if(niv==2) st += '</tr></table>';
		}
		//alert('i==pos[niv] i:' + i + " pos[niv] " + pos[niv])
		if (i==pos[niv]) {
			st += menuRec(obj[i],niv+1,pref + i +'_');
		}
	}
	return st;
}

function filetHTML(w,imagen) {
	var st = '';
	st += '<table width="'+w+'" cellpadding="0" cellspacing="0" border="0">';
	st += '<tr>';
	st += '<td background="img/'+imagen+'"><img src="img/cp.gif" width="1" height="1"></td>';
	st += '</tr>';
	st += '</table>';
	return(st);
}//


