/**
 * @author nick (tweaked by nico)
 */
 var Search = Class.create(DropDown, {
	oaction			:'',
	start_value		:'',
	initialize:function(form,trigger,container,container_class,query)
	{
		this.form			 = $(form);
		this.oaction		 = this.form.action;
		this.query_field	 = $(query);
		this.start_value	 = this.query_field.value;
		this.trigger	 	 = $(trigger);
		this.sub_container	 = container;
		this.container_class = container_class;
		this.left 			 = 0;
		this.top 			 = -2;
		this.top_anchor		 = false;
		
		// event handling
		Event.observe(this.form,"submit",this.submit.bind(this)); 
		this.bfx = this.check_state.bindAsEventListener(this);
		// when focusing/defocusing the form input
		Event.observe(this.query_field,"focus",this.focus.bind(this));
		// blurring the search input
		Event.observe(this.query_field,"blur",this.blur.bind(this));
	},
	add_items:function($super, orray)
	{
		$super(orray);	//override base class
		this.sub_selected = $(this.sub_items[0]);		//select first item
		var s_opt = this.sub_selected.innerHTML;
		this.form.action = this.sub_selected.readAttribute('dropvalue');
		for(var i=0; i<this.sub_items.length; i++) {
			$(this.sub_items[i]).removeClassName(this.on_class);
		}
		this.sub_selected.addClassName(this.on_class);
	},
	focus:function()
	{
		if($(this.query_field).value==this.start_value){
			$(this.query_field).value="";
			this.showDrop();
		}
	},
	blur:function()
	{
		if($(this.query_field).value==""){$(this.query_field).value=this.start_value;}
	},
	subitem_select:function()	//overwrites base class
	{
		this.form.action = this.sub_selected.readAttribute('dropvalue');
		for(var i=0; i<this.sub_items.length; i++) {
			$(this.sub_items[i]).removeClassName(this.on_class);
		}
		this.sub_selected.addClassName(this.on_class);
		this.query_field.focus();
	},
	submit:function()
	{
		if($(this.query_field).value==this.start_value)
		{
			$(this.query_field).focus();
			return false;
		}
		this.form.submit();
	}
});