(function($) {
	$(document).ready(function(){

		var hasStyleSheet = true;
		//	create div and check for style
		$('<div></div>').attr('id', 'checkForCSS').appendTo('body');
		//	default value for a renderered div is: display: block
		if	($('#checkForCSS').css('display') != 'none')
		{
			hasStyleSheet = false;
		}
		//	and remove div
		$('#checkForCSS').remove();
		//	end modifications for 'drempelsweg'
		
		// Remove default value onClick, and reset it onBlur
		$('.tx-tferathenau-search-controller div.filter-form .query-field input').each(function(){
			if($(this).prev('label').attr('title') != undefined) {
				$(this).click(function() {
					if($(this).val() == $(this).prev('label').attr('title')) {
						$(this).val('');
					}
				});
	
				$(this).blur(function() {
					if($(this).val() == '') {
						$(this).val($(this).prev('label').attr('title'));
					}
				});
			}
		});
		
		// On submit handler, empty default values
		$('.tx-tferathenau-search-controller .filter-form form').bind('submit', function(evt) {
			if ($('.query-field input', $(this)).val() == $('.query-field label', $(this)).attr('title')) {
				$('.query-field input').val('');
			}
			if ($('.start-field input', $(this)).val() == $('.start-field label', $(this)).attr('title')) {
				$('.start-field input').val('');
			}
			if ($('.end-field input', $(this)).val() == $('.end-field label', $(this)).attr('title')) {
				$('.end-field input').val('');
			}
		});
	
		//	show only if visitor has stylesheets enabled
		if	(hasStyleSheet)
		{
			// datepicker img is not shown (search.css) -> show it now
			$('img.datepicker').show();

			// Add datepickers
			$('div.tx-tferathenau-search-controller div.filter-form fieldset.time-span .field').each(function(){
				$(this).find('img.datepicker').click(function(){
					$(this).parent().find('input').datepicker('show');
				});
		
				$(this).find('input').datepicker({
					dateFormat: "dd-mm-yy",
					altFormat: "@",
					dayNamesMin: ['Ma', 'Di', 'Wo', 'Do', 'Vr', 'Za', 'Zo'],
					monthNames: ['Januari','Februari','Maart','April','Mei','Juni','Juli','Augustus','September','Oktober','November','December']
				});
			});
		}
		else
		{ 
			$('img.datepicker').remove();
		}
		
		// Post filter form on department change
		$('.filter-form-publication #tx_tferathenau_search_controller_filter_department').bind('change', function() {
			$('.tx-tferathenau-search-controller .filter-form form').trigger('submit');
			//$(this).attr('form').submit();
		});
	});
})(jQuery);
