var MySearch = {

	initialize: function() {
		this.sBar = $('ajaxsearch_result');
		this.indicator = $('ajaxindicator');
		if (!this.sBar) return;
		searchComplete = '0';
		this.sFX = new Fx.Style(this.sBar, 'height', {duration:600}).set(0);
		this.sFX3 = new Fx.Style(this.sBar, 'height', {duration:600}).set(0);
		this.sFX4 = new Fx.Style(this.sBar, 'opacity', {duration:600}).set(1);
		this.iFX = new Fx.Style(this.indicator, 'opacity', {duration:500}).set(0);
		$('ajaxsearch_input').addEvent('keydown',function(event) {
			if (event.key == 'enter') {
			this.indicator.setStyle('display','inline');
			this.iFX.start(0,1);
			if ($('ajaxsearch_input').value.replace(/^\s*|\s*$/g,"")=="") {
				this.sFX.start(0);
				return;
			}
			$clear(this.sTimeout);
			this.sTimeout = this.process.delay(500, MySearch);
		}
		}.bindWithEvent(this) );
	},
	
	process: function() {
		this.sFX.start(0); /* reset the output zone */

                                if ( searchComplete == '1' ) {
                                        this.sFX4.start(1,0);
                                        this.sFX3.start(this.sBar.scrollHeight);
                                }


		var wowJAX = new Ajax('modules/mod_vm_livesearch/livesearch.php', {
			postBody: $('ajaxsearch'),
			update: this.sBar,
			/* when done, open up the output */
			onComplete: function(){
				this.sBar.setStyle('opacity','1');
				this.sBar.setStyle('padding-top', '5px');
		                this.sBar.setStyle('height', 'auto');
				this.sFX.start(this.sBar.scrollHeight);
				this.iFX.start(1,0);
				//searchComplete = '1';
			}.bind(this)
		}).request();
	}

};
window.onDomReady(MySearch.initialize.bind(MySearch));