bgPix = [
  {"image":"sac-leaves.jpg", "caption":"Feet in the leaves. Sacramento, on the night of a dear friend’s funeral. October, 2007."},
  {"image":"coachella-fence.jpg", "caption":"Staring up at the sky. Coachella Valley Music and Arts Festival. April, 2007"},
  {"image":"sf-holga.jpg", "caption":"Walking down Jones Street with a Holga. San Francisco. April, 2008"},
  {"image":"austin-snocone.jpg", "caption":"Buying a snow cone with Holga in hand. Austin, Texas. May, 2008"},
  {"image":"bryce-sunrise.jpg", "caption":"Waking up for the sunrise. Bryce Canyon, Utah. November, 2006"},
  {'image':'hamptons-beach.jpg', 'caption':'Waiting for a storm on the beach. West Hampton. June, 2009'},
  {'image':'central-park.jpg', 'caption':'Sunset on a lazy Saturday in Central Park. New York City. April, 2009'},
  {'image':'lake-contrary.jpg', 'caption':'Pontoon boat ride on Lake Contrary. Saint Joseph. June, 2009'},
  {'image':'ba-cemetery.jpg', 'caption':'La Recoleta Cemetery. Buenos Aires. September, 2009'},
  {'image':'ba-ranch.jpg', 'caption':'Estancia Los dos Hermanos. Buenos Aires. September, 2009'},
  {'image':'mo-winter.jpg', 'caption':'After the ice storm. Saint Joseph. December, 2008'},
  {'image':'ellis-island.jpg', 'caption':'Dad and I at the wall of immigrants. Ellis Island. November, 2008'},
  {'image':'utah_zion.jpg', 'caption':'Zion National Park, Utah. June, 2010'},
  {'image':'mo-plane.jpg', 'caption':'Flying out of Kansas City, Missouri. July, 2010'},
  {'image':'lantau.jpg', 'caption':'Lantau Island, Hong Kong. December, 2010'}
];

total_images = bgPix.length;

randomnumber = function(){
  return Math.floor(Math.random()*total_images);
}

var swap = function(integer){
  current_image = integer
  $('#caption').text(bgPix[integer].caption);
  $('body').css("background-image","url(backgrounds/" + bgPix[integer].image + ")");
};

$(document).ready(function (){
  swap(randomnumber());
  
  $('#next-photo').click(function(){
    if (current_image + 1 < total_images) {
      swap(current_image + 1);
    }
    else {
      swap(0);
    }
  });
});


