// Clase lObj para los <div>s

// La idea es tener una clase generica de tratamiento de capas tanto para el explorer como para el Netscape como para el Netscape 6
// ademas de funciones adicionales que permita hacer movimientos repetitivos sobre una (fun_divs.js) o varias capas (mul_fun_divs.js)
// de manera simultanea...

// La clase contendra asociadas a ella funciones basicas de las capas, mientras que los ficheros de funciones contendran
// funciones complejas que haran uso de las funciones simples implementadas en la clase.

function lObj (_loId, _loPh)
{
	var _loObj;
	var _loPath;
	if (_loPh && document.layers)
	{
		_loPath = document.layers[_loPh].document;
	}
	else
	{
		_loPath = document;
	}

	if ( (document.all && (_loObj=document.all[_loId]) ) || (document.layers && (_loObj=_loPath.layers[_loId])) || (document.getElementById && (_loObj=document.getElementById(_loId))) )
	{
		_loObj.l = function (evt){return (parseInt ((_loObj.style)? _loObj.style.left : _loObj.left));};
		_loObj.t = function (evt){return (parseInt ((_loObj.style)? _loObj.style.top : _loObj.top));};
		_loObj.h = function (evt){return (parseInt ((_loObj.style)? _loObj.offsetHeight : _loObj.clip.height));};
		_loObj.w = function (evt){return (parseInt ((_loObj.style)? _loObj.offsetWidth : _loObj.clip.width));};
		_loObj.child = new Array ();
		_loObj.childId = new Array ();
		_loObj.newChild = newChildForMe;
		_loObj.Id;
		_loObj.Name;
		_loObj.L = !_loObj.L? _loObj.l() : _loObj.L;  // Propiedades de esta clase : L = La posicion horizontal de la esquina superior izquierda, en pixels, relativo a el origen o aa su capa padre
		_loObj.T = !_loObj.T? _loObj.t() : _loObj.T;  // T = top - La posicion vertical de la esquina superior izquierda, en pixels, relativo a el origen o aa su capa padre
		_loObj.H = !_loObj.H? _loObj.h() : _loObj.H;  // H = clip.height - La altura del rectangulo de vision de la capa
		_loObj.W = !_loObj.W? _loObj.w() : _loObj.W;  // W = clip.width - La anchura del rectangulo de vision de la capa
		_loObj.reDimTo = reDimensionTo;				// Funciones implementadas en esta clase : reDimTo
		_loObj.moveTo = moveMeTo;							// moveTo
		_loObj.moveBy = moveMeBy;							// moveBy
		_loObj.clipTo = clipMeTo;							// clipTo
		_loObj.clipBy = clipMeBy;							// clipBy
		_loObj.reClip = reClipToMe;						// reClip
		_loObj.show = setMyVisTo;							// show
		_loObj.rewrite = replaceMyHTML;				// rewrite
	}
	return _loObj;
}

// newChildForMe

function newChildForMe (_ncfmObj, _ncfmName)
{
	this.childId[this.childId.length]=_ncfmObj;
	this.child[_ncfmName]=_ncfmObj;
	_ncfmObj.Name = _ncfmName;
	
	_ncfmObj.moveTo (this.l()+_ncfmObj.L, this.t()+_ncfmObj.T);
	
	_ncfmW = (_ncfmObj.W+_ncfmObj.L >= this.w())? _ncfmObj.W+_ncfmObj.L : this.w() ;
	_ncfmH = (_ncfmObj.H+_ncfmObj.T >= this.h())? _ncfmObj.H+_ncfmObj.T : this.h() ;

	this.reDimTo (_ncfmW, _ncfmH);
}

// reDimensionTo ==>>  reDimTo(ancho, alto)

function reDimensionTo (_rdW, _rdH)
{
	if (this.clip)
	{
		this.clip.width=this.W=_rdW;
		this.clip.height=this.H=_rdH;
	}
	else
	{
		this.style.width=(this.W=_rdW)+'px ';
		this.style.height=(this.H=_rdH)+'px ';
	}
}

// moveMeTo ==>> moveTo(izquierda, arriba, )

function moveMeTo (_mmtLeft, _mmtTop, _mmtRL)
{
	var _mmtObj = this.style? this.style : this;
	var _mmtByL = _mmtLeft - this.l();
	var _mmtByT = _mmtTop - this.t();
	if (_mmtRL)
	{
		this.L=_mmtLeft;
		this.T=_mmtTop;
	}
	if (this.style)
	{
		_mmtLeft += 'px ';
		_mmtTop += 'px ';
	}
	_mmtObj.left = _mmtLeft;
	_mmtObj.top = _mmtTop;
	if (this.childId.length!=0)
	{
		for(_mmtI=0; _mmtI<this.childId.length; _mmtI++)
		{
			this.childId[_mmtI].moveBy(_mmtByL, _mmtByT);
		}
	}
}

// moveMeBy ==>> moveBy(izquierda, arriba, )

function moveMeBy (_mmbLeft, _mmbTop, _mmbRL)
{
	var _mmbObj = this.style? this.style : this;
	this.moveTo (parseInt (_mmbObj.left)+_mmbLeft, parseInt (_mmbObj.top)+_mmbTop, _mmbRL);
}

// clipMeTo ==>> clipTo(izquierda, derecha, arriba, abajo)

function clipMeTo (_cmtLeft, _cmtRight, _cmtTop, _cmtBottom)
{
	var _cmtObj = this.style? this.style : this;
	if (document.layers)
	{
		_cmtObj.clip.left=_cmtLeft;
		_cmtObj.clip.right=_cmtRight;
		_cmtObj.clip.top=_cmtTop;
		_cmtObj.clip.bottom=_cmtBottom;
	}
	else
	{
		_cmtObj.clip = 'rect(' + _cmtTop + 'px ' + _cmtRight + 'px ' + _cmtBottom  + 'px ' + _cmtLeft + 'px)';
	}
}

// clipMeBy  ==>> clipBy(izquierda, derecha, arriba, abajo)

function clipMeBy (_cmbLeft, _cmbRight, _cmbTop, _cmbBottom)
{
	var _cmbObj = this.style? this.style : this;
	if (document.layers)
	{
		_cmbObj.clip.left = parseInt (_cmbObj.clip.left,10) + _cmbLeft;
		_cmbObj.clip.right = parseInt (_cmbObj.clip.right,10) - _cmbRight;
		_cmbObj.clip.top = parseInt (_cmbObj.clip.top,10) + _cmbTop;
		_cmbObj.clip.bottom = parseInt (_cmbObj.clip.bottom,10) - _cmbBottom;
	}
	else
	{
		if(!_cmbObj.clip || _cmbObj.clip=='')
		{
			_cmbObj.clip = 'rect(0px ' + parseInt(_cmbObj.width,10)+'px ' + parseInt(_cmbObj.height,10) + 'px 0px)';
		}
		var _cmbC = _cmbObj.clip, _cmbClip = 'rect(';
		_cmbClip += (parseInt (_cmbC.substring (_cmbC.indexOf ('(') + 1, _cmbC.indexOf (' ')), 10) + _cmbTop) + 'px ';
		_cmbC = _cmbC.substring (_cmbC.indexOf (' ') + 1, _cmbC.length);
		_cmbClip += (parseInt (_cmbC.substring (0, _cmbC.indexOf ('px')), 10) - _cmbRight) + 'px ';
		_cmbC = _cmbC.substring ( _cmbC.indexOf (' ') + 1, _cmbC.length);
		_cmbClip += (parseInt (_cmbC.substring (0, _cmbC.indexOf ('px')), 10) - _cmbBottom) + 'px ';
		_cmbC = _cmbC.substring (_cmbC.indexOf (' ') + 1, _cmbC.length);
		_cmbClip += (parseInt (_cmbC.substring (0, _cmbC.indexOf ('px')), 10) + _cmbLeft) + 'px';
		_cmbClip += ')';
		_cmbObj.clip = _cmbClip;
	}
}

// reClipToMe ==>> reClip

function reClipToMe ()
{
	if (document.layers)
	{
		this.clipTo(this.clip.left, this.clip.right, this.clip.top, this.clip.bottom);
		if (this.childId.length!=0)
		{
			for(_mmtI=0; _mmtI<this.childId.length; _mmtI++)
			{
				this.childId[_mmtI].reClip();
			}
		}
	}
}

// setMyVisTo ==>> show([false - true])

function setMyVisTo (_smvt)
{
	var _smvtObj = this.style? this.style : this;
	if (_smvt)
	{
		_smvtObj.visibility = (document.layers)? "show" : "visible";
	}
	else
	{
		_smvtObj.visibility = (document.layers)? "hide" : "hidden";
	}
	if (this.childId.length!=0)
	{
		for(_mmtI=0; _mmtI<this.childId.length; _mmtI++)
		{
			_smvtObj = this.childId[_mmtI].style? this.childId[_mmtI].style : this.childId[_mmtI];
			if (_smvt)
			{
				_smvtObj.visibility = (document.layers)? "show" : "visible";
			}
			else
			{
				_smvtObj.visibility = (document.layers)? "hide" : "hidden";
			}
		}
	}
}

// replaceMyHTML ==>> rewrite(codigo HTML)

function replaceMyHTML (_rmHTMLString)
{
	_rmHTMLString = unescape (_rmHTMLString);
	if (document.layers)
	{
		this.document.open();
		this.document.write(_rmHTMLString);
		this.document.close();
	}
	else
	{
		this.innerHTML = _rmHTMLString;
	}
}