
	document.addEvent('domready', function() 
	{
		var locComp;

		$('autocomplete-location-button').fade(0,0);			
		$('autocomplete-overlay').setStyles({'opacity': 0, 'visibility': 'hidden' });
		
		new Autocompleter.Request.JSON(
			$('autocomplete-search'),
			'http://www.preistipp.de/ajax.search.php', {
				'indicatorClass': 'autocompleter-loading',
				'multiple': false,
				'selectFirst': false,
				'selectMode': true,
				'filterSubset': true,
				'minLength': 3,
				'maxChoices': 40,
				'isCategorized': true,
				'autoTrim': true,
				'categories': 'Produkte,Hersteller'
			}
		);
		
		locComp = new Autocompleter.Request.JSON(
			$('autocomplete-location'),
			'http://www.preistipp.de/ajax.local.php', {
				'indicatorClass': 'autocompleter-loading',
				'multiple': false,
				'selectFirst': false,
				'selectMode': false,
				'filterSubset': true,
				'autoTrim': true,
				'isEmbedded': true,
				'minLength': 1,
				'zIndex': 20000,
				'width': 233,
				'onHide': function() {
//					$('autocomplete-overlay-suggestions').style.display = 'none';
//					$('autocomplete-overlay-bg').tween('height','52px');
				},
				'onShow': function() {
					$('autocomplete-overlay-suggestions').style.display = 'block';
					var num;
					num = $('autocompleter-choices');
					num = num.getChildren();
					num = ( num.length == 0 ? 1 : num.length );
					min = ( num == 0 ? -28 : 0);
					$('autocomplete-overlay-bg').tween('height',(185 + num * 19 + min) + 'px');
					$('autocompleter-choices').tween('height',(num * 19) + 'px');
				},
				'onUpdate': function() {
					$('autocomplete-overlay-suggestions').style.display = 'block';
					var num;
					num = $('autocompleter-choices');
					num = num.getChildren();
					num = ( num.length == 0 ? 1 : num.length );
					min = ( num == 0 ? -28 : 0);
					$('autocomplete-overlay-bg').tween('height',(185 + num * 19 + min) + 'px');
					$('autocompleter-choices').tween('height',(num * 19) + 'px');
				}
			}
		);

		$('autocomplete-location').addEvent('focus', function() {
			$('autocomplete-overlay-suggestions').style.display = 'block';
			var num;
			num = $('autocompleter-choices');
			num = num.getChildren();
			num = ( num.length == 0 ? 1 : num.length );
			min = ( num == 0 ? -28 : 0 );
			$('autocomplete-overlay-suggestions').style.display = 'block';
			$('autocomplete-overlay').fade(1);
			$('autocomplete-overlay-bg').tween('height',(185 + num * 19 + min) + 'px');
			$('autocomplete-location').tween('width','173px');
			$('autocomplete-location-button').tween('opacity','1');
		});
		
		function autocomplete_fill() {
			if($('autocompleter-choices').getChildren().length == 0) {
				$('autocompleter-choices').innerHTML = '<li>Geben Sie bitte Ihren Standort ein.</li>';
			}
		}
		
		$('autocomplete-search').addEvent('focus',function(obj) {
			if($('autocomplete-search').value == 'Wonach suchen Sie?') $('autocomplete-search').value = '';
		});
		
		$('autocomplete-search').addEvent('blur',function(obj) {
			if($('autocomplete-search').value == '') $('autocomplete-search').value = 'Wonach suchen Sie?';
		});


//		$('autocomplete-location').addEvent('blur', function() {
//			window.setTimeout("hideLoc();",100);
//		});
		
		$('autocomplete-location-button').addEvent('mouseover', function() {
			$('autocomplete-location-button').src = $('autocomplete-location-button').src.replace('-0.gif','-1.gif');
		});
		
		$('autocomplete-location-button').addEvent('mouseout', function() {
			$('autocomplete-location-button').src = $('autocomplete-location-button').src.replace('-1.gif','-0.gif');
		});
		
		$('autocomplete-location-help').addEvent('click', function() {
			if($('autocomplete-location-help-tooltip').style.opacity == 1) $('autocomplete-location-help-tooltip').fade(0);
			 else $('autocomplete-location-help-tooltip').fade(1);
		});
	});
	
	function hideLoc() {
		$('autocomplete-overlay-suggestions').style.display = 'none';
		$('autocomplete-overlay-bg').tween('height','52px');
		window.setTimeout("$('autocomplete-overlay').fade(0);",250);
		$('autocomplete-location').tween('width','218px');
		$('autocomplete-location-button').tween('opacity','0');
		$('autocomplete-location').blur();
	}
	
	function setLoc(txt,id,category) {
		if(category == 'Produkte') document.location.href = 'http://www.preistipp.de/__preisvergleich_' + id + '/';
		if(category == 'Hersteller') document.location.href = 'http://www.preistipp.de/suche/?m=' + id + '&text=' + txt;
		if(category == 'Händler') document.location.href = 'http://www.preistipp.de/_partner_' + id + '/';
	}
