var galCurrent = 0;

function getElement(v_id)
{
   // primitive DOM retrieval - supports IE and W3C methods. No NS4 support
   if (document.getElementById(v_id)) return document.getElementById(v_id);
   if (document.all[v_id]) return document.all[v_id];
   return false;
}

function galLoad()
{
   var pattern = new RegExp("(image=)([0-9]+)");
   if (document.location.href.match(pattern))
   {
      var match = document.location.href.match(pattern);
      galCurrent = parseInt(match[2]);
   }
   galShow();
}

function galShow()
{
   // update preview pane
  if (getElement('galImage'))
  {
     getElement('galImage').src = 'gallery'+ galleryId +'/'+ gallery[galCurrent][3];
     getElement('galImage').setAttribute('alt', gallery[galCurrent][0]);
     getElement('galTitle').innerHTML = gallery[galCurrent][0];
     getElement('galAbstract').innerHTML = gallery[galCurrent][1];
     getElement('galStatus').innerHTML = gallery[galCurrent][4];
     getElement('galCounter').innerHTML = '<STRONG>Picture '+ (galCurrent+1) +'</STRONG> of '+ gallery.length;

     if (galCurrent==0)
     {
        getElement('galPrevious').style.display = 'none';
     } else {
        getElement('galPrevious').style.display = 'block';
     }

     if (galCurrent>=gallery.length-1)
     {
        getElement('galNext').style.display = 'none';
     } else {
        getElement('galNext').style.display = 'block';
     }

     setTimeout('galPreload()', 350);
   }
}

function galThumbs()
{
   window.location.href = 'thumbnails'+ galleryId +'.html';
}

function galPicture(pic)
{
    window.location.href = 'gallery'+ galleryId +'.html?image='+ pic;
}

function galPos()
{
   getElement('galImage').style.display = 'block';
   var h = parseInt(getElement('galImage').offsetHeight);
   var w = parseInt(getElement('galImage').offsetWidth);
   if (w>h)
   {
      getElement('galWindow').style.height = '535px';
      getElement('galSubWindow').style.left = '0';
   } else {
      getElement('galWindow').style.height = '615px';
      getElement('galSubWindow').style.left = Math.round((455 - w)/2) + 'px';
   }
}

function galNext()
{
   // load next image
  if (galCurrent<gallery.length-1)
  {
     f_fadeOut('galImage', 0);
     galCurrent++;
     setTimeout('galShow()', 450);
  } else {
     f_fadeOut('galImage', 0);
     setTimeout('galThumbs()', 450);
  }
}

function galPrevious()
{
  // load previous image
  if (galCurrent>0)
  {
     f_fadeOut('galImage', 0);
     galCurrent--;
     setTimeout('galShow()', 450);
   }
}

function galPreload()
{
   // preload next and previous images

  if (galCurrent<gallery.length-1)
  {
     var v_preload1 = new Image;
     v_preload1.src = gallery[galCurrent+1][3];
  }

  if (galCurrent>0)
  {
     var v_preload0 = new Image;
     v_preload0.src = gallery[galCurrent-1][3];
  }

}