$(function() {

$('.has_focus').focus();

var nav = {
	hide_timeout: null,

	start_hiding: function() {
		nav.hide_timeout = window.setTimeout(nav.hide, 1000);
	},
	
	stop_hiding: function() {
		window.clearTimeout(nav.hide_timeout);
	},
	
	hide: function() {
		$('#nav div.submenu:visible').fadeOut('fast');
	},
	
	hide_fast: function() {
		nav.stop_hiding();
		$('#nav div.submenu').hide();
	}
};

/**
 * Shows and hides the submenus of the navigation.
 */
$('#nav > ul > li > a').hover(function() {
	nav.stop_hiding();

	var submenu = $(this).parent().find('div.submenu');
	var hidden_submenu = $(this).parent().find('div.submenu:hidden');

	if (submenu.length == 0 || hidden_submenu.length == 1) {
		nav.hide_fast();
	}

	hidden_submenu.fadeIn();
	
	return false;
}, function() {
	nav.start_hiding();
});

$('#nav div.submenu').hover(function() {
	nav.stop_hiding();
}, function() {
	nav.start_hiding();
});

// Show the picture of the first floor.
$('#vloer').attr('src', $('#vloeren a:first').attr('href'));
$('#vloeren a').click(function() {
	$('#vloer').attr('src', $(this).attr('href'));
	return false;
});

});

