$(document).ready( function() {
	$("#gallery_list li a").each( function() {
		$(this).css({'padding': '5px 0px'});
		$(this).prepend('<span class="white"></span>').append('<span class="white"></span>');
		$(this).attr({'rel': $(this).attr('href')});
		$(this).attr({'href': 'javascript:void(0)'});
		$(this).click( function() {
			$this = $(this);
			$(this).parents().find('ul')
				.find('a').removeClass('selected')
				.parent().find('span').addClass('white');
			$(this).parent().find('span').removeClass('white');
			$(this).addClass('selected');
			var img = './bpimages/gallery/small_images/'+$(this).attr('id').split('_')[1]+'.jpg';
			$("#photo_caption span").hide().html( $(this).attr('title') ); // Fade out caption and replace with next image's.
			$("#gallery_photo").fadeOut('fast', function(){ 
				$("#gallery_photo").attr({'src': $this.attr('rel')}); // Fade in the image.
				$("#gallery_photo").fadeIn('slow');
			});
			$("#photo_caption span").show();
			$("#view_larger_image a").attr({'rel':$(this).attr('location')});
			var bool = $(this).hasClass("vertical");
			var mover = function() { moveCaption(bool); }
			setTimeout(mover, 200);
			}).mouseover( function() {
			$(this).parent().find('span').removeClass('white');
		}).mouseout( function() {
			if ( $(this).hasClass('selected') ){} else { $(this).parent().find('span').addClass('white'); }
		});
	});
	$("#a_01").click();
	$("#view_larger_image a").attr({'href': 'javascript:void(0)'});
	$("#view_larger_image a").click( function() {
		var new_image = $(this).attr('rel');
		if ($(this).hasClass('changed')){
			$("#frame_background_2").css({'background-image':'url('+new_image+')'});
			$("#frame_background_2").fadeIn();
			$(this).removeClass('changed');			
		} else {
			$("#frame_background").css({'background-image':'url('+new_image+')'});
			$("#frame_background_2").fadeOut();
			$(this).addClass('changed');			
		}
		closeTab();
	});
});

function slideshow(){
	$("#frame").css({ 'background-image': 'url(' + nextImage + ')' }); // Set next image as background.
	$("#photo").fadeOut('slow', function(){ 
		$("#photo").attr({'src': nextImage}); // Fade in the image.
		$("#photo").fadeIn('slow');
	});
}

function moveCaption(bool){
	if (bool == 1){
		$("#view_larger_image img").attr({'src':"./bpimages/gallery/larger_image_not_available.jpg"});
		$("#view_larger_image a").css({'cursor':'default'});
		$("#photo_caption").css({'position':'absolute'});
	} else {
		if ($("#photo_caption").css('position') == 'absolute'){
			$("#photo_caption").css({'position':'static'});
			$("#view_larger_image img").attr({'src':"./bpimages/gallery/view_larger_image.jpg"});
			$("#view_larger_image a").css({'cursor':'pointer'});
		}
	}
}