/* 
Generic Toggling class.  Pass it an object with the ID's for the trigger and the target. Requires MooTools

Example: 
var toggle = new Toggle( {trigger: "target"} );
*/

var Toggle = function(obj) {
		for (var x in obj) {
			this.trigger = $(x);
			this.target = $(obj[x]);
		}
		
		this.toggle = function(event) {
			if (this.trigger.checked === true) {
				this.show();
			} else {
				this.hide();
			}
		}
		
		this.show = function() {
			var height = this.target.getSize().size.y;
			this.fx.start({
					'height': [height,this.targetSize.size.y],
					'opacity': [0, 1]
					});
		}
		
		this.hide = function() {
			var height = this.target.getSize().size.y;
			this.fx.start({
					'height': [height,0],
					'opacity': [1, 0]
					});
		}

		
		if (this.trigger && this.target) {
			this.fx = new Fx.Styles(this.target, {duration:300, transition: Fx.Transitions.linear});
			this.targetSize =  this.target.getSize();
		
			if (this.trigger.checked === false) {
				this.target.setStyles({
								overflow: 'hidden',
								height:'0'
								});
			}
		
			this.trigger.onclick = this.toggle.bindAsEventListener(this);
			return this;
		}			
}
	


