//-----------------------------------------------------------------------
// Navegación de Thumbnails, LightBox y Play-Presentación
// Fotos EMOL 3.0
// marzo 2008
// Desarrollado por Gustavo Vargas Retamal
// Departamento de Desarrollo TI Internet - El Mercurio
//-----------------------------------------------------------------------
segINTERVALO = 4;

function viewDivPage(intDIVmostrar, intDIVocultar, fotoMostrarPorDefecto)
{
strDIVmostrar='DIVPAG'+intDIVmostrar;
strDIVocultar='DIVPAG'+intDIVocultar;
document.getElementById(strDIVocultar).style.display='none';
document.getElementById(strDIVmostrar).style.display='block';

PresentarFotosOFF();

if (fotoMostrarPorDefecto==-1)
{
	for (i=0; fotoMostrarPorDefecto==-1; i++)
	{
	if (arrDATA[i][6]==intDIVmostrar)
	   {
	   fotoMostrarPorDefecto=i;
	   }
	}
	viewFoto(fotoMostrarPorDefecto);
	}
}
//-----------------------------------------------------------------------
function viewFoto(RowIndex)
{
//Marca CERTIFICA
tagCertifica( 13947, arrDATA[RowIndex][0]); 
//Carga la foto
generar_foto(arrDATA[RowIndex][1],arrDATA[RowIndex][2],arrDATA[RowIndex][3],arrDATA[RowIndex][4],arrDATA[RowIndex][5],RowIndex,this);
//Mostrar mensaje: "Foto x de xx"
for (i=1; i<=MAXPAGINAS;i++)
	{
	document.getElementById("msgNumFotos"+i).innerHTML= "<center>Foto "+ (RowIndex+1) +" de "+ MAXFOTOS +"</center>";
	}
}
//-----------------------------------------------------------------------
function AvanzaFoto(IndiceUltimaFoto_dePag)
{
indiceFOTOPREVIA = indiceFOTOACTUAL;
indiceFOTOACTUAL++;
if (indiceFOTOACTUAL >= MAXFOTOS-1)
	{
	// está en la última foto
	 indiceFOTOACTUAL = MAXFOTOS-1;
	 indiceFOTOPREVIA = MAXFOTOS-2;
	}
viewFoto(indiceFOTOACTUAL);
	if (indiceFOTOACTUAL == IndiceUltimaFoto_dePag+1)
	{
	viewDivPage(arrDATA[indiceFOTOACTUAL][6], arrDATA[indiceFOTOPREVIA][6],0)
	//alert("avanza pagina");
	}
}
//-----------------------------------------------------------------------
function RetrocedeFoto(IndicePrimeraFoto_dePag)
{
indiceFOTOANTERIOR = indiceFOTOACTUAL;
indiceFOTOACTUAL--;
if (indiceFOTOACTUAL <= 0) 
	{
	 indiceFOTOACTUAL = 0;
	}
viewFoto(indiceFOTOACTUAL);
	if (indiceFOTOACTUAL == IndicePrimeraFoto_dePag-1)
	{
	viewDivPage(arrDATA[indiceFOTOACTUAL][6], arrDATA[indiceFOTOANTERIOR][6],0)
	//alert("retrocede pagina");
	}
}
//-----------------------------------------------------------------------
function PresentarFotos()
{
if (TimerID==0)
    {
	indiceFOTOACTUAL++;
	if (indiceFOTOACTUAL > MAXFOTOS-1)
		{
		indiceFOTOACTUAL > MAXFOTOS-1;
		}
	PresentarFotosAvanzar();
	TimerID=setInterval("PresentarFotosAvanzar()", 1000 * segINTERVALO);
		for (i=1; i<=MAXPAGINAS;i++)
		{
		document.getElementById("icoPLAY"+i).src= "/imagenes/ico_nav_play_pause.gif";
		}
	}
	else
	{
	PresentarFotosOFF();
	}
}
//-----------------------------------------------------------------------
function PresentarFotosOFF()
{
	clearInterval(TimerID);
	TimerID=0;
	for (i=1; i<=MAXPAGINAS;i++)
		{
		document.getElementById("icoPLAY"+i).src= "/imagenes/ico_nav_play.gif";
		}
}
//--------------------------------------------------
function PresentarFotosAvanzar()
{
viewFoto(indiceFOTOACTUAL);
indiceFOTOACTUAL++;
if (indiceFOTOACTUAL > MAXFOTOS-1)
 	 {
	 PresentarFotosOFF();
	 indiceFOTOACTUAL = MAXFOTOS-1;
	 }
}
//-----------------------------------------------------------------------

function gettrailobjnostyle(){

	if (document.getElementById)
	return document.getElementById("trailimageid")
	else if (document.all)
	return document.all.trailimagid

}
//-----------------------------------------------------------------------

function generar_foto(imagename,title,description,credito,fecha,RowIndex,inputObj){
	RowPrev = RowIndex-1;
	RowNext = RowIndex+1;
	indiceFOTOACTUAL = RowIndex;
	if (RowPrev<0)
	{
		RowPrev=0;
	}
	// cambiar acá por el maximo de fotos de la galeria
	if (RowNext>MAXFOTOS-1)
	{
		RowNext=MAXFOTOS-1;
	}

    newHTML = '<div id="div_cubo_img">';
	newHTML = newHTML + '<ul>';

		newHTML = newHTML + '<div id="hoverNav">';
		newHTML = newHTML + '<a href="#" onclick="viewFoto(RowPrev);PresentarFotosOFF();" id="prevLink"><img src="/imagenes/blank.gif" border=0></a>';
		newHTML = newHTML + '<a href="#" onclick="viewFoto(RowNext);PresentarFotosOFF();" id="nextLink"><img src="/imagenes/blank.gif" border=0></a>';
		newHTML = newHTML + '</div>';

	newHTML = newHTML + '<div id="div_cubo_img_foto">';
//    newHTML = newHTML + '<img src="' + imagename + '" border="0" width="618" height="425">';
    newHTML = newHTML + '<img src="' + imagename + '" border="0">';

	newHTML = newHTML + '</div>';
	newHTML = newHTML + '<h3>' + title + '</h3>';	
	newHTML = newHTML + description + '<br/><br/>';
	newHTML = newHTML + 'Fotos: '+ credito;
    newHTML = newHTML + ' <font color="#666666">|</font> Publicado el '+fecha + '<br/>';
	newHTML = newHTML + '</ul>';
	newHTML = newHTML + '</div>';
	gettrailobjnostyle().innerHTML = newHTML;

}
//-----------------------------------------------------------------------

