// Componente Scroll
var ns4=document.layers?1:0;
var ie4=document.all?1:0;
var ns6=document.getElementById&&!document.all?1:0;
	
function Scroll(){
	this.nombre;
	this.ID_ElementoHTML;
	this.PosicionDerechaTope = 0;
	this.PosicionSuperiorTope = 0;
	this.PosicionHorizontal = 0;	
	this.PosicionVertical = 0;
	this.IEHeight = 0;
	this.AnchoPantalla = window.screen.availWidth;
	
	// 1=Derecha, 2=Centrado; 3=Izquierda. 
	this.AlineacionHorizontal = 1;
	
	// 1=Superior, 2=Centrado; 3=Inferior. 
	this.AlineacionVertical = 1;
}

Scroll.prototype.DesplegarControl = function(){
	var ElementoHTML = document.getElementById(this.ID_ElementoHTML);
	var ContenidoHTML = "";

	if(ElementoHTML == null)
		return;

	if (!document.layers) {
		ContenidoHTML = '<div id="' + this.nombre + '_MarcoReferencia" style="position:absolute;margin-top:' + this.PosicionSuperiorTope +  'px;top:' + this.PosicionSuperiorTope +  'px;margin-left:' + this.PosicionDerechaTope + 'px;"></div>';
		ContenidoHTML = ContenidoHTML + '<div id="' + this.nombre + '_ElementoFlotante" style="position:absolute;z-index:5000;margin-top:' + this.PosicionVertical +  'px;top:' + this.PosicionVertical +  'px;margin-left:' + this.PosicionHorizontal + 'px;">';
	}
	
	if (document.layers) {
		ContenidoHTML = '<layer id="' + this.nombre + '_MarcoReferencia" style="margin-top:' + this.PosicionSuperiorTope +  'px;z-index:1;margin-left:' + this.PosicionDerechaTope + 'px;"></layer>';
		ContenidoHTML = ContenidoHTML + '<layer id="' + this.nombre + '_ElementoFlotante">';
	}

	ContenidoHTML = ContenidoHTML  + ElementoHTML.innerHTML;

	if (!document.layers)
		ContenidoHTML = ContenidoHTML + '</div>';
	else
		ContenidoHTML = ContenidoHTML + '</layer>';

	document.body.innerHTML += ContenidoHTML;
};

Scroll.prototype.ActualizarPosicion = function()
{
	var mm = document.getElementById(this.nombre + '_MarcoReferencia');
	var my = 0;
	var mx = 0;

	if(document.getElementById(this.nombre + '_ElementoFlotante') == null)
		return;
		
	my = (document.body.scrollTop > 0) ? document.body.scrollTop : my;
	my = (document.documentElement.scrollTop > 0) ? document.documentElement.scrollTop : my;	

	mx = (document.body.scrollLeft > 0) ? document.body.scrollLeft : mx;
	mx = (document.documentElement.scrollLeft > 0) ? document.documentElement.scrollLeft : mx;	

	var mmy = this.xPageY(mm);

	if (my < mmy) 
	my = mmy;
	
	switch(this.AlineacionVertical){
		case 2:
			my += (document.body.clientHeight - (document.getElementById(this.nombre + "_ElementoFlotante").offsetHeight))/2;
			break;
		case 3:
			my += document.body.clientHeight - (document.getElementById(this.nombre + "_ElementoFlotante").offsetHeight);
			break;
	}

	switch(this.AlineacionHorizontal){
		case 2:
			mx += (document.body.clientWidth - (document.getElementById(this.nombre + "_ElementoFlotante").offsetWidth))/2;
			break;
		case 3:
			mx += document.body.clientWidth - (document.getElementById(this.nombre + "_ElementoFlotante").offsetWidth);
			break;
		case 4:
			mx = (document.body.offsetWidth/2) - 630;
			break;
	}

	if(this.IEHeight == 0)
		this.IEHeight = (document.body.scrollHeight > document.body.offsetHeight) ? document.body.scrollHeight: document.body.offsetHeight;

	//if(ie4)
		if((this.IEHeight - document.getElementById(this.nombre + "_ElementoFlotante").offsetHeight) < my)
			my = (this.IEHeight - document.getElementById(this.nombre + "_ElementoFlotante").offsetHeight);

	/*if(ns4 | ns6)
		if((document.body.offsetHeight - document.getElementById(this.nombre + "_ElementoFlotante").offsetHeight) < my)
			my = (document.body.offsetHeight - document.getElementById(this.nombre + "_ElementoFlotante").offsetHeight);
*/
//	mx -= (this.AnchoPantalla/2) - 300;
		
	this.PosicionY = my;
	this.PosicionX = mx;

	this.Mover();
};

Scroll.prototype.Mover  = function(){

	var Salto = 50;

	if (ie4) {
		if(document.getElementById(this.nombre + "_ElementoFlotante").style.pixelTop < this.PosicionY)
			document.getElementById(this.nombre + "_ElementoFlotante").style.pixelTop += Salto;
			
		if(document.getElementById(this.nombre + "_ElementoFlotante").style.pixelTop > this.PosicionY)
			document.getElementById(this.nombre + "_ElementoFlotante").style.pixelTop -= Salto;			

		if(document.getElementById(this.nombre + "_ElementoFlotante").style.pixelLeft < this.PosicionX)
			document.getElementById(this.nombre + "_ElementoFlotante").style.pixelLeft += Salto;

		if(document.getElementById(this.nombre + "_ElementoFlotante").style.pixelLeft > this.PosicionX)
			document.getElementById(this.nombre + "_ElementoFlotante").style.pixelLeft -= Salto;

	}
	else if (ns6) {
		document.getElementById(this.nombre + "_ElementoFlotante").style.top = this.PosicionY + "px";
		document.getElementById(this.nombre + "_ElementoFlotante").style.left =  this.PosicionX + "px";
	}
	else if (ns4) {
		eval(document.object1.top = eval(this.PosicionY));
		eval(document.object1.left = eval(this.PosicionX));
	}
};


Scroll.prototype.xPageY = function(e) {

	if(this.xDef(e.pageY)) return e.pageY;
	var y = 0;
	while (e) {
		if (this.xDef(e.offsetTop)) y += e.offsetTop;
		e = this.xParent(e);
	}
	return y;
}

Scroll.prototype.xParent = function(e,bNode){
	var p=null;
	if (!bNode && this.xDef(e.offsetParent)) p=e.offsetParent;
	else if (this.xDef(e.parentNode)) p=e.parentNode;
	else if (this.xDef(e.parentElement)) p=e.parentElement;
	else if (this.xDef(e.parentLayer)){if (e.parentLayer!=window) p=e.parentLayer;}
	return p;
}	

Scroll.prototype.xDef = function() {
	for(var i=0; i<arguments.length; ++i){if(typeof(arguments[i])=='undefined') return false;}
	return true;
}