;(function ($) {

	// Document search placeholder.

	$('#level1menu #Form_DocumentSearchForm_DocumentSearch').focus(function() {
		if($(this).val() === 'Document Search') {
			$(this).val('');
			$(this).css('color', '#6A6A6B');
		}
	});
	$('#level1menu #Form_DocumentSearchForm_DocumentSearch').focusout(function() {
		if($(this).val() === '') {
			$(this).val('Document Search');
			$(this).css('color', '#DEDEDE');
		}
	});

	// Generate the autocomplete document search values.

	$(window).load(function() {

		// Determine the absolute URL path of the current page.

		var base = $('base').attr('href');

		var URL = window.location;
		var path = URL.pathname.substring(0, URL.pathname.lastIndexOf('/') + 1);
		var page = URL.href.substring(0, URL.href.length - ((URL.pathname + URL.search + URL.hash).length - path.length));
		if (page.length < base.length) {
			page = base;
		}
		if(page === base) {
			page = page + 'home/';
		}

		// Using the documents retrieved, generate the autocomplete field.

		$('#level1menu #Form_DocumentSearchForm_DocumentSearch').autocomplete({
			source: page + 'RetrieveDocumentJSON',
			minLength: 2
		});
	});
})(jQuery);
