// 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);
		$("#photoImageTitle").html($(this).parent().find(".photoItemTitle").html());
		$("#photoImageDescription").html($(this).parent().find(".photoItemDescription").html());
		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:first a').attr('href');
	showImage(firstImageSource);
	$("#photoImageTitle").html($("#photoItems div.photoItem:first .photoItemTitle").html());
	$("#photoImageDescription").html($("#photoItems div.photoItem:first .photoItemDescription").html());
}

