// Note, any changes made to this will need to be modified at the end of ../../comb.js

var placeholder = new Class({
	
	Implements: [Options],
	
	options: {
		'color':'#ccc',
		'backgroundColor':false,
		'placeholder':false,
		'removeTitle':true,
		'addclass':false
	},
	
	initialize: function(element,options){
		
		if(element.get('title')){
			this.holding = false;
			
			this.element = element;
			this.setOptions(options);
			
			if(this.options.color){
				this.initColor = this.element.getStyle('color');
			}
			
			if(this.options.backgroundColor){
				this.initBackgroundColor = this.element.getStyle('background-color');
			}
			
			if(!this.options.placeholder){
			
				title = this.element.get('title');
				
				if($defined(title) && title.clean() != ""){
					
					this.options.placeholder = title;
					
				}
			
			}
			
			if(this.options.removeTitle){
				this.element.set('title','');
			}
			
			this.showPlaceholder();
			
			this.element.addEvent('focus',this.hidePlaceholder.bindWithEvent(this));
			this.element.addEvent('blur',this.showPlaceholder.bindWithEvent(this));
		}
		
	},
	
	showPlaceholder: function(){
		if(this.element.get('value').clean() == ""){
			this.element.set('value',this.options.placeholder);
			if(this.options.addclass)this.element.addClass(this.options.addclass);
			if(this.options.color)this.element.setStyle('color',this.options.color);
			if(this.options.backgroundColor)this.element.setStyle('background-color',this.options.backgroundColor);
			this.holding = true;
		}
		
	},
	
	hidePlaceholder: function(){
		if(this.holding){
			this.element.set('value','');
			if(this.options.addclass)this.element.removeClass(this.options.addclass);
			if(this.options.color)this.element.setStyle('color',this.initColor);
			if(this.options.backgroundColor)this.element.setStyle('background-color',this.initBackgroundColor);
			this.holding = false;
		}
		
	}
	
});
