$(document).ready(function(){
    $('input[type=checkbox]').each(function(){
        $(this).hide();
        $(this).after($('<a href="" class="checkbox' + (($(this).is(':checked')) ? ' checked' : '') + '"></a>').click(function (){
            box = $(this).prev();
            if (box.attr('name') == 'book_service_both'){
                if (box.is(':checked')){
                    toggleCheckbox(box, $(this), false);
                }
                else {
                    service = $('input[name=book_service_service]');
                    toggleCheckbox(service, service.next(), false);
                    mot = $('input[name=book_service_mot]');
                    toggleCheckbox(mot, mot.next(), false);
                    toggleCheckbox(box, $(this));
                }
            }
            else {
                both = $('input[name=book_service_both]');
                toggleCheckbox(both, both.next(), false);
                toggleCheckbox(box, $(this));
            }
            return false;
        }));
    })
})

function toggleCheckbox(box, link_box, checked){
    if (checked == null){
        checked = (!$(box).is(':checked'));
    }
    if (checked){
        $(box).prop('checked', true);
        if (!$(link_box).hasClass('checked')){
            $(link_box).addClass('checked');
        }
    }
    else {
        $(box).prop('checked', false);
        $(link_box).removeClass('checked');
    }
}

(function($) {
  jQuery.fn.backgroundPosition = function() {
    var p = $(this).css('background-position');
    if(typeof(p) === 'undefined') return $(this).css('background-position-x') + ' ' + $(this).css('background-position-y');
    else return p;
  };
})(jQuery);
