function PantallaEspera(id, nombre, idImg, numImagenes, nombreImagenes, extensionImagenes, tiempo, ancho, alto)
{
	this.id = id;
	this.nombre = nombre;
	this.idImg = idImg;
	this.numImagenes = numImagenes;
	this.nombreImagenes = nombreImagenes;
	this.extensionImagenes = extensionImagenes;
	this.tiempo = tiempo;
	this.ancho = ancho;
	this.alto = alto;
	this.CurrentImageIndex = 0;
	this.timeout_id = null;
	this.CapaDiv = document.getElementById(this.id);
	this.CacheImages();
	this.Hide();
}

PantallaEspera.prototype.Resize = function()
{
	//alert('aaaaa');
	//this.CapaDiv.style = 'width:' + this.Width + 'px;height:' + this.Height + 'px;';
	//alert('bbbbb');
	//this.CapaDiv.style.width = this.Width + 'px';
	//this.CapaDiv.style.height = this.Height + 'px';
}

PantallaEspera.prototype.Center = function()
{
	// Center the BusyBox in the window regardless of the scroll positions
	var objLeft = 0;
/*	if( PantallaEspera.IsBrowserIE() )
	{
		objLeft = (document.body.clientWidth - this.CapaDiv.offsetWidth) / 2;
	}
	else
	{
		objLeft = (document.body.clientWidth) / 2;
	}
*/
	objLeft = (document.body.clientWidth - this.CapaDiv.offsetWidth) / 2;
	var objTop = (document.body.clientHeight) / 2;
	objLeft = objLeft + document.body.scrollLeft;
	objTop = objTop + document.body.scrollTop;
	
	// Position object
	this.CapaDiv.style.position = "absolute";
	//this.CapaDiv.style.width = "90%";
	//this.CapaDiv.style.background-color = "#FF0000";
	//this.CapaDiv.style.border-color = "#FF0000";
	//this.CapaDiv.style.border-width = "3px";
	//this.CapaDiv.style.border-style = "solid";
	//alert('top: ' + objTop + ' left:' + objLeft);
	this.CapaDiv.style.top = objTop;
	this.CapaDiv.style.left = objLeft;
//	this.CapaDiv.style.align = "center";

}

PantallaEspera.prototype.CacheImages = function()
{
	// Instantiate the array to store the image references
	this.Images = new Array(this.numImagenes);
	
	// Load all the images to cache into the aniframes array
	for(var i = 0; i < this.numImagenes; i++)
	{
		this.Images[i] = new Image();
		this.Images[i].src = this.nombreImagenes + i + this.extensionImagenes;
	}
}

PantallaEspera.prototype.IsAnimating = function()
{
	if( this.timeout_id == null)
		return false;
	else
		return true;
}

// IsVisible:
// Returns a boolean value representing the visibility state for the busy box.
PantallaEspera.prototype.IsVisible = function()
{
	var ifrm = document.getElementById(this.id);
	
	if( ifrm.style.visibility == "visible" && ifrm.style.width > 0 )
		return true;
	else
		return false;
}


PantallaEspera.prototype.Animate = function()
{
	//alert(this.CurrentImageIndex);
	//alert(this.Images[0].src);
	document.getElementById(this.idImg).src = this.Images[this.CurrentImageIndex].src;

	this.Resize();
	this.Center();
	
	this.CurrentImageIndex = (this.CurrentImageIndex + 1)%this.numImagenes;
	
	this.timeout_id = setTimeout(this.nombre + ".Animate();", this.tiempo);
}

PantallaEspera.prototype.StartAnimate = function()
{
	if( this.IsAnimating() )
		return;
	
	this.Animate();
}

// StopAnimation:
// Stops the animation process.
PantallaEspera.prototype.StopAnimate = function()
{
	clearTimeout(this.timeout_id);
	this.timeout_id = null;
}

// Hide:
// Hides the busy box making it invisible to the user.
PantallaEspera.prototype.Hide = function()
{	
	this.StopAnimate();
	
	// Hide the busy box.
	this.CapaDiv.style.visibility = "hidden";
	this.CapaDiv.style.display = "none";
	this.CapaDiv.style.width = 0;
	this.CapaDiv.style.height = 0;
}

PantallaEspera.prototype.Show = function()
{
	if( this.IsAnimating() || this.IsVisible() )
		return;	
	this.CapaDiv.style.display = "block";
	this.Resize();
	this.Center();
		
	// Set the busy box to be visible and make sure it is on top of all other controls.	
	this.CapaDiv.style.visibility = "visible";
	this.CapaDiv.style.className = "show";
	this.CapaDiv.style.zIndex = "999999";
	
	// Start the animation
	this.StartAnimate();
}

PantallaEspera.IsBrowserIE = function()
{
	try
	{ return (window.navigator.userAgent.indexOf("MSIE ") > 0); }
	catch(x)
	{ return false; }
}

// IsBrowserNS:
// Returns true if the executing browser it a Netscape browser.
PantallaEspera.IsBrowserNS = function()
{
	try
	{ return (window.navigator.userAgent.indexOf("Netscape") > 0); }
	catch(x)
	{ return false; }
}

// IsBrowserFirefox:
// Returns true if the executing browser it a Firefox browser.
PantallaEspera.IsBrowserFirefox = function()
{
	try
	{ return (window.navigator.userAgent.indexOf("Firefox") > 0); }
	catch(x)
	{ return false; }
}



