// Image Checkbox (Связывает картинку и checkbox)
var Gi_IBox = new Class({
  checkbox: null, // Element
  imagebox: null, // Element
  //checked: null,

  initialize: function(c,i) {
    this.checkbox = $(c);
    this.imagebox = $(i);
    this.imagebox.addEvent('click',(function(){
      this.checkbox.checked = !this.checkbox.checked;
      this.checkbox.fireEvent('click');
    }).bind(this));
    this.checkbox.addEvent('click',(function(){ this.setActive(); }).bind(this));
    this.checkbox.addEvent('change',(function(){ this.setActive(); }).bind(this));
    this.checkbox.fireEvent('click');
  },

  setActive: function() {
    if (this.checkbox.checked) this.imagebox.addClass('ibox_active');
    else this.imagebox.removeClass('ibox_active');
  }
});

// Radio Checkboxes (Делает элементы-флажки(checkbox) взаимно связанными, как и радио-флажки)
var Gi_RBoxes = new Class({
  boxes: null, // Elements
  active: null, // Checked element

  initialize: function(e) {
    this.boxes = e;
    var box0 = null;
    this.boxes.each((function(box){
      if (!box0) box0 = box;
      if (box.checked && !this.active) this.setActive(box);

      box.addEvent('click',(function(){ this.setActive(box); }).bind(this));
    }).bind(this));

    if (!this.active) this.setActive(box0);
  },

  setActive: function(box) {
    box.checked = true;
    box.fireEvent('change');
    this.active = box;
    this.clear();
  },

  clear: function() {
    this.boxes.each((function(box){
      if (this.active != box) {
        box.checked = false;
        box.fireEvent('change');
      }
    }).bind(this));
  }
});
