
(function () {
    
    var W = Allthat.namespace('Allthat.Widget');
    
    W.Checkgroup = new Class({
        Implements : [Events, Options],
        options : {},
        
        initialize : function (options) {
            if (arguments[1]) { // user prefer to pass in two arguments instead of object
                options = {
                    masterSelector : arguments[0],
                    childSelector : arguments[1]
                }
            }
            
            this.master = $$(options.masterSelector);
            this.master.set('checked', false);
            
            this.children = $$(options.childSelector);
            
            
            // bind scope of the this.toggle method to this
            this.boundedToggle = this.toggle.bind(this);
            
            this.master.addEvent('click', this.boundedToggle);
            
            this.fireEvent('initialize');
        },
        
        toggle : function () {
            var checked = !!this.master.checked;
            this.children.each(function (child) {
                child.set('checked', checked);
            }, this);
        }
    });
    
})();