window.onload = function () {myCbir = new Cbir('images/other/check_on.gif', 'images/other/check_off.gif',  'check_dis.gif'); initScrollLayer();}
function Cbir(img_checked_src, img_unchecked_src, img_disabled_src) {
	this.img_on = new Image();
	this.img_off = new Image();
	this.img_on.src = img_checked_src;
	this.img_off.src = img_unchecked_src;
	if (img_disabled_src) {    
		this.img_dis = new Image();
		this.img_dis.src = img_disabled_src;
	} 
	              
	this.labels = document.getElementsByTagName('label');
  this.inputs = document.getElementsByTagName('input');
  for (var i=0; i<this.inputs.length; i++) {
		input = this.inputs[i];
    if (input.getAttribute('type') == 'checkbox') {
      if (!input.getAttribute('id')) {
        input.setAttribute('id', 'checkbox_' + input.getAttribute('name') + '_' + i);
      }                
			img	= document.createElement("img");
			img.src = this.img_dis && input.disabled ? this.img_dis.src : input.checked ? this.img_on.src : this.img_off.src;
			img.setAttribute('id', 'img_' + input.getAttribute('id')); 
			img.className = 'checkbox_img';
			if (!input.disabled) {
				if (!this.checkLabels(input)) {
				  img.onclick = function() { myCbir.toggle (this); }
				}                  
			}             
			
			input.parentNode.insertBefore(img, input.nextSibling);
			//input.style.display = 'none';  /* this method doesn't work in safari */
			input.style.visibility = 'hidden';
			input.style.position = 'absolute';
			
    }
  }
}       

Cbir.prototype.checkLabels = function(inp) {
  this.inp_id = inp.getAttribute('id');
	                    
  this.inp_parent = inp.parentNode;
  if (this.inp_parent.tagName.toLowerCase() == 'label') {
    this.inp_parent.setAttribute('id', 'label_' + this.inp_id);    
    this.inp_parent.onclick = function() { myCbir.toggle (this);}
		return true;      
  }
  for (var i=0; i<this.labels.length; i++) {
    lbl = this.labels[i];
    if (lbl.htmlFor == this.inp_id) {
      lbl.setAttribute('id', 'label_' + this.inp_id);     
    	lbl.onclick = function() { myCbir.toggle (this); return false; }
    }
  }
  return false;
}     

Cbir.prototype.toggle = function(el) {
  if (!el) return false;  
                
	id = el.tagName.toLowerCase() == 'img' ? el.getAttribute('id').replace('img_', '') : el.getAttribute('id').replace('label_', '');
  checkbox = document.getElementById(id);    
  img = document.getElementById('img_' + id);
  
  checkbox.click();   
  img.src = checkbox.checked ? this.img_on.src : this.img_off.src;           
}   