// Begin User Configurable Variables:



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

var imgsMax = 51;  // total number of images

var slideTimeout = 3; // seconds before loading the next slide



var gPath = '../../images/galeria/';  // gallery files (thumbnails) path, include trailing slash

var gPrefix = '';

var gSuffix = 'tn';

var gExt = '.jpg';

var gZeros = true; // filename uses leading zeros?

var gDigits = 2    // total digits in filename, including leading zeros



var sPath = '../../images/galeria/'; // slideshow files (big imgs) path, include trailing slash

var sPrefix = '';

var sSuffix = '';

var sExt = '.jpg';

var sZeros = true; // filename uses leading zeros?                     

var sDigits = 2    // total digits in filename, including leading zeros



var captions = new Array();//datos para el Slideshow

// There must be (imgsMax + 1) captions.

// captions[0] is currently not used.

captions[0] = "not used";

captions[51] = "41. 'Doble visió'<br>Oli sobre fusta<br>50 x 55 cm";
captions[50] = "42. 'Vell'<br>Oli sobre fusta<br>55 x 60 cm";
captions[49] = "43. 'Troballa'<br>Oli sobre fusta<br>20 x 20 cm";
captions[48] = "44. 'Jo'<br>Oli sobre fusta<br>20 x 20 cm";
captions[47] = "45. 'Tu'<br>Oli sobre fusta<br>20 x 20 cm";
captions[46] = "47. 'Ella'<br>Oli sobre fusta<br>20 x 20 cm";
captions[45] = "48. 'Destí'<br>Tècnica mixta sobre fusta<br>20 x 20 cm";
captions[44] = "49. 'Pastors...'<br>Tècnica mixta sobre fusta<br>20 x 20 cm";
captions[43] = "50. Sense títol<br>Tècnica mixta sobre fusta<br>20 x 20 cm";
captions[42] = "51. Sense títol<br>Tècnica mixta sobre fusta<br>20 x 20 cm";
captions[41] = "52. Sense títol<br>Tècnica mixta sobre fusta<br>20 x 20 cm";
captions[40] = "53. 'Son'<br>Tècnica mixta sobre fusta<br>20 x 20 cm";
captions[39] = "54. 'Nena'<br>Tècnica mixta sobre fusta<br>20 x 20 cm";
captions[38] = "55. 'Mirall?'<br>Oli sobre fusta<br>30 x 35 cm";
captions[37] = "56. 'Mai és tard'<br>Oli sobre fusta<br>50 x 56 cm";
captions[36] = "57. 'Elsa'<br>Oli sobre fusta<br>48 x 50 cm";
captions[35] = "65.'Inspiració de les aigües'<br>Tècnica mixta sobre fusta<br>30 x 30 cm";
captions[34] = "66.'La petxina presumida'<br>Tècnica mixta sobre fusta<br>20 x 20 cm";
captions[33] = "67.'L'ull de la tempesta'<br>Tècnica mixta sobre fusta<br>20 x 20 cm";
captions[32] = "69. Sense títol<br>Tècnica mixta sobre fusta<br>25 x 35 cm";
captions[31] = "70.'Equilibri'<br>Tècnica mixta sobre fusta<br>42 x 42 cm";
captions[30] = "71.'Deconstrucció'<br>Tècnica mixta sobre fusta<br>70 x 70 cm";
captions[29] = "72.'L'ull'<br>Tècnica mixta sobre fusta<br>70 x 50 cm";
captions[28] = "73.'Refugi'<br>Tècnica mixta sobre fusta<br>60 x 40 cm";
captions[27] = "74.'Viatge'<br>Tècnica mixta sobre fusta<br>65 x 35 cm";
captions[26] = "75.'Portadora'<br>Tècnica mixta sobre fusta<br>70 x 50 cm";
captions[25] = "76.'Escalfor'<br>Tècnica mixta sobre fusta<br>20 x 20 cm";
captions[24] = "77.'Més del que veiem'<br>Tècnica mixta sobre fusta<br>60 x 40 cm";
captions[23] = "78.'Les dues cares'<br>Tècnica mixta sobre fusta<br>20 x 40 cm";
captions[22] = "79.'Confusió'<br>Tècnica mixta sobre fusta<br>34 x 65 cm";
captions[21] = "80.'Traient ferro'<br>Tècnica mixta sobre fusta<br>34 x 52 cm";
captions[20] = "101.'Formacions'<br>Tècnica mixta sobre fusta<br>33 x 53 cm";
captions[19] = "102. Sense títol<br>Tècnica mixta sobre fusta<br>35 x 70 cm";
captions[18] = "103.'Depèn'<br>Tècnica mixta sobre fusta<br>33 x 72 cm";
captions[17] = "104.'La fugida de la màscara'<br>Tècnica mixta sobre fusta<br>33 x 52 cm";
captions[16] = "105. Sense títol<br>Tècnica mixta sobre fusta<br>20 x 20 cm";
captions[15] = "106.'Flor'<br>Tècnica mixta sobre fusta<br>35 x 70 cm";
captions[14] = "107.'Formes'<br>Tècnica mixta sobre fusta<br>35 x 70 cm";
captions[13] = "108.'La meditació del guerrer'<br>Tècnica mixta sobre fusta<br>25 x 25 cm";
captions[12] = "109.'Formació'<br>Tècnica mixta sobre fusta<br>25 x 25 cm";
captions[11] = "110.'Rostre'<br>Tècnica mixta sobre fusta<br>25 x 25 cm";
captions[10] = "111.'Sense títol'";
captions[9] = "112.'Sense títol'";
captions[8] = "113.'Sense títol'";
captions[7] = "114.'Sense títol'";
captions[6] = "115.'Sense títol'";
captions[5] = "116.'Sense títol'";
captions[4] = "117.'Sense títol'";
captions[3] = "118.'Sense títol'";
captions[2] = "119.'Sense títol'";
captions[1] = "120.'Sense títol'";




var names = new Array(); //titulos para rollover de la galería

// There must be (imgsMax + 1) namess.

// names[0] is currently not used.

names[0] = "not used";
names[51] = "41. 'Doble visió'";
names[50] = "42. 'Vell'";
names[49] = "43. 'Troballa'";
names[48] = "44. 'Jo'";
names[47] = "45. 'Tu'";
names[46] = "47. 'Ella'";
names[45] = "48. 'Destí'";
names[44] = "49. 'Pastors...'";
names[43] = "50. Sense títol";
names[42] = "51. Sense títol";
names[41] = "52. Sense títol";
names[40] = "53. 'Son'";
names[39] = "54. 'Nena'";
names[38] = "55. 'Mirall?'";
names[37] = "56. 'Mai és tard'";
names[36] = "57. 'Elsa'";
names[35] = "65.'Inspiració de les aigües'";
names[34] = "66.'La petxina presumida'";
names[33] = "67.'L'ull de la tempesta'";
names[32] = "69. Sense títol";
names[31] = "70.'Equilibri'";
names[30] = "71.'Deconstrucció'";
names[29] = "72.'L'ull'";
names[28] = "73.'Refugi'";
names[27] = "74.'Viatge'";
names[26] = "75.'Portadora'";
names[25] = "76.'Escalfor'";
names[24] = "77.'Més del que veiem'";
names[23] = "78.'Les dues cares'";
names[22] = "79.'Confusió'";
names[21] = "80.'Traient ferro'";
names[20] = "101.'Formacions'";
names[19] = "102. Sense títol";
names[18] = "103.'Depèn'";
names[17] = "104.'La fugida de la màscara'";
names[16] = "105. Sense títol";
names[15] = "106.'Flor'";
names[14] = "107.'Formes'";
names[13] = "108.'La meditació del guerrer'";
names[12] = "109.'Formació'";
names[11] = "110.'Rostre'";
names[10] = "111.'Sense títol'";
names[9] = "112.'Sense títol'";
names[8] = "113.'Sense títol'";
names[7] = "114.'Sense títol'";
names[6] = "115.'Sense títol'";
names[5] = "116.'Sense títol'";
names[4] = "117.'Sense títol'";
names[3] = "118.'Sense títol'";
names[2] = "119.'Sense títol'";
names[1] = "120.'Sense títol'";


// End User Configurable Variables



function winOnLoad()

{

  xImgGallery();

}





// don't change these:

var galMode = true;

var autoSlide = false;//no quiero que cambien de forma automática

var slideTimer = null;

var slideCounter = 0;

var currentSlide = 1;



function xImgGallery()

{

  if (document.getElementById && document.getElementById('navigation').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) { n = 1; } 

        if (a['s']) { galMode = false; }

      }

    }

    gal_paint(n);

     var e = document.getElementById('time');

    if (e) e.style.display = 'none'; // mf

  }

}

function gal_paint(n)

{

  gal_setImgs(n);

  gal_setNav(n);

}

function gal_setImgs(n)

{

  var ssEle = document.getElementById('slideshow');

  var galEle = document.getElementById('gallery');

  var i, imgTitle, pth, img, id, src, ipp, idPrefix, imgSuffix, imgPrefix;

  var zeros, digits, capEle, capPar;

  if (galMode) {

    ipp = imgsPerPg;

    idPrefix = 'g';

    imgPrefix = gPrefix;

    imgSuffix = gSuffix + gExt;

    imgTitle = '';// sería captions [n], pero no quiero qeu aparezca con ese <br>

    ssEle.style.display = 'none';

    galEle.style.display = 'block';

    pth = gPath;

    zeros = gZeros;

    digits = gDigits;

  }

  else {

    currentSlide = n;

    ipp = 1;

    idPrefix = 's';

    imgPrefix = sPrefix;

    imgSuffix = sSuffix + sExt;

    imgTitle = '';// sería captions [n], pero no quiero que aparezca con ese <br>

    ssEle.style.display = 'block';

    galEle.style.display = 'none';

    pth = sPath;

    zeros = sZeros;

    digits = sDigits;

  }

  for (i = 0; i < ipp; ++i) {

    id = idPrefix + (i + 1);

    img = document.getElementById(id);

    capEle = document.getElementById((galMode ? 'gc':'sc') + (i + 1));

    if (capEle) capPar = capEle.parentNode;

    if ((n + i) <= imgsMax) {

      if (zeros) src = xPad(n + i, digits, '0', true);

      else src = (n + i) + "";

      img.title = ''; // toma el título de la variable names OJO!! names [n+i] (no es [n], sino [n+i])

      img.alt = names[i + n];

      img.src = pth + imgPrefix + src + imgSuffix; // img to load now

      img.onerror = imgOnError;

      if (galMode) {

        img.style.cursor = 'pointer';

        img.slideNum = n + i; // slide img to load onclick

        img.onclick = imgOnClick;

      }

      if (capEle) {

        capEle.innerHTML = galMode ? names[i + n] : captions[i + n]; // mf

        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()

{

  galMode = false;

  gal_paint(this.slideNum);

}

function imgOnError()

{

  var p = this.parentNode;

  if (p) p.style.display = 'none';

}

function gal_setNav(n)

{

  var ipp = galMode ? imgsPerPg : 1;

  // Next

  var e = document.getElementById('next');

  if (n + ipp <= imgsMax) {

    e.nextNum = n + ipp;

    e.onclick = next_onClick;

    e.style.display = 'inline';

  }

  else {

    e.nextNum = 1;

  }

  // Previous

  e = document.getElementById('prev');

  e.style.display = 'inline';

  e.onclick = prev_onClick;

  if (n > ipp) {

    e.prevNum = n - ipp;

  }

  else {

    e.prevNum = galMode ? normalize(imgsMax) : imgsMax;

  }

  // Back

  e = document.getElementById('back');

  if (!galMode) {

    e.onclick = back_onClick;

    e.style.display = 'inline';

    e.backNum = normalize(n);

  }

  else {

    e.style.display = 'none';

  }

   // Auto Slide

  e = document.getElementById('auto');

  if (e) { // mf

    if (!galMode) {

      e.onclick = auto_onClick;

      e.style.display = 'inline';

    }

    else {

      e.style.display = 'none';

    }

  }

  

  

  // Auto Slide

  e = document.getElementById('auto');

  if (!galMode) {

    e.onclick = auto_onClick;

    e.style.display = 'inline';

  }

  else {

    e.style.display = 'none';

  }

}

function normalize(n)

{

  return 1 + imgsPerPg * (Math.ceil(n / imgsPerPg) - 1);

}

function next_onClick(e)

{

  gal_paint(this.nextNum);

}

function prev_onClick(e)

{

  gal_paint(this.prevNum);

}

function back_onClick(e)//

{

  galMode = true;

  if (slideTimer) {

    clearTimeout(slideTimer);

  }

  autoSlide = false;

  gal_paint(this.backNum);

    var e = document.getElementById('time');

  if (e) e.style.display = 'none'; // mf

}

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) 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;

}





