

// Begin User Configurable Variables:

var imgsPerPg = 6; // number of img elements in the html


//ESTAS SON LAS VARIABLES QUE HAY QUE SETEAR

var imgsMax = new Array();
imgsMax[1] = 269;  // total number of images casting
imgsMax[2] = 171;  // total number of images locaciones

var sPath = new Array();
sPath[1] = '../imagenes/casting/'; // slideshow files (big imgs) path, include trailing slash
sPath[2] = '../imagenes/locaciones/'; // slideshow files (big imgs) path, include trailing

var sPrefix = new Array();
sPrefix[1] = 'casting';
sPrefix[2] = 'locaciones';

//FIN DE ESTAS SON LAS VARIABLES QUE HAY QUE SETEAR


var sSuffix = '';
var sExt = '.jpg';
var sZeros = true; // filename uses leading zeros?                     
var sDigits = 3    // total digits in filename, including leading zeros


window.onload = function()
{
  xImgGallery(1); 
  xImgGallery(2);
};



/* Development Notes and Script Assumptions:

1) Optional URL arguments: g = 'gallery first num', s = 'slideshow img num'.
   For example:
   img_gallery_2.php?g=21
   img_gallery_2.php?s=30

2) IMG IDs begin with 'g' (for gallery) or 's' (for slideshow)
   then are numbered sequentially beginning with 1. No leading zeros.

3) Gallery (thumbnail) image pathnames: gPath + gPrefix + seq_num + gSuffix + gExt
   SlideShow (large image) pathnames:   sPath + sPrefix + seq_num + sSuffix + sExt
   Leading zeros (as part of seq_num) are optional.

4) The captions array initializations could be generated server-side.

5) This file does not have to be a PHP file - I use it here for my page-template, not for this demo.
*/

/* xImgGallery, Copyright (C) 2004,2005 Michael Foster (Cross-Browser.com)
   Distributed under the terms of the GNU LGPL.
*/

// don't change these:
var galMode = false;
var autoSlide = false;
var slideTimer = null;
var slideCounter = 0;
var currentSlide = 1;

function xImgGallery(inst)
{
//inst=1;
  if (document.getElementById && document.getElementById('navigation'+inst).style) {
    var n = 1, a = xGetURLArguments();
    if (a.length) {
      var arg = a['g'] || a['s'];
      if (arg) {
        n = parseInt(arg, 10);
        if (n <= 0 || n > imgsMax[inst]) { n = 1; } 
        if (a['s']) { galMode = false; }
      }
    }
   gal_paint(n, inst);
   //document.getElementById('time').style.display = 'none';
  } 
	
}


function gal_paint(n, inst) 
{
  gal_setImgs(n, inst); 
  gal_setNav(n, inst);
}

function gal_setImgs(n, inst) {
  var ssEle = document.getElementById('slideshow'+inst);
  var i, imgTitle, pth, img, id, src, ipp, idPrefix, imgSuffix, imgPrefix;
  var zeros, digits, capEle, capPar;
    currentSlide = n;
    ipp = 1;
    idPrefix = 's'+inst;
    imgPrefix = sPrefix[inst];
    imgSuffix = sSuffix + sExt;
    imgTitle = '';
    ssEle.style.display = 'block';
    pth = sPath[inst];
    zeros = sZeros;
    digits = sDigits;

  for (i = 0; i < ipp; ++i) {
    id = idPrefix + (i + 1);
    img = document.getElementById(id);
    capEle = document.getElementById((galMode ? 'gc'+inst : 'sc'+inst) + (i + 1)); 
    if (capEle) capPar = capEle.parentNode;
    if ((n + i) <= imgsMax[inst]) {
      if (zeros) src = xPad(n + i, digits, '0', true);
      else src = (n + i) + "";
      img.title = imgTitle;
      img.alt = src;
      img.src = pth + imgPrefix + src + imgSuffix; 
      img.onerror = imgOnError;
      if (galMode) {
        img.style.cursor = 'pointer';
        img.slideNum = n + i; 
        img.onclick = imgOnClick;
      }
      if (capEle) {
        capEle.innerHTML = src;
        if (capPar) capPar.style.display = 'block';
      }
      img.style.display = 'inline';
    }
    else {
      img.style.display = 'none';
      if (capEle) {
        if (capPar) capPar.style.display = 'none';
      }
    }
  }  
}
function imgOnClick(inst)
{
  galMode = false;
  gal_paint(this.slideNum, inst);
}
function imgOnError()
{
  var p = this.parentNode;
  if (p) p.style.display = 'none';
}


function gal_setNav(n, inst)
{
  var ipp =1;
  // Next
  var e = document.getElementById('next'+inst);
  if (n + ipp <= imgsMax[inst]) {
    e.nextNum = n + ipp;
    e.onclick = next_onClick;
   e.style.display = 'inline';
  }
  else {
    e.nextNum = 1;
  }
  // Previous
  e = document.getElementById('prev'+inst);
  e.style.display = 'inline';
  e.onclick = prev_onClick;
  if (n > ipp) {
    e.prevNum = n - ipp;
  }
  else {
    e.prevNum = galMode ? normalize(imgsMax[inst]) : imgsMax[inst];
  }

}

function normalize(n)
{
  return 1 + imgsPerPg * (Math.ceil(n / imgsPerPg) - 1);
}
function next_onClick(e, inst)
{
  inst = this.id.substr(4);
  gal_paint(this.nextNum, inst);
}
function prev_onClick(e, inst)
{
  inst = this.id.substr(4);
  gal_paint(this.prevNum, inst);
}
function back_onClick(e, inst)
{
  galMode = true;
  if (slideTimer) {
    clearTimeout(slideTimer);
  }
  autoSlide = false;
  gal_paint(this.backNum, inst);
  document.getElementById('time').style.display = 'none';
}
function auto_onClick(e)
{
  var ele = document.getElementById('time');
  autoSlide = !autoSlide;
  if (autoSlide) {
    slideCounter = 0;
    slideTimer = setTimeout("slide_OnTimeout()", slideTimeout);
    ele.style.display = 'inline';
  }
  else if (slideTimer) {
    clearTimeout(slideTimer);
    ele.style.display = 'none';
  }
}
function slide_OnTimeout()
{
  slideTimer = setTimeout("slide_OnTimeout()", 1000);
  ++slideCounter;
  document.getElementById('time').innerHTML = slideCounter + '/' + slideTimeout;
  if (slideCounter == slideTimeout) {
    if (++currentSlide > imgsMax[inst]) currentSlide = 1; 
    gal_paint(currentSlide);
    slideCounter = 0;
  }
}

/* xGetURLArguments and xPad are part of the X library,
   distributed under the terms of the GNU LGPL,
   and maintained at Cross-Browser.com.
*/
function xGetURLArguments()
{
  var idx = location.href.indexOf('?');
  var params = new Array();
  if (idx != -1) {
    var pairs = location.href.substring(idx+1, location.href.length).split('&');
    for (var i=0; i<pairs.length; i++) {
      nameVal = pairs[i].split('=');
      params[i] = nameVal[1];
      params[nameVal[0]] = nameVal[1];
    }
  }
  return params;
}
function xPad(str, finalLen, padChar, left)
{
  if (typeof str != 'string') str = str + '';
  if (left) { for (var i=str.length; i<finalLen; ++i) str = padChar + str; }
  else { for (var i=str.length; i<finalLen; ++i) str += padChar; }
  return str;
}

