/**
* Checkbox Show Hide
* @requires:
* 	prototype.js
* 	prototype_ss.js
* 	behaviour.js
* 	behavious_extensions.js
* 	scriptaculous/scriptaculous.js
* @example:
* 	<span class="question">(<a href="javascript:void('some_id')">?</a>)</span>
* 	<div id="some_id" style="display:none">hidden content</div>
**/

var CheckboxShowHideClass = Class.create();
CheckboxShowHideClass.prototype = {
	//Properties
	el: null,
	bool: null,
	hiddenID: null,
	hiddenEl: null,
	
	//Constructor
	initialize: function(el, bool) {
		this.el = el;
		this.bool = bool;
		this.hiddenID = this.el.value;
		this.hiddenEl = $(this.hiddenID);
		if (this.hiddenEl != null) {
			Event.observe(this.el, 'click', this.clickCheckbox.bind(this));
			this.clickCheckbox();
		}
	},
	
	//Methods
	clickCheckbox: function (e) {
		//fork for bool
		if ((this.bool && !this.el.checked && this.hiddenEl) || (!this.bool && this.el.checked && this.hiddenEl))
			var show = false;
		else if ((!this.bool && !this.el.checked && this.hiddenEl) || (this.bool && this.el.checked && this.hiddenEl))
			var show = true;
			
		//show hide the extra info
		if (show && Element.visible(this.hiddenEl))
			new Effect.BlindUp(this.hiddenEl);
		else if (!show && !Element.visible(this.hiddenEl))
			new Effect.BlindDown(this.hiddenEl);
	}
};
EventSelectors.register({
	// When Checked, show hidden content
	'input.checkboxShowHide' : function(el){
		new CheckboxShowHideClass(el, false);
	},

	// When UnChecked, show hidden content
	'input.checkboxHideShow' : function(el){
		new CheckboxShowHideClass(el, true);
	}
});