/*
 * Funciones en JavaScript creadas por Soluciones Nexus
 * */

var fotNum = 8;
var fotAct = 1;
var fotNom = 'imag/quienes/';
var fotExt = '.jpg';

/*
 * Función que propone una de las imágenes de la galería.
 * */
function cambiaImagen ()
{
  if (fotAct < 10)
    document.getElementById('imagenGaleria').src = fotNom + '00' + fotAct + fotExt;
  else if (fotAct < 100)
    document.getElementById('imagenGaleria').src = fotNom + '0' + fotAct + fotExt;
  else
    document.getElementById('imagenGaleria').src = fotNom + fotAct + fotExt;

  if (fotAct < 9)
    document.getElementById('cache').src = fotNom + '00' + (fotAct+1) + fotExt;
  else if (fotAct < 99)
    document.getElementById('cache').src = fotNom + '0' + (fotAct+1) + fotExt;
  else if (fotAct < fotNum)
    document.getElementById('cache').src = fotNom +  (fotAct+1) + fotExt;
  else
    document.getElementById('cache').src = fotNom + '001' + fotExt;

  setTimeout("aclara()",100);
}


/*
* Pulsamos flecha adelante.
* */
function anterior()
{
  if (fotAct > 1)
    fotAct--
  else
    fotAct = fotNum;
  oscurece();
  setTimeout ("cambiaImagen()",600);
}

/*
* Pulsamos flecha hacia detrás.
* */
function posterior()
{
  if (fotAct < fotNum)
    fotAct++
  else
    fotAct = 1;
  oscurece();
  setTimeout ("cambiaImagen()",600);
}

/*
 * Oscurece.
 * */
function oscurece ()
{
  var el = $('imagenGaleria');
  el.fade(0);
}

/*
 * Aclara.
 * */
function aclara ()
{
  var el = $('imagenGaleria');
  el.fade(1);
}

/*
 * Función que elige la primera imágen que se muestra.
 * */
function primeraImagen ()
{
  var retImg = -1;

  while ((retImg < 1) || (retImg >= fotNum))
    retImg = Math.round (1000*Math.random());

  fotAct = retImg;
  cambiaImagen();
}

/*
 * Función que ejecuta un carrusel.
 * */
function carrusel() {
  setTimeout ("posterior()",600);
  setTimeout ("carrusel()",10000);
}

