var SearchForm = new Class({
	Implements: [Options],
	options: {
		value: 'Search',
		container: 'top',
		action: 'http://gpwmedia.pl/tags/',
		name: 'tags',
		maxlength:'50',
		method:'post',
		labelColor: '#fff',
		textColor: '#fff'
	},
	initialize: function(options) {
		this.setOptions(options);
		this.createForm();
		this.switchInput('b');
	},
	createForm: function(){
		if(this.options.container){
			this.SF = new Element('div',{'id':'SearchForm','styles':{'opacity':0}});
			this.SB = new Element('button',{'type':'submit',events:{
					mouseenter: function(e){this.SB.fade(1);}.bindWithEvent(this),
					mouseleave: function(e){this.SB.fade(0.5);}.bindWithEvent(this)
				}
			});				
			this.SI = new Element('input',{
				'type':'text',
				'name':this.options.name,
				'maxlength':this.options.maxlength,
				events:{
					focus: function(e) {new Event(e).stop();this.switchInput('f');}.bindWithEvent(this),
					blur:function(e){new Event(e).stop();this.switchInput('b');}.bindWithEvent(this)
				}
			});
			
			this.SS = new Element('form',{
				'action':this.options.action,
				'method':this.options.method,
				'enctype':'multipart/form-data',
				events:{
					submit:function(e){if(this.SI.value==this.options.value) e.stop();}.bindWithEvent(this)
				}
			});
			
			this.SS.grab(this.SI, 'bottom');
			this.SS.grab(this.SB, 'bottom');
			this.SF.grab(this.SS, 'bottom');
			
			if(typeof(this.options.container)=='string') $(this.options.container).grab(this.SF, 'bottom');
			else this.options.container.grab(this.SF, 'bottom');
			
			this.SF.fade(1);
		}
	},
	switchInput: function(which){
		text = this.options.value;
		if(which=='f'){
			if(this.SI.value==text) this.SI.value='';
			this.SI.setStyle('color',this.options.textColor);
		}
		if(which=='b'){
			if(this.SI.value=='') this.SI.value=text;
			if(this.SI.value==text) this.SI.setStyle('color',this.options.labelColor);
		}
        }

});
