
	function xGetElementById(e) {
		if(typeof(e)!='string') return e;
		if(document.getElementById) e=document.getElementById(e);
		else if(document.all) e=document.all[e];
		else e=null;
		return e;
	}

	function xInnerHtml(e,h){
		if(!(e=xGetElementById(e)) || !xStr(e.innerHTML)) return null;
		var s = e.innerHTML;
		if (xStr(h)) {e.innerHTML = h;}
		return s;
	}
	 
	function xStr(s){
		for(var i=0; i<arguments.length; ++i){if(typeof(arguments[i])!='string') return false;}
		return true;
	}


	var iLimitX=0;
	var iLimitY=0;
	var iPasos=40;
	var iPasosHechos=1;
	var iVelocidad=10;
	var iDivX=100;
	var iDivY=50;
	var bCerrar=false;

	var sImgError='';
	var sImgLoad='';
	var aPieImg=new Array();
	var iOpenIndex=-1;

	function Ampliar(sUrlImg,iAncho,iAlto,iIndex)
	{
		oDiv=document.getElementById('ImgAmpliar');
		oIfr=document.getElementById('IfrImgAmpliar');
		oBody=document.getElementById('Pagina');

		iOpenIndex=iIndex;

		oDiv.style.width=iDivX;
		oDiv.style.height=iDivY;

		// centro de la página
		oDiv.style.left=(oBody.clientWidth/2)-(iDivX/2);
		oDiv.style.top=oBody.scrollTop+((oBody.clientHeight/2)-(iDivY/2));

		// iframe
		oIfr.style.width=oDiv.style.width;
		oIfr.style.height=oDiv.style.height;
		oIfr.style.left=oDiv.style.left;
		oIfr.style.top=oDiv.style.top;

		iLimitX=iAncho;
		iLimitY=iAlto;

		if (ImgContenedor=document.getElementById('ImgContenedor')) oDiv.removeChild(ImgContenedor);

		bCerrar=false;

		// crear areas

		var	oCont=document.createElement('DIV');
		oDiv.appendChild(oCont);
		oCont.id='ImgContenedor';
		oCont.align="center";

		// crear cerrar
		var	oCont1=document.createElement('DIV');
		oCont.appendChild(oCont1);
		oCont1.id='ImgTextCerrar';
		oCont1.className='ImgTxtCerrar';
		oCont1.align="center";
		oCont1.onclick=function () { bCerrar=true; CerrarImg();}

		// crear imagen cargando
		var	oCont2=document.createElement('IMG');
		oCont.appendChild(oCont2);
		oCont2.id='ImgCargando';
		oCont2.style.width=iDivX;
		oCont2.style.height=iDivY;
		oCont2.src=sImgLoad;

		// crear imagen
		var	oCont3=document.createElement('IMG');
		oCont.appendChild(oCont3);
		oCont3.id='ImgLoaded';
		oCont3.style.width='1';
		oCont3.style.height='0';
		oCont3.style.cursor='pointer';
		oCont3.title='Pulsar para cerrar';

		// crear texto
		var	oCont4=document.createElement('DIV');
		oCont.appendChild(oCont4);
		oCont4.id='ImgTextoImg';
		oCont4.className='ImgTxt';
		oCont4.align="left";

		iPasosHechos=1;

		oDiv.style.visibility='visible';
		oIfr.style.visibility='visible';

		// esperar a crear las demas areas para saltar
		oCont3.onload=function () { AmpliarImg(); }
		oCont3.onerror=function () { ErrorImg(); }
		oCont3.onclick=function () { bCerrar=true; CerrarImg(); }
		oCont3.src=sUrlImg;
	}

	function AmpliarImg()
	{
		oCont=document.getElementById('ImgContenedor');

		if (oImgCargar=document.getElementById('ImgCargando')) oCont.removeChild(oImgCargar);
		if (oImg=document.getElementById('ImgLoaded')) oImg.style.border='1px solid #002454';
		
		ImgTexto();

		setTimeout("ImgResize()",iVelocidad);
	}

	function ImgResize()
	{
		oDiv=document.getElementById('ImgAmpliar');
		oIfr=document.getElementById('IfrImgAmpliar');
		oCont=document.getElementById('ImgContenedor');
		oBody=document.getElementById('Pagina');

		if (oImg=document.getElementById('ImgLoaded'))
		{

			// tamaño de la imagen
			iImgX=oImg.style.width;
			iImgY=oImg.style.height;

			// relacion xy
			iRelXY=iLimitX/iLimitY;

			// limitar a la pantalla
			if (iRelXY>1)
			{
				if (iLimitX>(oBody.clientWidth-20)) 
					{ iLimitX=parseInt(oBody.clientWidth)-20; iLimitY=iLimitX/iRelXY; }
			}
//			else
//			{
//				if (iLimitY>oBody.clientHeight)
//					{ iLimitY=parseInt(oBody.clientHeight); iLimitX=iLimitY*iRelXY; }
//			}

			// ampliar imagen
			iImgXNew=(iPasosHechos*iLimitX)/iPasos;
			iImgYNew=(iPasosHechos*iLimitY)/iPasos;
			oImg.style.width=iImgXNew;
			oImg.style.height=iImgYNew;

			var iPorcTxt=Math.round(iImgXNew/iLimitX*100)/100;
//			window.status=iPorcTxt;
			if (oImgTextCerrar=document.getElementById('ImgTextCerrar')) oImgTextCerrar.style.fontSize=iPorcTxt+"em";
			if (oImgText=document.getElementById('ImgTextoImg')) oImgText.style.fontSize=(iPorcTxt*0.8)+"em";


			// centro de la página
			oDiv.style.width=iImgXNew;
			oDiv.style.height=iImgYNew;
			oDiv.style.left=(oBody.clientWidth/2)-(iImgXNew/2);
			oDiv.style.top=oBody.scrollTop+((oBody.clientHeight/2)-(parseInt(oDiv.clientHeight)/2));

			if (parseInt(oDiv.style.top)<0) oDiv.style.top=2;
			
			// iframe
			oIfr.style.width=parseInt(oDiv.style.width)+5;
			oIfr.style.height=oDiv.style.height;
			oIfr.style.left=oDiv.style.left;
			oIfr.style.top=oDiv.style.top;

			iPasosHechos++;
			if (iPasosHechos<=iPasos) setTimeout("ImgResize()",iVelocidad);
		}
	}

	function CerrarImg()
	{
		if (bCerrar)
		{
			oDiv=document.getElementById('ImgAmpliar');
			oIfr=document.getElementById('IfrImgAmpliar');
			if (oCont=document.getElementById('ImgContenedor')) oDiv.removeChild(oCont);
			
			oDiv.style.width=iDivX;
			oDiv.style.height=iDivY;
			oDiv.style.visibility='hidden';
			oIfr.style.visibility='hidden';
		}
	}

	function ErrorImg()
	{
		oCont=document.getElementById('ImgContenedor');
		if (oImgCargar=document.getElementById('ImgCargando')) oImgCargar.src=sImgError;
		bCerrar=true;
		setTimeout("CerrarImg()",1000);
	}

	function ImgTexto()
	{

		if (oImgTextCerrar=document.getElementById('ImgTextCerrar'))
		{
			// cerrar
			oImgTextCerrar.style.padding="2px";
			oImgTextCerrar.style.fontSize="0em";
			oImgTextCerrar.appendChild(document.createTextNode('Cerrar Imagen (Puede pulsar sobre la imagen para cerrarla)'));
		}

		if (oImgText=document.getElementById('ImgTextoImg'))
		{
			// texto
			oImgText.style.padding="2px";
			oImgText.style.fontSize="0em";
			xInnerHtml(oImgText,aPieImg[iOpenIndex]);

		}


	}
