(function($){
	$(function(){

		// Search terms not blank
		$('input.searchsubmit').bind('click', function(){
			if( $.trim($('.s_input', $(this).parent()).val()) == ''){
				if($('input[name="cat"], select[name="cat"]', $(this).parent()).val()) {
					$('.s_input', $(this).parent()).val(' ');
					return true;
				}
				return false;
			}
			else return true;
		});
		
		// Ajax Popup terms
		$('a.popup').click(function(){
			$('#dialogbox').html('<br/><br/><br/><br/><br/><br/><br/><br/>').dialog('open');
			$.get($(this).attr('href'), function(data){
				$('#dialogbox').html(data).dialog('open');
			});
			return false;
		});
		
		// Init dialog box
		$('#dialogbox').dialog({
			bgiframe: true,
			modal: true,
			width:650,
			autoOpen:false,
			position:['center', 50],
			title:false,
			resizable:false,
			draggable:false
		});
		
		// Init date time pickers
		jQuery('input.datepicker').each(function(){
			jQuery(this).datepicker({
				dateFormat: 'dd-mm-yy',
				constrainInput: true,
				minDate: '0',
				maxDate: '+2y',
				gotoCurrent: true,
				hideIfNoPrevNext: true,
				showButtonPanel: true,
				showOtherMonths: true,
				closeText:'Close',
			});
		});
		jQuery('input.timepicker').timepicker();
		
		// Pre select Radio buttons
		$('form.wpcf7-form span.wpcf7-radio').each(function(){
			if(! $(this).find('input[type="radio"]:checked').get(0) ){
				$(this).find('input[type="radio"]').first().attr('checked', true);
			}
		});
		
		// Thema select
		$('select[name="thema-1-rondleiding"]').bind('change', function(){
			if( $(this).val().toLowerCase() == 'de uithof' ){
				$('p.de-uithoth').removeClass('none');
			}else{
				$('p.de-uithoth').addClass('none');
			}
		});
		
		// Contest page add overlay
		if($('.contestpage').get(0)){
			var el = $('.entry-content').children(":first");
			if(el.find('div.gallery').get(0) || el.hasClass('gallery') || el.find('img').get(0) || el.get(0).tagName.toLowerCase() == 'img'){
				$('div.topoverlay').addClass('absolute');
			}
		}
		
	});
})(jQuery);
