$(document).ready(function() {

		// Home page
	if (!($.browser.msie && $.browser.version <= 6)) {
		if ($("body#home").length) {
			$("#box-news").append('<p id="box-news-show"><a href="#">Read more</a></p>');
			$("#box-news-show").fancybox({
				width: function() {
					return $("#popup-news-picture img").attr('width');
				},
				height: function() {
					return $("#popup-news-picture img").attr('height');
				},
				padding: 0,
				margin: 0,
				autoScale: false,
				autoDimensions: false,
				content: function() {
					return $("#popup-news-picture").html();
				}
			});
		}
	}

		// Fancybox up the scrapbook
	if ($("ul#the-scrapbook").length) {
		$(window).bind("load", function(e) {
			var fancyboxSlides = [];
			$("ul#the-scrapbook li .detail").each(function() {
				fancyboxSlides.push({
					content: $(this).html(),
					width: $(this).outerWidth(),
					height: $(this).outerHeight()
				});
			}).remove();
			$("ul#the-scrapbook").data('fancyboxSlides', fancyboxSlides);
			$("ul#the-scrapbook li")
				.bind("click", function(e) {
					$.fancybox($("ul#the-scrapbook").data('fancyboxSlides'), {
						padding: 0,
						margin: 0,
						autoScale: false,
						autoDimensions: false,
						scrolling: 'no',
						index: $("ul#the-scrapbook li").index(this)
					});
					e.preventDefault();
				});
		});
	}

		// Attach Gallery functionality
	if ($("#box-slideshow").length) {
		$("#pictures li:not(:first)").fadeTo(0, 0);
		$("#box-slideshow").data("active-image", 1);
		$("#thumbnails li").bind("click.gallery", function(e) {
			var cImgNo, nImgNo, $cLargeImg, $nLargeImg;
			
				// Get the selected image number
			cImgNo = $("#box-slideshow").data("active-image");
			nImgNo = $(this).data("image-number");
			
				// Find its matching large variant
			$nLargeImg = $("#box-slideshow #pictures li[data-image-number='"+ nImgNo +"']");
			
				// Transition it!
			if ($nLargeImg.length) {
				$cLargeImg = $("#box-slideshow #pictures li[data-image-number='"+ cImgNo +"']");
				$cLargeImg.stop().fadeTo(1000, 0);
				$nLargeImg.stop().fadeTo(1000, 1);
				$("#box-slideshow").data("active-image", nImgNo);
			}
			
			e.preventDefault();
		});
	}
	
		// Find any links to news and ajaxify them
	$('a[href^="/news"]').fancybox({
		width: 600,
		height: 450,
		padding: 0,
		margin: 0,
		autoScale: false,
		autoDimensions: false,
		content: function() {
			return $('<div id="latest-news" class="ajax-container"></div>').load('/news #content > *');
		}
	});

		// Find any links to quotes and ajaxify them
	$('a[href^="/quotes"]').fancybox({
		width: 600,
		height: 450,
		padding: 0,
		margin: 0,
		autoScale: false,
		autoDimensions: false,
		content: function() {
			return $('<div id="latest-news" class="ajax-container"></div>').load('/quotes #content > *');
		}
	});

});
