var JUHPSwaptext = Class.create();
JUHPSwaptext.prototype = {
	initialize : function(element, options) {
		this.id = element.identify();
		this.element = $(element);

		this.element.descendants().each(function(e) {
			if (e.title) {
				e.store('first', e.innerHTML);
				e.store('second', e.title);
			}
		}.bind(this));
		this.element.on('click', 'a.juhp-swapper', this.swap.bind(this), false);
		this.element.store('status', true);
	},
	swap : function(event) {
		var status = this.element.retrieve('status');
		this.element.descendants().each(function(e) {
			if (e.title) {
				e.fade({
					duration: .1,
					fps: 60,
					after: function() {
						if (status == true)
							e.update(e.retrieve('second'));
						else
							e.update(e.retrieve('first'));
						e.appear({
							duration: .1,
							fps: 60
						});
					}
				});
			}
		});
		this.element.store('status', !status);
		Event.stop(event);
		return false;
	}
}
Element.addMethods({ swapText : function(e) { return new JUHPSwaptext(e); } });
Event.observe(window, 'load', function() { $$('.juhp-swaptext').invoke('swapText'); });
