var pics = new Array();
pics.push('david_evan_thomas_headshot0.jpg');
pics.push('david_evan_thomas_headshot1.jpg');
pics.push('david_evan_thomas_headshot2.jpg');
pics.push('david_evan_thomas_headshot3.jpg');
pics.push('det_conduct-slide.jpg');
pics.push('det_listening.jpg');
pics.push('landmark_plaza_square.jpg');
pics.push('det_wales1-slide.jpg');
pics.push('det_wales2-slide.jpg');
pics.push('det_fleming.jpg');
pics.push('det_teaching.jpg');
pics.push('det_parents-slide.jpg');
pics.push('det_montana-slide.jpg');
pics.push('det_noa.jpg');
pics.push('det_griggfest-slide.jpg');
pics.push('det_aspen.jpg');
pics.push('det_jazz.jpg');
pics.push('lil_det_coke.jpg');

var preload = new Array();
for(var i in pics) {
  preload[i] = new Image();
  preload[i].src = 'photos/' + pics[i];
}

var photo_container;
var prev_link;
var next_link;
var current_photo = 0;

window.onload = init;
function init() {
  photo_container = document.getElementById('photo_container');
  prev_link = document.getElementById('prev_link');
  next_link = document.getElementById('next_link');
  set_state();
}

function next_pic() {
  if( current_photo < preload.length - 1 ) current_photo++;
  set_state();
}

function prev_pic() {
  if( current_photo > 0 ) current_photo--;
  set_state();
}

function set_state() {
  // remove last viewed image and add current photo in its place
  while( photo_container.childNodes.length > 0 )
    photo_container.removeChild( photo_container.childNodes[0] );
  photo_container.appendChild( preload[current_photo] );
  
  // show or hide prev and next links
  if( current_photo <= 0 ) prev_link.style.visibility = 'hidden';
  else prev_link.style.visibility = 'visible';
  if( current_photo >= preload.length - 1 ) next_link.style.visibility = 'hidden';
  else next_link.style.visibility = 'visible';
}