/*
*	Dependencies:
*		MooTools 1.2.1
*/

var CustomDropDown = new Class({
	Implements: Options,
	options: {
	},
	initialize: function(element, options){
		this.setOptions(options);
		this.element = $(element) || false;
		this.setup();
	},
	setup: function(){
		this.element.addEvent('click', this.toggle.bindWithEvent(this));
		this.element.addEvent('mouseleave', this.hide.bindWithEvent(this));
	},
	toggle: function(e){
		if($(e.target).hasClass('toggler')) e.stop();
		this.element.toggleClass('active');
	},
	hide: function(e, i){
		this.element.removeClass('active');
	}
});

/* ------------------------------------------------- */

var Prompt = new Class({
	initialize: function(field) {
		this.field = $(field);
		this.setup();
	},
	setup: function() {
		this.field.addEvent('focus', this.focus.bind(this));
		this.field.addEvent('blur', this.blur.bind(this));
	},
	focus: function() {
		if (this.field.value == this.field.defaultValue) {
			this.field.value = '';
		}
	},
	blur: function() {
		if (this.field.value == '') {
			this.field.value = this.field.defaultValue;
		}
	}
});

/* ------------------------------------------------- */

window.addEvent('domready', function(){
	if($('flashMessage')){
		$('flashMessage').addEvent('click', function(e){
			e.stop();
			this.fade('out').setStyle('display', 'none');
		});
	}

	if($$('div.select-box').length > 0){
		$$('div.select-box').each(function(el, i){
			new CustomDropDown(el);
		});
	}

	if($$('input.prompt').length > 0){
		$$('input.prompt').each(function(el){
			new Prompt(el);
		});
	}
});