/**
 * @author Peter Swan
 */
var DefaultMessage = Class.create({
	initialize: function(elm){
		this.elm = $(elm);
		if( !this.elm || (this.elm.tagName != 'INPUT' && this.elm.tagName != 'TEXTAREA')){
			throw 'Element must be an input or textarea!';
		}
		this.options = Object.extend({
			default_value: this.getValue() || 'Click to Enter'
		}, arguments[1] || {});
		this.elm
		.observe('focus', function(e){
			if( this.getValue() == this.options.default_value){
				this.setValue('');
			}
		}.bindAsEventListener(this))
		.observe('blur', function(e){
			if( this.getValue().replace(/^\s+|\s+$/, '') == ''){
				this.setValue(this.options.default_value);
			}
		}.bindAsEventListener(this));
	},
	setValue: function(value){
		if( this.elm.tagName == 'INPUT'){
			this.elm.value = value;
		}else if(this.elm.tagName == 'TEXTAREA'){
			this.elm.update(value);
		}
	},
	getValue: function(){
		if( this.elm.tagName == 'INPUT'){
			return this.elm.value;
		}else if(this.elm.tagName == 'TEXTAREA'){
			return this.elm.innerHTML;
		}
	}
});

Event.observe(document, 'dom:loaded', function(){
	var login = $('login-form-container');
	if( login ){
		$$('.toggle-login').invoke('observe', 'click', function(e){
			e.stop();
			new Effect.toggle(login, 'blind', {duration: 0.5});
		});
	}
	$$('.default_message').each(function(e){
		new DefaultMessage(e);
	});
});

