$(function () {
        var
                name=null,
                value=null,
                current=null,
                orig=null;
        $('input[type="checkbox"], input[type="radio"]')
                .mousedown(function () {
                        if (!this.hasAttribute('name')) return;
                        orig = this;
                        name = this.getAttribute('name');
                        var radio = this.getAttribute('type').toLowerCase() == 'radio';  
                        if (radio)
                                value = true;
                        else           
                                value = !this.checked;
                        this.checked = value;
                })
                .hover(function () {
                        if (name===null) return;
                        if (this.getAttribute('name')!==name) return;
                        if (current!==this) {      
                                current = this;
                                this.checked = value;
                                $(this).change();
                                this.focus();
                        }
                }, function () {
                        if (name===null) return;                       
                        current = null;
                }).change(console.log);
        $().mouseup(function (e) {
                if (name===null) return;               
                name = null;

                if (e.originalTarget===orig) {
                        var radio = orig.getAttribute('type').toLowerCase() == 'radio';
                        if (radio)
                                orig.checked = true;
                        else
                                orig.checked = !value;
                }
        });
});