$(function() {
	// We will automatically hide the label when clicking on them (they are covering the inputs)
	$('#header label').each(function() {
		// What input does they refer to
		var input = $('#' + $(this).attr('htmlFor'));
		// If it does not belong to a input/text, we stop
		if (!input.is(':text,:password')) return $(this);

		// We store the default value and corresponding label
		input.data('defaultValue', $(this).html()).data('linkedLabel', $(this));
		// We store the corresponding field in the label
		$(this).data('linkedField', input);

		// When clicking on the label, we hide it and give focus to the corresponding input
		$(this).click(function() {
			// We set focus to the input
			$(this).data('linkedField').focus();
		});

		 // When focusing an input
		input.focus(function() {
			// We hide the linked label
			$(this).data('linkedLabel').hide();
			return true;
		});

		// When losing focus on a field
		input.blur(function() {
			// If the field is empty, we re-show the label
			if ($(this).val()=="") {
				$(this).data('linkedLabel').show();
			}
		});

		// If there allready is a value, we hide the label
		if (input.val()!="") {
			$(this).hide();
		}

		return $(this);
	});

	// We show the submenu when hovering the menu
	$('#menu > li > a').hoverIntent(function() {
		var currentSubmenu = $(this).closest('#menu').find('li ul.current');
		var newSubmenu = $(this).next('ul');
		// If no next submenu or no actual submenu, we won't do anything
		if (!currentSubmenu || !newSubmenu) return false;

		// We hide the current submenu
		currentSubmenu.removeClass('current');
		// Showing the selected one
		newSubmenu.addClass('current');
		return true;
	}, function() {});


    $.ajaxSetup({ cache: false });
});