searchCtrlClass = new Class ({
	init: function()	{
		this.fx	= {
			showWaitingScreen: $('advSearchLoading').effect('opacity', {duration: 400, wait: false}).hide(),
			showContentScreen: $('advSearchResults').effect('opacity', {duration: 400, wait: false}).hide()
		}
		
		this.extraFieldsToggle = new Fx.Slide('advSearchExtraFieldsContainer', {duration: 400});
	},
	
	switchScreen: function(waitingOp, contentOp)	{
		this.fx.showContentScreen.start(contentOp);
		this.fx.showWaitingScreen.start(waitingOp);
	},
	
	doSearch: function(searchString)	{
		// if (searchString != '') {
			thLightbox.openLightBox('searchResults', null, label_search_searchfor+' "'+searchString+'" '+label_search_process, false);
			jsonServer.dispatchMethod('hht_search', 'tx_hhtsearch_json::doSearch', {'searchString':searchString,'searchLanguage':searchLanguage}, this.displaySearchResult);
		// } else {$('searchString').focus();}
	},
	
	doAdvancedSearch: function(searchString)	{
		if (searchString != '') {
			$('advSearchLoading').setStyle('display', '');
			this.switchScreen(1.0, 0);
			$('advSearchResults').setStyle('display', 'none');
		
			jsonServer.dispatchMethod('hht_search', 'tx_hhtsearch_json::doAdvancedSearch', {'searchString':searchString,'searchLanguage':searchLanguage}, this.displayAdvSearchResults, this);
		}
	},
	
	displayAdvSearchResults: function(result, pObj)	{
		$('advSearchResults').innerHTML = result;
		$('advSearchResults').setStyle('display', '');
		hhtTeaser.initTabs();
		pObj.switchScreen(0, 1.0);
		$('advSearchLoading').setStyle('display', 'none');
	},
			
	displaySearchResult: function(result)	{
		if (!thLightbox.options.closed)	{
			$('searchResults').innerHTML = result;
			thLightbox.changeContent('searchResults');
		}
	}
});
	
window.addEvent('domready', function()	{
	var searchCtrl = new searchCtrlClass();
	
		// do quick search on submit
	$$('form.searchForm').addEvent('submit', function(e)	{
		e = new Event(e)
		t = new Element(e.target);
		e.stop();
		input = $E('input.searchString',t);
		if (input) {
			searchCtrl.doSearch(input.value);
		}
	});
	
		// clear on focus	
	$$('form.searchForm input.searchString').addEvent('focus', function(e)	{
		e = new Event(e);
		t = new Element(e.target);
		t.value = '';
	});
	
		// do stuff if advanced search is available
	if ($('advSearchForm'))	{
			// init effects
		searchCtrl.init();

			// do advanced search on submit
		$('advSearchForm').addEvent('submit', function(e)	{
			new Event(e).stop();
			searchCtrl.doAdvancedSearch($('advSearchString').value);
		});
		
			// clear on focus
		$('advSearchString').addEvent('focus', function(e)	{
			$('advSearchString').value = '';
		});
		
			// extra field toggle
		$('advSearchFieldToggle').addEvent('click', function(e)	{
			searchCtrl.extraFieldsToggle.toggle();
		});
		
		if ($('adv_search_0'))	{
			// TODO: adjust size of .tabs
			setTimeout(function() {hhtTeaser.activateTab($('adv_search_1'))},1);			
		}
	};

});