var swapInterval = null;

function swapImage (imageName)
{
  var img = document.getElementById('mainImage');
  var image = new Image()
  image.src = '../images/gallery/previews/' + imageName + '.jpg';
  if (swapInterval)
    clearInterval(swapInterval);
  swapInterval = setInterval(function ()
  {
    if (image.height > 0)
    {
      clearInterval(swapInterval);
      swapInterval = null;
      img.src = image.src;
      img.height = image.height;
      img.width = image.width;
    }
  }, 100);
  document.getElementById('gallery-link').href = '../images/gallery/' + imageName + '.jpg';
}

