var ShuffledText = Class.create({
	initialize:function(option){
		this.element = $(option.element);
		this.trigger = option.trigger;
		this.target  = $(option.target);
		
		this.element.observe(this.trigger,this.action.bind(this));
	},
	action : function(){
		this.target.value=$A(this.target.value.split(/\s/)).map(function(elem){
			var array = elem.split('');
			var first = array.shift();
			var last  = array.pop();
			return [first,
				array.sortBy(Math.random),last].flatten().join('')
		}).join(' ');
	}
});
document.observe("dom:loaded",function(){
	new ShuffledText({
		trigger  : "click",
		element : "button",
		target  : "shuffled"
	});
});