var genMenu ='';
// cont equivale al numero de filas visibles del menu
var cont;
function ordenMenu(){
	cont=0;
	for(i=0;i<navegacion.length;i++){
		if(i==0){offsetcaixes=0}else{offsetcaixes=1}
		eval('nav' + i + '.moveTo(null,' + ((cont*19)-offsetcaixes) + ')');
		cont++;
	// acciones que asignan los distintos colores del menu de "Servicios"
		for(j=0;j<navegacion2.length;j++){
			if(document.all){eval('nav2' + j + 'Div.style.backgroundColor="'+ eval('elcolor2' + j ) +'"');}
			for(k=0;k<eval('navegacion2' + j).length;k++){
				if(document.all){eval('nav2' + j + k + 'Div.style.backgroundColor="'+ eval('elcolor2' + j + '0') +'"');}
			}
		}
	}
}
// colores de los servicios:
var elcolor20 = "#946132";
var elcolor21 = "#853B6C";
var elcolor22 = "#9B8201";
var elcolor23 = "#D25600";
var elcolor200 = "#CAB099";
var elcolor201 = elcolor200;
var elcolor210 = "#C29DB6";
var elcolor211 = elcolor210;
var elcolor212 = elcolor210;
var elcolor213 = elcolor210;
var elcolor214 = elcolor210;
var elcolor215 = elcolor210;
var elcolor216 = elcolor210;
var elcolor220 = "#CDC180";
var elcolor221 = elcolor220;
var elcolor230 = "#E9AB80";
var elcolor231 = elcolor230;
var elcolor232 = elcolor230;
var elcolor233 = elcolor230;
var elcolor234 = elcolor230;
// acciones de los botones
// aqui venimos siempre que pulsamos un boton
function actuar(actuacion){
	if(actuacion.length==1){eval(actua[actuacion])}
	if(actuacion.length==2){
		accion = eval('actua' + actuacion.substring(0,1) + '[' + actuacion.substring(1,2) + ']')
		eval(accion)
		}
	if(actuacion.length==3){
		accion = eval('actua2' + actuacion.substring(1,2) + '[' + actuacion.substring(2,3) + ']')
		eval(accion)
		}		
}

var menuactual;
var	menu2offset=0;

function mostra(id){
	if(menuactual!=id){
		if(menuactual!=null){
			for(k=0;k<navegacion2.length;k++){
				for(l=0;l<eval('navegacion2' + k + '.length');l++){
					if(eval('nav2' + k + l + '.y')>-20){
						eval('nav2' + k + l + '.moveTo(null,-20)');
						cont--;
						menu2offset++;
					}
				}
			}			
			for(j=0;j<eval('navegacion' + menuactual + '.length');j++){
				eval('nav' + menuactual + j + '.moveTo(null,-20)');
				cont--
			}
			for(i=(menuactual+1);i<navegacion.length;i++){
				eval('nav' + i + '.moveBy(null,-'+ (eval('navegacion' + menuactual + '.length')+menu2offset)*19 +')')
			}
			// como escondo todos los menus, reinicio las variables de control de estado
			menuactual=null;
			menuactual2=null;
			menu2offset=0;
			setTimeout('mostra(' + id + ')',100);
		}else{
			for(i=(id+1);i<navegacion.length;i++){
				eval('nav' + i + '.moveBy(null,'+ eval('navegacion' + id + '.length')*19 +')')
			}
			for(j=0;j<eval('navegacion' + id + '.length');j++){
				eval('nav' + id + j + '.moveTo(null,(nav' + id + '.y +19)+(j*19)' +')');
				cont++
			}
			//reposiciono el menu perque es vegi
			//menu.moveTo(null,-id*19)
			//menuactual indica el número de opcion de 1er nivel seleccionada ahora
			menuactual=id;
		}
	}else{
		for(k=0;k<navegacion2.length;k++){
			for(l=0;l<eval('navegacion2' + k + '.length');l++){
				if(eval('nav2' + k + l + '.y')>-20){
					eval('nav2' + k + l + '.moveTo(null,-20)');
					cont--
					menu2offset++;
				}
			}
		}
		for(j=0;j<eval('navegacion' + id + '.length');j++){
			eval('nav' + id + j + '.moveTo(null,-20)');
			cont--
		}
		for(i=(id+1);i<navegacion.length;i++){
			eval('nav' + i + '.moveBy(null,-'+ (eval('navegacion' + id + '.length')+menu2offset)*19 +')')
		}
		//menu.moveTo(null,0)
		// como escondo todos los menus, reinicio las variables de control de estado
		menu2offset=0;
		menuactual=null;
		menuactual2=null;
	}	
}
// opcions de 3er nivell ----------------------------------------------------------------------
var menuactual2;
function mostra2(id){
	if(menuactual2!=id){
		if(menuactual2!=null){
			for(j=0;j<eval('navegacion2' + menuactual2 + '.length');j++){
				eval('nav2' + menuactual2 + j + '.moveTo(null,-20)');
				cont--
			}
			for(i=(menuactual2+1);i<navegacion2.length;i++){
				eval('nav2' + i + '.moveBy(null,-'+ eval('navegacion2' + menuactual2 + '.length')*19 +')')
			}
			// el 4 como incio del for esta para mover todo lo que hay despues del menu de servicios
			for(h=3;h<navegacion.length;h++){
				eval('nav' + h + '.moveBy(null,-'+ eval('navegacion2' + menuactual2 + '.length')*19 +')')
			}		
			menuactual2=null;
			setTimeout('mostra2(' + id + ')',100);
		}else{
			for(h=3;h<navegacion.length;h++){
				eval('nav' + h + '.moveBy(null,'+ eval('navegacion2' + id + '.length')*19 +')')
			}		
			for(i=(id+1);i<navegacion2.length;i++){
				eval('nav2' + i + '.moveBy(null,'+ eval('navegacion2' + id + '.length')*19 +')')
			}
			for(j=0;j<eval('navegacion2' + id + '.length');j++){
				eval('nav2' + id + j + '.moveTo(null,(nav2' + id + '.y +19)+(j*19)' +')');
				cont++
			}
			//reposiciono el menu perque es vegi "servicios"
			//menu.moveTo(null,-3*19)
			//menuactual indica el número de opcion de 3er nivel seleccionada ahora
			menuactual2=id;
		}
	}else{
		for(j=0;j<eval('navegacion2' + id + '.length');j++){
			eval('nav2' + id + j + '.moveTo(null,-20)');
			cont--
		}
		for(i=(id+1);i<navegacion2.length;i++){
			eval('nav2' + i + '.moveBy(null,-'+ eval('navegacion2' + id + '.length')*19 +')')
		}
		for(h=3;h<navegacion.length;h++){
			eval('nav' + h + '.moveBy(null,-'+ eval('navegacion2' + id + '.length')*19 +')')
		}
		//seleccion=seleccion.substring(0,2);
		menuactual2=null;
	}	
}
// --------------------------------------------------------------------------------------------
// el id.length color es el color del rollover dependiendo del nivel de profundidad del menu
function rollover(id){
	if(id.length==1){color='#DDE6F0'}
	if(id.length==2){
		// cuando abrimos "servicios"
		if(id.substring(0,1)==2){
				switch(id.substring(1,2)){
					case '0':color='#764E28';break
					case '1':color='#6A2F56';break
					case '2':color='#7C6801';break
					case '3':color='#A84500';break												
					default:break;
				}
		//color='#FFFFFF'
		}else{
		color='#D9DEED'
		}
	}
	if(id.length==3){
		// cuando abrimos dentro de "servicios"
			switch(id.substring(1,2)){
				case '0':color='#E5D8CC';break
				case '1':color='#E1CEDB';break
				case '2':color='#E6E0C1';break
				case '3':color='#F4D5C0';break												
				default:break;
			}
	}
	// este if es para que no se ilumine el boton de CANALAlimentación
	if(id!='5'){
		if(document.all){
			eval('nav' + id + 'Div.style.backgroundColor="'+color+'"');
		}
	}
}
function rollout(id){
	if(id.length==1){color='#FFFFFF'}
	if(id.length==2 && id.substring(0,1)!=2){color='#F1F1F1'}
	if(id.length==2 && id.substring(0,1)==2){color=eval('elcolor' + id)}
	if(id.length==3){color=eval('elcolor' + id.substring(0,2) + '0')}
	// este if es para que no se ilumine el boton de CANALAlimentación
	if(id!='5'){
		if(document.all){
			eval('nav' + id + 'Div.style.backgroundColor="'+color+'"');
		}
	}
}

var scrollTime;
function scrollup(){
	if(menu.y>=0){
		menu.moveTo(null,0);
		arrowu.hide();
		clearTimeout(scrollTime)
	}else{
		menu.moveBy(null,1);
		arrowu.show();
		scrollTime = setTimeout('scrollup();',20)		
	}
}
function scrolldown(){
	// cont es el numero de filas que tiene el menu
	// 19 es su altura
	//200 es la altura total de la caja del menu
	if(menu.y<=-((cont*19)-200)){
		menu.moveTo(null,-((cont*19)-200));
		arrowd.hide();
		clearTimeout(scrollTime)
	}else{
		menu.moveBy(null,-1);
		arrowd.show();
		scrollTime = setTimeout('scrolldown();',20)		
	}
}
function scrollControl(){
	// cont es el numero de filas que tiene el menu
	// 19 es su altura
	//200 es la altura total de la caja del menu
	if(menu.y>=0){arrowu.hide()}else{arrowu.show()}
	if(menu.y<=-((cont*19)-200)){arrowd.hide()}else{arrowd.show()}
	setTimeout('scrollControl()',100)
}
function ira(donde){
	parent.main.document.location = 'zprueba.htm?pag=' + donde;
}

// generacio dels menus
			for(i=0;i<navegacion.length;i++){
				//creacion del menu
				genMenu += '<DIV ID="nav' + i + 'Div" CLASS="nav">';
							genMenu +='<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0>';
								genMenu +='<TR><TD BGCOLOR="#A30131" COLSPAN=2><IMG SRC="images/pix_trans.gif" WIDTH="199" HEIGHT="1" ALT="" BORDER="0"></TD></TR>';
								if (navegacion[i] == '<IMG SRC="images/bt_canala.gif" alt="">'){
									genMenu +='<TR><TD WIDTH=1 BGCOLOR="white"><IMG SRC="images/pix_trans.gif" WIDTH="1" HEIGHT="18" ALT="" BORDER="0"></TD>';
								}else{
									genMenu +='<TR><TD WIDTH=1 BGCOLOR="#A30131"><IMG SRC="images/pix_trans.gif" WIDTH="1" HEIGHT="18" ALT="" BORDER="0"></TD>';
								}
								if (navegacion[i] == "SERVICIOS"){
									genMenu +='<TD WIDTH=100%" BGCOLOR="#A30131"><table border=0 cellpadding=0 cellspacing=0><td><span class="txtservicios">&nbsp;' + navegacion[i] + '<span></TD></TABLE></TD></TR>';
								}
								else{
									if (navegacion[i] == '<IMG SRC="images/bt_canala.gif" alt="">'){
										genMenu +='<TD CLASS="bts" WIDTH=100%"><br>' + navegacion[i] + '</TD></TR>';
									}else if(navegacion[i] == 'hola'){
										genMenu +='<TD BGCOLOR="#A30131"><table border=0 cellpadding=0 cellspacing=0><td><a href="default.htm" target="_top"><img src="images/ic_home3.gif" width="13" height="13" border="0" ALT="página de inicio" name="home"></a></td><td><img src="images/pix_trans.gif" width="3" height="1" border="0"></td><td><a href="fr_contacte.htm" target="principal" onClick="colorea(3)"><img src="images/ic_mail3.gif" width="16" height="13" border="0" ALT="contacte con nosotros" name="contact"></a></td></table></td></TR>'
									}else{
										genMenu +='<TD CLASS="bts" WIDTH=100%">&nbsp;' + navegacion[i] + '</TD></TR>';
									}
								}
								genMenu +='<TR><TD BGCOLOR="white" COLSPAN=2><IMG SRC="images/pix_trans.gif" WIDTH="164" HEIGHT="1" ALT="" BORDER="0"></TD></TR>'
							+'</TABLE>';
							if(eval('navegacion' + i + '.length')>0){
								if (navegacion[i] == "SERVICIOS"){
									genMenu +='<DIV CLASS="btTrans"><A HREF="javascript:actuar(\'' + i + '\')" onmouseover="rollover(\'' + i + '\')" onmouseout="rollout(\'' + i + '\')"><IMG SRC="images/pix_scroll2.gif" WIDTH="199" HEIGHT="18" ALT="" BORDER="0"></A></DIV>'						
								}else{
									genMenu +='<DIV CLASS="btTrans"><A HREF="javascript:actuar(\'' + i + '\')" onmouseover="rollover(\'' + i + '\')" onmouseout="rollout(\'' + i + '\')"><IMG SRC="images/pix_scroll.gif" WIDTH="199" HEIGHT="18" ALT="" BORDER="0"></A></DIV>'								
								}
							}else{
								if (navegacion[i] == '<IMG SRC="images/bt_canala.gif" alt="">'){
									genMenu +='<DIV CLASS="btTrans"><br><A HREF="javascript:actuar(\'' + i + '\')" onmouseover="rollover(\'' + i + '\')" onmouseout="rollout(\'' + i + '\')"><IMG SRC="images/pix_trans.gif" WIDTH="199" HEIGHT="18" ALT="Conozca la web para profesionales de la Industria Alimentaria" BORDER="0"></A></DIV>'
								}else if(navegacion[i] == 'hola'){
										genMenu +=''
								}else{
									genMenu +='<DIV CLASS="btTrans"><A HREF="javascript:actuar(\'' + i + '\')" onmouseover="rollover(\'' + i + '\')" onmouseout="rollout(\'' + i + '\')"><IMG SRC="images/pix_trans.gif" WIDTH="199" HEIGHT="18" ALT="" BORDER="0"></A></DIV>'
								}
							}
						genMenu +='</DIV>';
				//creacion del submenu de primer nivel
				if(eval('navegacion' + i + '.length')>0){
					for(j=0;j<eval('navegacion' + i + '.length');j++){
						genMenu += '<DIV ID="nav' + i + j + 'Div" CLASS="nav1">'
							+'<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0>'
								+'<TR><TD BGCOLOR="#B2B2B2" COLSPAN=2><IMG SRC="images/pix_trans.gif" WIDTH="199" HEIGHT="1" ALT="" BORDER="0"></TD></TR>'
								+'<TR><TD WIDTH=1 BGCOLOR="#A30131"><IMG SRC="images/pix_trans.gif" WIDTH="1" HEIGHT="18" ALT="" BORDER="0"><BR></TD>';
								if(i==2){genMenu+='<TD CLASS="bts2" WIDTH=200>&nbsp;&nbsp;&nbsp;' + eval('navegacion' + i + '[j]') + '</TD></TR>'}
								else{if((i==1)||(i==3)) {genMenu+='<TD  WIDTH=200><TABLE CELLPADDING=0 CELLSPACING=0 BORDER=0 WIDTH=100%><TD WIDTH=25><IMG SRC="images/bullet_bot2.gif" HEIGHT="19" BORDER="0"></TD><TD><IMG SRC="images/pix_trans.gif" WIDTH=2 BORDER="0"></TD><TD CLASS="bts" ALIGN="left" WIDTH=173>' + eval('navegacion' + i + '[j]') + '</TD></TABLE></TD></TR>'}
								else{genMenu+='<TD CLASS="bts" WIDTH=200>&nbsp;' + eval('navegacion' + i + '[j]') + '</TD></TR>'}}
								genMenu+='<TR><TD BGCOLOR="#B2B2B2" COLSPAN=2><IMG SRC="images/pix_trans.gif" WIDTH="199" HEIGHT="1" ALT="" BORDER="0"></TD></TR>'
							+'</TABLE>';
							if(i==2){
							genMenu +='<DIV CLASS="btTrans"><A HREF="javascript:actuar(\'' + i + "" + j + '\')" onmouseover="rollover(\'' + i + "" + j +'\')" onmouseout="rollout(\'' + i + "" + j +'\')"><IMG SRC="images/pix_scroll.gif" WIDTH="199" HEIGHT="18" ALT="" BORDER="0"></A></DIV>'
							}else{
							genMenu +='<DIV CLASS="btTrans"><A HREF="javascript:actuar(\'' + i + "" + j + '\')" onmouseover="rollover(\'' + i + "" + j +'\')" onmouseout="rollout(\'' + i + "" + j +'\')"><IMG SRC="images/pix_trans.gif" WIDTH="199" HEIGHT="18" ALT="" BORDER="0"></A></DIV>'
							}
						genMenu +='</DIV>';
					//creacion del submenu de segundo nivel de los servicios : navegacion3.length
						if(i==2){
							for(k=0;k<eval('navegacion2' + j + '.length');k++){
								genMenu += '<DIV ID="nav2' + j + k + 'Div" CLASS="nav2">'
									+'<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0>'
									if(k==eval('navegacion2' + j + '.length-1')){
										genMenu+='<TR><TD><IMG SRC="images/bullet_bot.gif" HEIGHT="19" ALT="" BORDER="0"></TD>'									
										}else{
										genMenu+='<TR><TD><IMG SRC="images/bullet_mid.gif" HEIGHT="19" ALT="" BORDER="0"></TD>'
									}
										genMenu +='<TD CLASS="bts2" WIDTH=199>' + eval('navegacion2' + j + '[k]') + '</TD></TR>'
										+'<TR><TD COLSPAN=2><IMG SRC="images/pix_trans.gif" WIDTH="164" HEIGHT="1" ALT="" BORDER="0"></TD></TR>'
									+'</TABLE>'
									+'<DIV CLASS="btTrans"><A HREF="javascript:actuar(\'2' + j + "" + k + '\')" onmouseover="rollover(\'2' + j + "" + k +'\')" onmouseout="rollout(\'2' + j + "" + k +'\')"><IMG SRC="images/pix_trans.gif" WIDTH="199" HEIGHT="18" ALT="" BORDER="0"></A></DIV>'
								+'</DIV>';
							}
						}
					}
				}
			}