(function ($) {
	$(document).ready(function () {
		$('.view').hide();
		
		createSplash();
		createContent();
		
		$('.viewSwitch').click(function (e) {
			e.preventDefault();
			var newScreen = $($(this).attr('href'));
			$('.view:visible').fadeOut('fast', function () {
				newScreen.fadeIn('slow');
			});
		});
		
		$('.pageSwitch').click(function (e) {
			e.preventDefault();
			$('.pageSwitch').removeClass('selected');
			$(this).addClass('selected');
			var newPage = $($(this).attr('href'));
			$('.page:visible').fadeOut('fast', function () {
				$(this).hide();
				newPage.fadeIn('slow');
				if (newPage.hasClass('map'))
					showMap();
			});
		});
		
		
	});
	
	function createSplash() {
		var boerin = $('#boerinSplash');
		
		if (boerin.height() > $(window).height()-40) {
			boerin.width(boerin.width()*($(window).height()-40)/boerin.height());
			boerin.height($(window).height()-40);
		}
		$('#splash .content').width(boerin.width());
		boerin.click(function () {
			$('#splash a').click();
		});
		
		$('#splash').fadeIn('slow');
	}
	
	function createContent() {
		var boerin = $('#boerin');
		var container = $('#background');
		container.height($(window).height());
		
		var overflow = 160;
		if (boerin.height() > $(window).height()+overflow) {
			boerin.width(boerin.width()*($(window).height()+overflow)/boerin.height());
			boerin.height($(window).height()+overflow);
			boerin.css('top', $(window).height()+overflow-boerin.height());
		}
	}

	function showMap () {
		var latlng = new google.maps.LatLng(51.056468, 4.670189);
		var myOptions = {
			zoom: 15,
			center: latlng,
			mapTypeId: google.maps.MapTypeId.ROADMAP
		};
		var map = new google.maps.Map(document.getElementById("googleMap"), myOptions);
		var marker = new google.maps.Marker({
			icon: 'img/marker.png',
			position: latlng,
			map: map,
			title: 'Boerinnekesfuif'
		});
	};
}) (jQuery)
