$(document).ready(function() {
	// Ajax form submission
	var $ajaxForm =  $('form.validate');
	var submitOptions = {
	  clearForm: true,
	  beforeSubmit: function() {
	    $('<div class="loading">Processing<img src="/assets/styles/images/ajax-loader.gif" alt="" /></div>').appendTo('div.actions');
	    $('<div class="overlay"></div>').css({opacity: '.4'}).appendTo($ajaxForm);
	  },
	  success: function(responseText) {
	    $ajaxForm.slideUp(200, function() {
	      var response = $('<div>' + responseText + '</div>').find('div.thankyou:first').html();
	      $('.loading').insertAfter(this).addClass('box success single-line').html(response).removeClass('loading');
	    });
	    $('div.overlay').fadeOut(100, function() {
	      $(this).remove();
	    });
	  }
	};
	$ajaxForm.tinyvalidate({
	  // submitOverride: function() {
	  //   $ajaxForm.ajaxSubmit(submitOptions);
	  // },
	  summary: {
	    wrapper: '<div class="error-summary error box"></div>',
	    preMessage: '<p>There was a problem processing your request. <br>Please correct the {num} highlighted {field|fields} and try again.</p><ul>',
	    postMessage: '</ul>'
	  }
	});

	// Autogrowing textareas
	  $('textarea').expandable({
	    init: true,
	    duration: 100,
	    interval: 400,
	    by: 1
	  });
	
	// datepicker
	if (typeof $.fn.datepicker !== 'undefined'){
		$('#visit_form #date').datepicker({
				showOn: "button",
		    buttonImage: '/assets/styles/images/icons/datepicker.png',
		    buttonImageOnly: true
				}
			);
		
	};
});