$(document).ready(function() {
				
	$('.post').each(function() {
	
		$(this).wrap('<div id="container"></div>');
		
		$('p').filter(':last').after('<div id="infiniteCarousel"><div id="wrapper"><ul></ul></div></div>');
		
		$('p', this).each(function() {
			$(this).after($(this).html()).remove();
		});
		
		$('#infiniteCarousel').before('<div id="large"></div>');
		
		$('img', this).each(function() {
			var url = $(this).attr('src');
			$(this)
				// Remove Width And Height Values
				.removeAttr('width')
				.removeAttr('height')
				// Wrap In a List item and a Link
				.wrap('<li><a href="' + url + '"></a></li>')
				.parent().parent()
				// Pretty obvious
				.appendTo('#wrapper ul');
			
		});
		
	});
	
	$("#infiniteCarousel").infiniteCarousel();
	
	$('#large').css({
		background: 'url(/slideshow.jpg) no-repeat center center'
	});
		
	
	$('ul a', '#infiniteCarousel').click(function() {
		
		var img_location = $('img', this).attr('src');
		
		if( !$(this).hasClass('selected') ) {
			$('ul a').removeClass('selected');
			$(this).addClass('selected');
			$('#large').find('img').remove();
			$('#large').append('<img src="" class="image" />').css({
				background: 'none'
			});
			$('.image', '#large').attr('src', img_location);
			$('.image', '#large').css({
				opacity: '0',
				left: ($('#large').width() / 2) - ($('img', '#large').width() / 2),
				top: ($('#large').height() / 2) - ($('img', '#large').height() / 2)
			}).animate({
				opacity: 1
			});
		}
		return false;
	});
	
});
