

var GameSearch = {};

GameSearch.wasCleared = false;

GameSearch.clearInputText = function() {
	if(GameSearch.wasCleared){
		return
	}
	GameSearch.wasCleared = true;
	var el = $('gameFinderInput');
	var altValue = el.getProperty('alt');
	var value = el.getProperty('value');
	if(altValue == value){
		$('gameFinderInput').setProperty('value','')
	}
}

GameSearch.updateInputText = function() {
	var el = $('gameFinderInput');
	if(!el.getProperty('value')){
		GameSearch.wasCleared = false;
		el.setProperty('value',el.getProperty('alt'));
	}
}

document.addEvent('domready', function() {
	if(!$('gameFinderTokens') || !$('gameFinderInput')){
		return;
	}
	var tokens = $('gameFinderTokens').get('html').split(",").map(function(item){return item.trim().replace(/&amp;/gi,'&').replace(/&lt;/gi,'<').replace(/&quot;/gi,'"')});
	
	new Autocompleter.Local('gameFinderInput', tokens, {
		'minLength': 1, 
		'selectMode': 'type-ahead', 
		'multiple': false 
	});
});

