var slidetimer = null;
var slidepos = 0;
function slideInit() {/*{{{*/
  var i=0;

  // Select random image to display in full
  var rnd = Math.floor(Math.random()*gallery_images.length);

  // Display random image in 'gallery' div
  $('gallery_bigimage').src = 'img/fotoalbum/foto_'+gallery_images[rnd][0]+'.jpg';
  // Display random image title
  $('gallery_title').appendChild(document.createTextNode(decodeURIComponent(gallery_images[rnd][1])));

  // Add event handlers to thumbnails
  for(i=0; i<4; i++) {
    $('gallery_smallimage'+i).observe('click',gallery_onClick);
  }

  slideShow();
  slidetimer = new PeriodicalExecuter(slideShow,10);
}/*}}}*/

function gallery_onClick() {
  var i=0;

  var srcid = this.src;
  srcid = srcid.substring(srcid.lastIndexOf('/')+11);
  srcid = srcid.substring(0,srcid.length - 4);

  for(i=0; i<gallery_images.length; i++) {
    if(gallery_images[i][0] == srcid)
      break;
  }

  $('gallery_bigimage').src = 'img/fotoalbum/foto_'+gallery_images[i][0]+'.jpg';
  $('gallery_title').innerHTML = "";
  $('gallery_title').appendChild(document.createTextNode(decodeURIComponent(gallery_images[i][1])));
}

function slideShow() {/*{{{*/
  var i=0;

  for(i=0; i<4; i++) {
    $('gallery_smallimage'+i).src = 'img/fotoalbum/fotothumb_'+gallery_images[slidepos][0]+'.jpg';

    slidepos++;
    if(slidepos == gallery_images.length)
      slidepos = 0;
  }
  return;
}/*}}}*/

Event.observe(window,'load',slideInit);

