(function($) {
    $(function() {
        $.datepicker.setDefaults($.datepicker.regional['de']);
        $('.date').datepicker({
            dateFormat: 'dd.mm.yy',
            beforeShow: function(input) {
                var type,
                    otherDate,
                    option,
                    $input = $(input);
                
                type = otherDate = $input.attr('name') == 'start_date' ? 'end_date' : 'start_date';
                otherDate = $('.date[name=' + otherDate + ']').datepicker('getDate');
                
                if(type == 'start_date') {
                    option = 'minDate';
                } else {
                    option = 'maxDate';
                }
                
                $input.datepicker('option', option, otherDate);
            }
        });
        
        
        $('.date-with-handle').datepicker({
            showOn: 'both',
            dateFormat: 'dd.mm.yy',
            buttonImage: 'images/calendar.jpg',
            buttonImageOnly: true,
            buttonText: 'Datum auswählen'
        });
    });
})(jQuery);
