 $(function(){
  //  try {
   if (global_lang != 'en') {
   	loadingText_Hint = 'Tippen Sie 3 Buchstaben und finden Sie &hellip;<br /><ul class="hint"><li class="hint_type_product">Produkte</li> <li class="hint_type_object">Objekte</li> <li class="hint_type_category">Kategorien</li> <li class="hint_type_region">Straßen / Regionen</li> </ul>';
   	loadingText_Field = 'Suchen Sie ...';
   }
   else {
   	loadingText_Hint = 'type 3 characters and find ... <ul class="hint"><li class="hint_type_product">products</li> <li class="hint_type_object">objects</li> <li class="hint_type_category">categories</li> <li class="hint_type_region">streets / districts</li> </ul>';
   	loadingText_Field = 'Search ...';
   }
   var ac_height = 450; 
   var params = ""; 
   if ( typeof( az_height_suggest ) != "undefined" && az_height_suggest > 0 ) { 
   		ac_height = az_height_suggest ;
		params = "?az_iframe=1"
   }
   
  	$("input#search_text").autocomplete('/neu_ajax.php'+params , {
			width : '414px',  
			height: '420px',
			max : '20', 
			minChars: 3,
			scrollHeight : ac_height + 'px' ,
			selectFirst : false,  
			delay: 300,
			cacheLength: 0,
		formatResult: function(data, value){
		//	$('#search_text_url').val(  data[1].replace(/ /g,"+") ); 
			return data[1]; //.replace(/ /g,"+");
		},
		formatItem: function(data, i, n, value){
			if( typeof(data[1]) != 'undefined' ) {
				//return  "<table class='suggest'><tr><th class='type_"+data[2]+"'>"+ data[2] + "</th><td>"+ data[1] +"</td><td class='info'>"+ data[0]+ "</td></tr></table>";  
				//return  "<table class='suggest'><tr><th class='type_"+data[2]+"'>"+ data[2] + "</th><td>"+ data[1] +"</td></tr></table>";  
			
				return  "<table cellpadding='0' cellspacing='0' border='0' class='suggest suggest_"+data[2]+"'><tr><th class='type_"+data[2]+"'></th><td>"+ data[1] +"</td></tr></table>";  
					// <!-- <td class='info'><em> "+ data[2] +"</em></td>-->
			} else {
				return false;
			}
		}
		
	}).result(function(event, data, formatted) {
 		short = data[1] ;
	
		
			
		if (data[2] == 'Kategorie') {
			//console.log( data );
			$('#search_text').val('');
			//$('#leftcolumn').load('/-/-/' + data[0] + '/search./object/index.html #leftcolumn');
			//document.location.href= '/-/-/cat.' + data[0] + '/search./object/index.html';
			
			//document.location.href = '/' +  data[0] ; // short
			//return false;
			data[1] = data [0];	
		}
		if ( data[2] == 'query') {
			$('#search_text').val(data[3]);
			return false; 
		} 
		
		if ( data[2]=='category-more') {
			top.location.href = '/' +  data[6].replace(/ /g,"+") + "/Overview" ; // short (by language !)
			return false;
		}	
		if ( data[2]=='location-more') {
			top.location.href = '/' +  data[6].replace(/ /g,"+") + "/Overview" ; // short (by language !)
			return false;
		}	
		if ( data[2]=='objects-more') {
			top.location.href = '/' +  data[6].replace(/ /g,"+") + "/Objekte" ; // short (by language !)
			return false;
		}	
		
		if (data[2] == 'object-id') {
			if ( data.length >2 && data[3]!="" ) {
				$('#search_text').val('');
				top.location.href = '/' +  data[3] ; // short
			}
			else {
				$('#search_text').val('');
				//alert( '/'+ data[1].replace(/ /g,"-") + '/' +  data[0] +"-mux" ); 
				top.location.href = '/'+ data[1].replace(/ /g,"-") + '-mux' +  data[0] +""; // short
			}
			return false;
		}
		if (data[2] == 'product-id' || data[2] == 'product-more') {
			
			// name reapeats
			if ( data[5] > 1) {
			    // start product search ?
				top.location.href = '/' +  data[6].replace(/ /g,"+") + "/Produkt" ; // short (by language !)
				return false; 
			}
			
			if ( data.length >2 && data[3]!="" ) {
				$('#search_text').val('');
				top.location.href = '/' +  data[3] ; // short
			}
			else {
				$('#search_text').val('');
				//alert( '/'+ data[1].replace(/ /g,"-") + '/' +  data[0] +"-mux" ); 
				top.location.href = '/'+ data[1].replace(/ /g,"-") + '-mux' +  data[0] +""; // short
			}
			return false;
		}
		
		if ( data[4]=='last') {
			$('#search_text').val( data[5] + " " + data[1]); 
			$('#search_text_url').val( data[5] + " " + data[1].replace(/ /g,"+") ); 
		}
		if ( data[4]=='full') {
			$('#search_text').val(  data[1]); 
			$('#search_text_url').val(  data[1].replace(/ /g,"+") ); 
		}
		//alert("submit " + $('#search_text'.val() + " " + $('#search_text_url').val() + "..") ); 
		$('#search').submit(); 
		
		return false; 
	});
	
	$('#search_hint').html( loadingText_Hint );
	$('#search_hint_field').html( loadingText_Field );
	
	if ( $('#search_text') && !location.hash && ( typeof(az_iframe) == "undefined" || az_iframe == 0) ) {
	  		$('#search_text').focus();
	} 
	
  	//} catch(e) {}
});
