// Script for Photo Gallery pages

$(document).ready(function() {
  loadFirstImage();
  $('#photoItems div.photoItem').each(function() {
    if ($(this).find('a.photoItemImage img').attr('src') == '') {
      $(this).hide();
    }
  });
});

$(function() {
  $('#photoItems div.photoItem a.photoItemImage').click(function() {
    var imageSource = $(this).attr("href");
    $("#photoLargeImage").addClass("loading");
    showImage(imageSource);
    return false;
  });
});

function showImage(src) {
  $('#photoLargeImage img').fadeOut('normal').remove();
  var largeImage = new Image();
  $(largeImage).load(function() {
    $(this).hide();
    $('#photoLargeImage').append(this).removeClass("loading");
    $(this).fadeIn('slow');
  });
  $(largeImage).attr('src', src);
}

function loadFirstImage() {
  var firstImageSource = $('#photoItems div.photoItem a:first').attr('href');
  showImage(firstImageSource);
}

