//Ⱥ¼
var Group = new Class({

    //캯
    initialize: function(){
        //ʹArray.flattenά
        this.instances = Array.flatten(arguments);
        //¼
        this.events = {};
        //¼
        this.checker = {};
    },

    //ΪȺĳ¼
    addEvent: function(type, fn){
        //ʹ||Ĭֵ
        this.checker[type] = this.checker[type] || {};
        //ʹ||Ĭֵ
        this.events[type] = this.events[type] || [];
        //¼,false
        if (this.events[type].contains(fn)) return false;
        //ӵ
        else this.events[type].push(fn);
        //ΪȺеÿһӸ¼,ָthis.check
        this.instances.each(function(instance, i){
            //ҪȺе֧addEvent
            instance.addEvent(type, this.check.bind(this, [type, instance, i]));
        }, this);
        return this;
    },

    //Լ
    check: function(type, instance, i){
        //ʶ,ȷȺеÿ˸¼ļ
        this.checker[type][i] = true;
        //ʶһ
        var every = this.instances.every(function(current, j){
            return this.checker[type][j] || false;
        }, this);
        //ȫδʶΪtrue,˳
        if (!every) return;
        //
        this.checker[type] = {};
        //¼
        this.events[type].each(function(event){
            event.call(this, this.instances, instance);
        }, this);
    }

}); 

