var resultArr = new Array();
resultArr[0]=[];
resultArr[1]=[];
resultArr[2]=[];
resultArr[0]['id']='null';

$(document).ready(function(){
	$("a[rel^='prettyPhoto']").prettyPhoto({theme:'light_square', showTitle:true, animationSpeed:'fast', allowresize:true});
	$("dd").hide();
	$("dt a").click(function(){
		$("dd:visible").slideUp("slow");
		$(this).parent().next().slideDown("slow");
		return false;
	});
	fixPNG(document.getElementById('loc_name1'));

	$("#loc_name1").autocomplete("/ajax_responders/answer.php", {
		  delay:1000,
		  minChars:2,
		  matchSubset:1,
		  autoFill:true,
		  matchContains:1,
		  cacheLength:50,
		  selectFirst:true,
		  maxItemsToShow:50,
		  formatItem:formatcity,
		  onItemSelect:point_loc,
	  inputClass:'ac_input',
	  loadingClass:'ac_loading',
		  extraParams:{data:"city",step:"1"}
	});

	function point_loc(li){
		if (li!=null){
			if (li.extra[1]=='-1') { //совпадений не найдено
				$('#loc_name1').val('');
				$('#found_place_alias').val('');
				$('#found_place_id').val('');
				return false;
			}
			if(li.extra[11] != '' && parseInt(li.extra[1]) > 0) {
				$('#found_place_alias').val(li.extra[11]);
				$('#found_place_id').val(li.extra[1]);
				$('#found_place_type').val('c');
				//top.location.href='/'+li.extra[11]+'_'+li.extra[1]+'_c.html#info';
			} else if(parseInt(li.extra[1]) > 0) {
				$('#found_place_alias').val('');
				$('#found_place_id').val(li.extra[1]);
				$('#found_place_type').val('c');
				//top.location.href='/index.php?city_id='+li.extra[1]+'#info';
			} else {
				$('#found_place_alias').val('');
				$('#found_place_id').val('');
			}
		}
		$("#loc_name1").val(formatcity4input(li.extra,0,0));
		if (li!=null){
			goto_loc('mix');
		}
		return true;
	}
});

function goto_loc(what) {
	if(what != 'autos' && what != 'cargo' && what != 'mix') {
		what = mix;
	}

	var _alias = $('#found_place_alias').val();
	var _id = $('#found_place_id').val();
	var _type = $('#found_place_type').val();

	var postfix = '';

	if(what != 'mix') {
		postfix = '/all_'+what+'_total';
	}
	if(_alias != '' && _id != '') {
		top.location.href='/'+_alias+'_'+_id+'_'+_type+postfix+'.html';
	} else if(_alias != '') {
		top.location.href='/'+_alias+'_'+_type+postfix+'.html';
	} else if(_id != '') {
		top.location.href='/index.php?city_id='+_id+'#info';
	} else {
		info_alert('Населенный пункт не найден! Попробуйте заново набрать название в строке поиска.');
	}
	return false;
}


