var searchBox = Class.create({
	initialize: function(id, options){
		this.id = id;
		this.options = {
			parent: $$('.header')[0],
			formAction: '/suche/',
			formMethod: 'get',
			queryName: 'tx_indexedsearch[sword]'
		};
		Object.extend(this.options, options);
		
		this.build();
		$(this.id).observe('click', function(evt){
			evt.stop();
			this.open();
		}.bind(this));
	},
	build: function(){
		this.wrap = new Element('div',{'id':'searchBoxWrap'});
		this.form = new Element('form',{'method':this.options.formMethod,'action':this.options.formAction});
		this.input = new Element('input',{'type':'text','name':this.options.queryName});
		this.options.parent.insert(this.wrap.update(this.form.update(this.input)));
		this.wrap.hide();
	},
	open: function(){
		this.wrap.show();
		this.input.focus();
		this.input.observe('keyup',function(){
			if(this.input.value.length && !this.input.hasClassName('go')) {
				this.input.addClassName('go');
				this.input.observe('click', function(evt){
					if((evt.pointerX() - this.input.cumulativeOffset()[0]) > 130) this.form.submit();
				}.bind(this));
			}
		}.bind(this));
	}
	
});