$(document).ready(function() {
	
	// ====================================
	// = Content showing for main buttons =
	// ====================================
	
	// The function to show the main content by layer
	function showContent(layer, animate) {
		
		$("#background").show();
		$("#people_html").hide();
		$("#nature_html").hide();
		$("#things_html").hide();
		$("#city_html").hide();
		$("#footer").hide();
		$("#announcement").hide();

		$("#" + layer + "_html").show();

		$("#nav").children().each(function() {
			if ($(this).attr("id").search(layer) == -1) {
				$(this).addClass("inactive");
			} else {
				$(this).removeClass("inactive");
			}
		});

		if (animate == true) {
			$('html,body').animate({scrollTop: $("#nav").offset().top - 16}, 200, "swing");
		}
		
		// setUpHover();
		setupHovers();
		
	
		
		window.location.hash = layer;
	}
	
	// Set up the on click functions for the different menus
	$("#nav").children().click(function() {
		showContent($(this).attr("id").split("_")[1], true);
	});
	
	$("#display_people").addClass("with_pointer");
	
	$("#display_people").click(function() {
		showContent($(this).attr("id").split("_")[1], true);
	});
	
	
	
	// If there is a location has we open the layer with the content and scroll to it,
	// but only if we're not coming from the same url, because then we'd like to end up
	// at the scroll position we were.
	if (window.location.hash && document.referrer != window.location) {
		showContent(window.location.hash.replace("#", ""), false);
	}
	


	// =========================
	// = Main page menu hovers =
	// =========================
	
	function setupHovers() {	
		$(".hoverable").hover(
			function() {$(this).addClass("hover")},
			function() {$(this).removeClass("hover")}
		);

	};
	
	setupHovers();
	
});



							$(document).ready(function() {
								
					
								$("a[rel=people]").fancybox({
									'transitionIn'		: 'none',
									'transitionOut'		: 'none',
									'titlePosition' 	: 'over',
									'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
										return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
									}
								});
					
								
							});
							
							
							$(document).ready(function() {
								
					
								$("a[rel=nature]").fancybox({
									'transitionIn'		: 'none',
									'transitionOut'		: 'none',
									'titlePosition' 	: 'over',
									'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
										return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
									}
								});
					
								
							});
							
							

							
							$(document).ready(function() {
								
					
								$("a[rel=things]").fancybox({
									'transitionIn'		: 'none',
									'transitionOut'		: 'none',
									'titlePosition' 	: 'over',
									'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
										return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
									}
								});
					
								
							});
