gAlto=708;
gAncho=904;
var gLista = new Array;
gConta=0;
gInd=0;
gSig=0;
gAnt=0;
gId=0;
gDescrip='';
var w=-1;
gTopFotos=0;
gImAct=null;
function AnimarFondoFoto()
{
  wa=parseInt(document.getElementById('LFoto').style.width);
  ha=parseInt(document.getElementById('LFoto').style.height);
  ta=parseInt(document.getElementById('LFoto').style.top);
  la=parseInt(document.getElementById('LFoto').style.left);
  if (wa>w) 
  {
	 wa-=10;
	 if (wa<w) wa=w;
  }
  if (wa<w) 
  {
	 wa+=10;
	 if (wa>w) wa=w;
  }
  if (ha>h) 
  {
	 ha-=10;
	 if (ha<h) ha=h;
  }
  if (ha<h) 
  {
	 ha+=10;
	 if (ha>h) ha=h;
  }
  if (ta>t) 
  {
	 ta-=5;
	 if (ta<t) ta=t;
  }
  if (ta<t) 
  {
	 ta+=5;
	 if (ta>t) ta=t;
  }
  if (la>l) 
  {
	 la-=5;
	 if (la<l) la=l;
  }
  if (la<l) 
  {
	 la+=5;
	 if (la>l) la=l;
  }
  
  document.getElementById('LFoto').style.left=la+'px';
  document.getElementById('LFoto').style.top=ta+'px';
  document.getElementById('LFoto').style.width=wa+'px';
  document.getElementById('LFoto').style.height=ha+'px';
  
  lc=parseInt(document.getElementById('LFoto').style.width);
  lc=Math.round(lc/2)-20;
  tc=parseInt(document.getElementById('LFoto').style.height);
  tc=Math.round(tc/2)-20;
  document.getElementById('LCargaFoto').style.left=lc+'px';
  document.getElementById('LCargaFoto').style.top=tc+'px';  
  if (wa!=w || ta!=t || la!=l || ha!=h) setTimeout('AnimarFondoFoto()',5)
  else 
  {
	 textodiv='';
	 if (gDescrip!='')
	 {
		textodiv=gDescrip+'<br />' 
	 }
	 if (gConta>0)
	 {
	   argum=gLista.join(",");
	   if (gAnt!='') textodiv+='<a href="javascript:Fotos('+gAnt+','+argum+');" target="_self" style="color: #FFFFFF">&lt; </a> ';
	   textodiv+=gInd+' de '+gConta; 	
	   if (gSig!='') textodiv+='<a href="javascript:Fotos('+gSig+','+argum+');" target="_self" style="color: #FFFFFF"> &gt;</a> ';
	 }
	 texto='<div style="position:absolute; left: 0px; top:'+h+'; z-index:11; font-family: Trebuchet MS; color:#FFFFFF; font-size: 16px;">'+textodiv+'</div>';
	 document.getElementById('LFoto').innerHTML='<img src="'+gSrc+'" alt="foto" width="'+w+'" height="'+h+'" border="0"><div id="LX" style="position:absolute; width:50px; height:39px; z-index:11; left: 0px; top: -36px;"><a href="javascript:CerrarFoto();" target="_self"><img src="fotos/x.gif" alt="Cerrar Foto" width="48" height="36" border="0"/></a></div>'+texto;
  }
}

function Fotos()
{
  id=arguments[0];
  gLista.length=0;
  if (id>-1)
  {
    for (i=1; i<arguments.length; i++) gLista[i-1]=arguments[i];
    document.getElementById('LFondoFotos').style.visibility='visible';
    document.getElementById('LFoto').style.visibility='visible';
  }
  var xhr = createXHR();
  xhr.onreadystatechange  = function()
  { 
    if (xhr.readyState  == 4)
    {
      if(xhr.status  == 200) 
	  {
		 if (id>-1)
		 {
           //Recibimos el enlace a la foto
		   var foto=new Image; 
		   arr=xhr.responseText.split('$');
		   foto.src=arr[0];
		   foto.onload=AnimarFondoFoto;
		   gSrc=foto.src;
		   w=arr[1];
	       h=arr[2];
		   gDescrip=arr[3];
		   gId=id;
		   izq=(gAncho/2)-(w/2);
  		   arr=(gAlto/2)-(h/2)+gTopFotos;		
		   t=arr;
		   l=izq;
		   gConta='';
		   gAnt='';
		   gSig='';
		   gInd='';
		   if (gLista.length>0)
		   {
		     gConta=gLista.length;
		     for (i=0; i<gLista.length; i++)
		     {
		       if (gLista[i]==id)
		       {
			     gInd=i+1;
			     if (i<gLista.length-1) gSig=gLista[i+1];
			     if (i>0) gAnt=gLista[i-1];
			     break;
		       }		     
		     }
		   }
		   if (document.getElementById("Im"+gId)!=null)
		   {
			 if (gImAct!=null) Fuera(gImAct);
			 Dentro(document.getElementById("Im"+gId));
			 gImAct=document.getElementById("Im"+gId);
		   }
		 }
		 else if (id==-1)
		 {
		    eval('Fotos('+xhr.responseText+');');
		 }
		 else if (id==-2)
		 {  
		   arr=xhr.responseText.split('$'); 
		   x=-15;
		   texto='';
		   listafotos='';
		   for (i=0; i<(arr.length/2); i++) listafotos+=arr[(i*2)]+',';
		   listafotos=listafotos.substring(0, listafotos.length-1);
		   for (i=0; i<(arr.length/2); i++)
		   {
			 texto+='<div style="position: absolute; top: 4px; left: '+x+'px; width: 100px; height: 54px; text-align: center;"><a href="javascript:Fotos('+arr[(i*2)]+','+listafotos+');"><img id="Im'+arr[(i*2)]+'" style="filter: alpha(opacity= 50); opacity: 0.5;" border="0" src="fotos/'+arr[(i*2)+1]+'" onmouseover="Dentro(this)" onmouseout="Fuera(this)"></a></div>'; 
			 x+=70;
		   }
		   document.getElementById("LSlideFotos").innerHTML=texto;
		   document.getElementById('LSlideFotos').style.visibility='visible'; 
		   if ((arr.length/2)>11)
		   {
		   document.getElementById('LScrollSlideL').style.visibility='visible'; 
		   document.getElementById('LScrollSlideR').style.visibility='visible'; 
		   }
		   gTopFotos=-50;
		   Fotos(-1);
		 }
	  }	 
      else 
         document.getElementById("LFoto").innerHTML = "Error code " + xhr.status;
    }
	else if (xhr.readyState  == 1)
	{		
	  if (id>-1)
	  {
	    if (document.getElementById('LFoto').style.left=='')
	    {  
	       izq=(gAncho/2)-(200/2);
  		   arr=(gAlto/2)-(100/2)+gTopFotos;
 		   document.getElementById('LFoto').style.top=arr+'px';
	       document.getElementById('LFoto').style.left=izq+'px';
		   document.getElementById('LFoto').style.width='200px';
		   document.getElementById('LFoto').style.height='100px';
	    }
	    l=parseInt(document.getElementById('LFoto').style.width);
	    l=Math.round(l/2)-20;
	    t=parseInt(document.getElementById('LFoto').style.height);
	    t=Math.round(t/2)-20;
	    document.getElementById("LFoto").innerHTML = "<div id=\"LCargaFoto\" style=\"position: absolute; left:"+l+"px; top:"+t+"px;\"><img src=\"cargando3.gif\" width=\"41\" height=\"41\" /></div>"+
	  '<div id="LX" style="position:absolute; width:50px; height:39px; z-index:11; left: 0px; top: -36px;"><a href="javascript:CerrarFoto();" target="_self"><img src="fotos/x.gif" alt="Cerrar Foto" width="48" height="36" border="0"/></a></div>';
	  }
	}
  }
  pagina='foto.php?id='+id;
  
  xhr.open('GET', pagina,  true); 
  xhr.send(null);
}

function CerrarFoto()
{
  document.getElementById('LFondoFotos').style.visibility='hidden';
  document.getElementById('LFoto').style.visibility='hidden';
  document.getElementById('LSlideFotos').style.visibility='hidden';  
  document.getElementById('LScrollSlideL').style.visibility='hidden'; 
  document.getElementById('LScrollSlideR').style.visibility='hidden'; 
  gTopFotos=0;
}

function Dentro(imagen)
{
  imagen.style.opacity='1';	
  imagen.style.filter='alpha(opacity= 100)';
}

function Fuera(imagen)
{
  if (gId!=parseInt(imagen.id.substring(2,4)))
  {
    imagen.style.opacity='0.5';	
    imagen.style.filter='alpha(opacity= 50)';
  }
}

function SlideScroll(factor)
{
  idslide=setInterval('DesplazarSlide('+factor+')',20);	
}
	
function DesplazarSlide(factor)	
{
  sc=document.getElementById('LSlideFotos').scrollLeft;
  document.getElementById('LSlideFotos').scrollLeft=sc+(factor*2);
}

function PararSlide()
{
  clearInterval(idslide);
}