/****************************************************************************************************/
/***************************************** IMPORTATANTE *********************************************/
/****************************************************************************************************/
/* Siempre que se utilizen estas librerias en proyectos .NET con paginas aspx hay que tener cuidado */
/* de no poner acentos ni en los comentarios de las librerias ni en los posibles alert que pongamos */
/* en ellas, ya que no funcionarian en Netscape.                                                    */
/****************************************************************************************************/


function pDinamicMenu(matOpc, prefCp, prefMenu){
	//Atributos.
	this.opciones = matOpc;
	this.prefCp = prefCp;
	this.prefMenu = prefMenu;

	this.matImgObj = null;
	this.matCapasObjOff = null;

	return this;
}

// Metodo para escribir el codigo HTML correspondiente a las capas del menu principal.
// Este metodo se debe invocar en el body de la página.
pDinamicMenu.prototype.paint = function() {
	window.status = "pDinamicMenu.paintHead::execute";
	// Debemos crear la cadena de texto con las distintas capas con las opciones principales del menu.	
	var cadHTML = "";
	this.matImgObj = new Array(null, new Array(null), new Array(null));
	
	// Creamos la tapadera.
	cadHTML += "<div id='cp" + this.prefMenu + "Over' style='position:absolute; left:" + 0 + "px; top:" + 0 + "px; width:10px; height:10px; z-index:200; visibility: hidden;'>";
	cadHTML += "<img src='img/pixel.gif' name='" + (this.prefMenu +  0) + "' border='0' id='" + (this.prefMenu +  0) + "'>";
	cadHTML += "</div>";	
	
	for(var i=1;i<=this.opciones.length;i++){
		// Obtencion de objetos imagen de la precarga.
		var cadTmp = this.opciones[i-1][0].split('|');
		var imgTmp = new Image(); imgTmp.src = cadTmp[0];
		this.matImgObj[1][i] = imgTmp;
		imgTmp = new Image();imgTmp.src = cadTmp[1]; 
		this.matImgObj[2][i] = imgTmp;	
		
		cadHTML += "<div id='" + (this.prefCp + i) + "off' style='position:absolute; left:" + 0 + "px; top:" + 0 + "px; width:10px; height:10px; z-index:100; visibility: hidden;'>";
		cadHTML += "<a href='" + cadTmp[2] + "' target='contenido' onClick='menu.accionMenu(" + i + ",\"click\");' onMouseOver='menu.accionMenu(" + i + ",\"over\");' onMouseOut='menu.accionMenu(" + i + ",\"out\");'><img src='" + cadTmp[0] + "' name='" + (this.prefMenu +  i) + "off' border='0' id='" + (this.prefMenu +  i) + "off'></a>";
		cadHTML += "</div>";
		// Segundo estado.
		cadHTML += "<div id='" + (this.prefCp + i) + "on' style='position:absolute; left:" + 0 + "px; top:" + 0 + "px; width:10px; height:10px; z-index:100; visibility: hidden;'>";
		cadHTML += "<a href='" + cadTmp[2] + "' target='contenido' onClick='menu.accionMenu(" + i + ",\"click\");' onMouseOver='menu.accionMenu(" + i + ",\"over\");' onMouseOut='menu.accionMenu(" + i + ",\"out\");'><img src='" + cadTmp[1] + "' name='" + (this.prefMenu +  i) + "on' border='0' id='" + (this.prefMenu +  i) + "on'></a>";
		cadHTML += "</div>";		
	}
	document.write(cadHTML);	
	
	window.status = "load";	
}


// Metodo para escribir el codigo HTML correspondiente a las capas del menu principal.
// Este metodo se debe situar en el onLoad de la página.
pDinamicMenu.prototype.moveTo = function(pIniX, pIniY, pSepX) {
	window.status = "pDinamicMenu.posHead::execute";
	// Atributos.
	this.x = pIniX;
	this.y = pIniY;
	this.separacion = pSepX;	
	
		
	// Debemos colocar en las cordenadas correctas las distintas capas con las opciones del menu.
	var posImg_X_temp = this.x;	
	this.matCapasObjOff = new Array(null);
	this.matCapasObjOn = new Array(null);
	
	// Capa tapadera.
	this.matCapasObjOff[0] = new ConstructObject("cp" + prefMenu + "Over");
	this.matCapasObjOff[0].moveTo(this.x, this.y);
	this.matCapasObjOff[0].show();
	
	// Capas de opciones principales.
	for(var i=1;i<=this.opciones.length;i++){
		// Primer estado
		this.matCapasObjOff[i] = new ConstructObject(this.prefCp + i + "off");
		this.matCapasObjOff[i].moveTo(posImg_X_temp, this.y);
		this.matCapasObjOff[i].show();
		// Segundo estado.		
		this.matCapasObjOn[i] = new ConstructObject(this.prefCp + i + "on");
		this.matCapasObjOn[i].moveTo(posImg_X_temp, this.y);

		// Obtenemos el ancho de la imagen actual
		posImg_X_temp += (document.getElementById(this.prefMenu + i + "on").width + this.separacion);			
	}

	// Dimensiones del pixel transparente de la capa tapadera.
	document.getElementById(this.prefMenu + 0).width = (posImg_X_temp - this.x);
	document.getElementById(this.prefMenu + 0).height = document.getElementById(this.prefMenu + 1 + "on").height;
	
	window.status = "load";
}
