var michaelborg = {};
michaelborg.main_menu = function() {
	var immediatelyNavTo = null;
	var links = $('a');
	var firstClick = true;
	var notAtMainMenu = false;
	function resizeWindow(){
		if(firstClick)
			$('.block').each(function(){
				$(this).attr('orig_bot', 
					$(document).height() - 
					$(this).offset()['top'] - 
					$(this).height());
				$(this).attr('orig_left', $(this).offset().left)
				});
	}
	function scrollWindow(){
		if(notAtMainMenu) {
			console.log("Woot...");
			$('.block').css('bottom', '0');
		}
	}
	$(window).bind("resize", resizeWindow);
	$(window).bind("scroll", scrollWindow);
	resizeWindow();
	function loadURL(url){
		window.location.href = url;
	};
	function transitionEffect(gotClicked, myURL){
		$('#content').height(0);
		$('#content').show();
		$('#content').animate({'height': $(window).height() -
				gotClicked.height()}, {
			duration: 1000,
			easing: "easeOutBounce",
			complete: function(){ loadURL(myURL); }
			});
		if(firstClick) $('h1.welcome').fadeOut();
		if(!gotClicked.is('.overlap'))
			$('.block.overlap').animate({
				left: gotClicked.attr('orig_left')});
		$('.block').css('position', 'absolute');
		$('.block').animate({'bottom': '0'}, {
			duration: 1000,
			easing: "easeOutBounce"
			});
		$('.only.block').fadeOut();
		$(gotClicked).fadeOut();
			
	};
	$(window).scroll(function(){
		if(notAtMainMenu)
			$('.block').animate({'bottom': '-100'}, {
				duration: 1000,
				easing: "easeOutBounce"
				});
		});
	$('a').each(function(){
		$(this).attr('old_href', $(this).attr('href')); });
	$('a').attr('href', '#');
	$('a').click(function(){
		notAtMainMenu = true;
		$('#content').fadeOut();
		$('.block').fadeIn();
		$('.block').each(function(){
			if(!firstClick)
				$(this).animate({
					'bottom': $(this).attr('orig_bot'),
					'left': $(this).attr('orig_left')},
					100);
			else
				$(this).css({
					'bottom': $(this).attr('orig_bot'),
					'left': $(this).attr('orig_left')});
			});

		var pBlock = $(this).parent('.block');
		var target = $(this).attr('old_href');
		/*$('#content').load(target, function(){transitionEffect(pBlock);});*/
		transitionEffect(pBlock, target);
		});
};

