/****************************************************************************************************/
/***************************************** 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.                                                    */
/****************************************************************************************************/


var Gb_HorizontalPluGin

function HorizontalPluGin(menuPrin,obj,nest,nest2,w,h,pPref,pVel) {
	// Objeto general.
	this.constructObject = (eval("typeof " + obj + "Object") == 'undefined')? new ConstructObject(obj,nest,nest2) : eval(obj + "Object");	
	this.constructObject.w=w
	this.constructObject.h=h	
	
	// Atributos.
	this.bw = new verifyCompatibleBrowser()
	this.menuPrin = menuPrin;
	this.hzPGpref = pPref;
	this.hzPGvel = (this.bw.ie5)? parseInt(pVel / 2):pVel;
	this.hzPGdepurado = false; // Depuracion del Plugin.
	this.cphzPGobjTp = new Array(); // temporizadores de cierre.

	// Creamos los objetos de cada submenu.
	this.cphzPGobj = new Array(); // capas de subopciones.
	this.cphzPGobjTapa = new Array(); // y tapaderas subopciones.
	for(var i=1;i<=this.menuPrin.num;i++){
		if(document.getElementById(pPref + i)){
			// Contenedor subOpciones.
			this.cphzPGobj[i] = (eval("typeof " + pPref + i + "Object") == 'undefined')? new ConstructObject(pPref + i, obj) : eval(pPref + i + "Object");
			this.cphzPGobj[i].moveTo(this.cphzPGobj[i].x, (-this.cphzPGobj[i].h))
			this.cphzPGobj[i].hide();
			// Inicializamos temporizadores.
			this.cphzPGobjTp[i] = null;
		}else this.cphzPGobj[i] = null;
	}	

	this.obj = obj + "_HzPG";
	eval(this.obj + "=this");
	
	Gb_HorizontalPluGin = this;
	// Cargamos los enventos
	for(var i=1;i<=this.menuPrin.num;i++) this.cargarEventosCont(i);
	
	return this	
}

// END INTERFACE.
HorizontalPluGin.prototype.endhzPGcerrar = function(pNum) {
	this.cphzPGobj[pNum].hide();
	// window.status = "listo";
}

HorizontalPluGin.prototype.endhzPGabrir = function(pNum) {
	// window.status = "listo";
}

// INIT INTERFACE.
HorizontalPluGin.prototype.initOver = function(pNum,pHref,pTarget) {
	if(this.hzPGdepurado) alert("Menu --> initOver: " + pNum);
	if(this.cphzPGobj[pNum] != null){
		clearTimeout(this.cphzPGobjTp[pNum]);
		this.cphzPGobj[pNum].css.zIndex = 100;
		this.hzPGabrir(pNum);
	}
}

// INIT INTERFACE.
HorizontalPluGin.prototype.initOut = function(pNum) {
	if(this.hzPGdepurado) alert("Menu --> initOut: " + pNum);
	if(this.cphzPGobj[pNum] != null){
		this.cphzPGobj[pNum].css.zIndex = 10;
		this.cphzPGobjTp[pNum] = setTimeout(this.obj + ".hzPGcerrar(" + pNum + ");", 500);
	}
}



HorizontalPluGin.prototype.cargarEventosCont = function(pNum) {
	// Capturamos los eventos de las capa contenedoras.
	if(this.cphzPGobj[pNum] != null){
		if(bw.ns5) {
			this.cphzPGobj[pNum].el.addEventListener("mouseover",this.objMouse,false);
			this.cphzPGobj[pNum].el.addEventListener("mouseout",this.objMouse,false);
		}
		if(bw.ie5 || bw.ie6){
			this.cphzPGobj[pNum].el.onmouseover = this.objMouse;
			this.cphzPGobj[pNum].el.onmouseout = this.objMouse;
		}
	}
}

HorizontalPluGin.prototype.objMouse = function(event) {
	  var idCont;  
	  if (window.event) {    
	  	idCont = this.id; 
	  	if(window.event.type == "mouseover") Gb_HorizontalPluGin.overCpCont(idCont);
		if(window.event.type == "mouseout") Gb_HorizontalPluGin.outCpCont(idCont);
	  }else{    
	  	idCont = event.currentTarget.id; 
	  	if(event.type == "mouseover") Gb_HorizontalPluGin.overCpCont(idCont);
		if(event.type == "mouseout") Gb_HorizontalPluGin.outCpCont(idCont);	  	
	  }	  
}

HorizontalPluGin.prototype.outCpCont = function(idCont) {
	if(this.hzPGdepurado) alert("Menu --> outCpCont: " + idCont);
	pNum = idCont.split(this.hzPGpref)[1];
	if(this.cphzPGobj[pNum] != null){
		this.cphzPGobjTp[pNum] = setTimeout(this.obj + ".hzPGcerrar(" + pNum + ");", 500);
	}
}

HorizontalPluGin.prototype.overCpCont= function(idCont) {
	if(this.hzPGdepurado) alert("Menu --> overCpCont: " + idCont);
 	pNum = idCont.split(this.hzPGpref)[1];
	if(this.cphzPGobj[pNum] != null){
		clearTimeout(this.cphzPGobjTp[pNum]);
	}
}

HorizontalPluGin.prototype.calcularVeloc = function(numPasos){
	if(this.hzPGvel == 0){
		return 1;
	}else{
		return parseInt(numPasos * this.hzPGvel);
	}
}

HorizontalPluGin.prototype.hzPGabrir = function(pNum) {
	if(this.hzPGdepurado) alert("Menu --> hzPGabrir: " + pNum);
	var velocidad = this.calcularVeloc(1.5);

	// Calculamos el pto final en caso de haber desplazamiento de scroll.
	var ptoFinal = 0;
	if(typeof(document.body.scrollTop) != 'undefined'){ // IE.
		this.cphzPGobj[pNum].moveTo(this.cphzPGobj[pNum].x, document.body.scrollTop - this.cphzPGobj[pNum].h);
		ptoFinal = document.body.scrollTop - 1;
	}else{ // NS.
		this.cphzPGobj[pNum].moveTo(this.cphzPGobj[pNum].x, window.pageYOffset - this.cphzPGobj[pNum].h);
		ptoFinal = window.pageYOffset -1;	
	}
	// Mostramos el submenu correspondiente.	
	this.cphzPGobj[pNum].show();
	this.cphzPGobj[pNum].slideTo(this.cphzPGobj[pNum].x, ptoFinal,velocidad,2,this.obj + ".endhzPGabrir(" + pNum + ");");
}


HorizontalPluGin.prototype.hzPGcerrar = function(pNum) {
	if(this.hzPGdepurado) alert("Menu --> hzPGcerrar: " + pNum);
	var velocidad = this.calcularVeloc(1);
	
	// Ocultamos el submenu correspondiente.
	this.cphzPGobj[pNum].slideTo(this.cphzPGobj[pNum].x, (-this.cphzPGobj[pNum].h),velocidad,2,this.obj + ".endhzPGcerrar(" + pNum + ");");
}