image_files = [];
image_links = [];


function set_image_num (new_index) {
  var node;
  
  // turn off old item with on-state
  node = document.getElementById ('imgnav' + this_image_num);
  if (node == null) return;
  node.className = '';
  
  // change image num
  this_image_num = new_index;
  
  // change the image
  node = document.getElementById ('main_image');
  if (node == null) return;
  node.src = image_files[this_image_num];
  
  $('#main_text').html('');
  
  if (image_links[this_image_num] != '') {
    $('#main_text').append('<br><b>View site:</b> <a href="' + image_links[this_image_num] + '" target="_blank">' + image_links[this_image_num] + '</a>');
  }
  
  
  // turn on old item with on-state
  node = document.getElementById ('imgnav' + this_image_num);
  if (node == null) return;
  node.className = 'current';
}


function set_image_prev () {
  if (this_image_num > 0) {
    set_image_num (this_image_num - 1);
  }
}


function set_image_next () {
  if (this_image_num < max_image_num) {
    set_image_num (this_image_num + 1);
  }
}


function preload_images () {
  var image;
  
  for (i in image_files) {
    image = new Image();
    image.src = image_files[i];
  }
}

