var Search = Class.create();
Search.prototype = {
	// ******************************************************************************
	// Constants
	// ******************************************************************************
	Version : '0.2',


	// ******************************************************************************
	// vars
	// ******************************************************************************

	search : {}, // lang element

	searchField : {},
	searchLabel : {},
	
	
	

	//
	//  Initialize the langs
	//
	initialize: function(options) {
		//Object.extend(this.options, options || {});
		
	    this.options = Object.extend({
	    	
		    // selectors
			selectors : {
		    	search : '#search',

				searchField : '#searchField',
				searchLabel : 'label',
				
				dummy : '#dummy'
			},
			classNames : {
//				toggleActive : 'lang_toggle_active',
				
				dummy : '#dummy'
			},

			dummy : '#dummy'
		}, options || {});
		
	
		//document.observe('dom:loaded', this.start.bind(this));
		this.start();

	},


	start : function(){

		this.search = $$(this.options.selectors.search).first();
		if(!this.search) return;
		
		
		this.searchLabel = this.search.select(this.options.selectors.searchLabel).first();
		this.searchField = this.search.select(this.options.selectors.searchField).first();
		
		this.searchLabel.absolutize();
		
		if(this.searchField.value) {
			this.searchLabel.hide();
		}
		
		
		Event.observe(this.searchField, 'focus', this.focusHandler.bind(this), false);
		Event.observe(this.searchField, 'blur', this.blurHandler.bind(this), false);
		
		Event.observe(this.searchField, 'click', this.clickHandler.bind(this), false);


	},
	
	

	focusHandler : function(ev) {
		ev.stop();
		this.searchLabel.hide();

		if(this.searchField.value) {
			//this.searchField.select();
		} else {
		}
	},
	
	blurHandler : function(ev) {
		ev.stop();
		
		if(!this.searchField.value) {
			this.searchLabel.show();
		}
	},
	
	clickHandler : function(ev) {
		ev.stop();

		if(this.searchField.value) {
			this.searchField.select();
		} else {
		}
	}


}


