/*
 * Note:
 *
 * Elements requiring dynamic sizing should NEVER be set to display: none
 * and offHide should always be set to false to prevent funkthis from setting
 * the above style automatically.
 */
 
function funkthis(elementId, options, offHide, duration, initStatus, oneWay, func_on, func_off) {
	if(duration == null) {
		duration = 500;
	}
	
	if(initStatus == null) {
		initStatus = 'off';
	}
	
	el = $(elementId);
	
	if(!el) {
		/*
		 * Someone was sloppy.
		 */
		 
		return;
	}
	
	if(!el.retrieve('onoff_status')) {
		el.store('onoff_status', initStatus);
	} else {
		/*
		 * if onoff_status is set, we've funked the element before, so we're going to
		 * ignore it this time.
		 */
	
		if(oneWay == true) {
			return;
		}
	}
	
	if(options.height) {
		if(options.height[0] == "dynamic") { 
			options.height[0] = document.getElementById(elementId).scrollHeight;
		}
	
		if(options.height[1] == "dynamic") { 
			options.height[1] = document.getElementById(elementId).scrollHeight;
		}
		
		if(options.height[0] == options.height[1]) {
			return false;
		}
	}
	
	if(options.width) {
		if(options.width[0] == 'dynamic') {
			options.width[0] = el.scrollWidth;
		}
		
		if(options.width[1] == 'dynamic') {
			options.width[1] = el.scrollWidth;
		}
	}
	
	optHash = new Hash(options);
	
	var eff = new Fx.Morph(elementId, {duration: duration, link: 'chain', transition: Fx.Transitions.Sine.easeInOut});
	
	if(el.retrieve('onoff_status') == 'on') {
		options_off = new Hash({});
		
		optHash.each(function(optVal, optKey) {
			options_off.set(optKey, [optVal[1], optVal[0]]);
		});
		
		el.setStyle('overflow', 'hidden');
	
		eff.start(options_off.getClean()).chain(function() {
			if(offHide) {
				el.setStyle('display', 'none');
			}
			
			el.store('onoff_status', 'off');
		
			if(typeof func_off != 'undefined') {
				func_off();
			}
		});
	} else {
		if(offHide) {
			if(optHash.has('opacity')) {
				el.setStyle('opacity', optHash.opacity[0]);
			}
			
			el.setStyle('display', 'block');
		}
		
		el.setStyle('overflow', 'hidden');
		
		eff.start(options).chain(function() {
			el.setStyle('overflow', 'visible');	
			
			el.store('onoff_status', 'on');
		
			if(typeof func_on != 'undefined') {
				func_on();
			}
		});
	} 
}