 /* 
    #########################################
    Author : JACKSON OATES jackson@zeroninelab.com
    Company : ZERO NINE LAB, LLC - www.zeroninelab.com
    Date: 09/23/08 
    * 
    #########################################

    USED TO REPLACE THE FORM INPUT CHECKBOX WITH A STYLABLE ELEMENT. 
    CHECKBOX VALUE SENT TO HIDDEN INPUT. 
    
    IMPLEMENT:       

	function initiateBox(){
		// WHERE cb1 IS THE ID OF THE CHECKBOX TO BE REPLACED
		var chkbx = new checkboxReplace($('cb1'));
	}
	window.addEvent('domready', initiateBox);
*/

var checkboxReplace = new Class({
		Implements: [Options],
        options:{
            onSelect: $empty,
            defaultText: 'SELECT OPTION!',
            wait: true
        },
        initialize: function(id, options){
			//set//
            this.setOptions(options);
            this.defaultSelection = null;
            this.checkbox = $(id);
            this.value = this.checkbox.value;
            this.getName = id.name;
            this.target = this.checkbox.getParent();

			//create hidden form element with the checkbox's name
			this.hiddenEl = new Element('input', {
				'id':this.checkbox.id,
				'type':'hidden',
				'name':this.getName,
				'value':false
			})
            this.hiddenEl.inject(this.target,'top');
			//create checkbox replacement div
			this.replacementChkBx = new Element('div', {
				//'id':this.checkbox.id,
				'class':'chkBx',
				'name':this.getName
			})
            this.hiddenEl.inject(this.target,'top');
            this.replacementChkBx.inject(this.target,'top');
            
            // now remove original checkbox, we dont need it anymore
            this.checkbox.dispose();
            
            //fire//
            this.onSelect(this.replacementChkBx, this.hiddenEl, this.value);
        },
		onSelect: function(el, target, val){
           /*
            * ELEMENTS
            * el 		==> input checkbox
            * target   	==> checkbox container
            */

			el.addEvent('click', function(){
				el.toggleClass('chkd');
				if (el.hasClass('chkd')) {
					target.value = val;
				}else{
					target.value = false;
				}

			})
		}
});

checkboxReplace.implement(new Events, new Options);