if (typeof metro_cnt == 'undefined') {
	var metro_cnt = 0;
}

var ulica_cnt = 0;
var item_i = 0;

$(function(){
	var m = new Array();
	m[85] = new Array("Авиамоторная",0,509,309);
	m[13] = new Array("Автозаводская",0,390,491);
	m[97] = new Array("Академическая",0,191,585);
	m[53] = new Array("Александровский сад",0,223,409);
	m[105] = new Array("Алексеевская",0,390,110);
	m[135] = new Array("Алтуфьево",0,316,60);
	m[156] = new Array("Аннино",0,290,665);
	m[50] = new Array("Арбатская",0,207,393);
	m[5] = new Array("Аэропорт",0,191,100);
	m[109] = new Array("Бабушкинская",0,390,70);
	m[57] = new Array("Багратионовская",0,52,297);
	m[71] = new Array("Баррикадная",0,179,260);
	m[47] = new Array("Бауманская",0,509,229);
	m[69] = new Array("Беговая",0,176,199);
	m[7] = new Array("Белорусская",0,225,239);
	m[93] = new Array("Беляево",0,191,625);
	m[131] = new Array("Бибирево",0,316,70);
	m[30] = new Array("Библиотека Ленина",0,235,409);
	m[120] = new Array("Боровицкая",0,241,419);
	m[107] = new Array("Ботанический сад",0,390,90);
	m[145] = new Array("Братиславская",0,407,625);
	m[195] = new Array("Бунинская аллея",0,290,755);
	m[106] = new Array("ВДНХ",0,390,100);
	m[16] = new Array("Варшавская",0,365,537);
	m[24] = new Array("Вернадского проспект",0,87,645);
	m[112] = new Array("Владыкино",0,316,90);
	m[2] = new Array("Водный стадион",0,191,70);
	m[3] = new Array("Войковская",0,191,80);
	m[77] = new Array("Волгоградский проспект",0,490,625);
	m[142] = new Array("Волжская",0,407,605);
	m[203] = new Array("Волоколамская",0,17,197);
	m[157] = new Array("Воробьевы горы",0,87,625);
	m[198] = new Array("Выставочная",0,128,348);
	m[81] = new Array("Выхино",0,490,665);
	m[6] = new Array("Динамо",0,191,110);
	m[115] = new Array("Дмитровская",0,265,179);
	m[132] = new Array("Добрынинская",0,290,487);
	m[21] = new Array("Домодедовская",0,390,655);
	m[164] = new Array("Донского Дмитрия бульвар",0,290,697);
	m[205] = new Array("Достоевская",0,316,211);
	m[140] = new Array("Дубровка",0,407,575);
	m[43] = new Array("Измайловская",0,509,189);
	m[94] = new Array("Калужская",0,191,615);
	m[18] = new Array("Кантемировская",0,390,625);
	m[17] = new Array("Каховская",0,302,594);
	m[15] = new Array("Каширская",0,390,513);
	m[52] = new Array("Киевская",0,158,377);
	m[74] = new Array("Китай-город",0,354,349);
	m[144] = new Array("Кожуховская",0,407,584);
	m[14] = new Array("Коломенская",0,390,501);
	m[35] = new Array("Комсомольская",0,386,259);
	m[92] = new Array("Коньково",0,191,635);
	m[22] = new Array("Красногвардейская",0,390,671);
	m[133] = new Array("Краснопресненская",0,187,268);
	m[36] = new Array("Красносельская",0,490,100);
	m[34] = new Array("Красные ворота",0,372,273);
	m[139] = new Array("Крестьянская застава",0,456,439);
	m[29] = new Array("Кропоткинская",0,209,436);
	m[62] = new Array("Крылатское",0,17,227);
	m[73] = new Array("Кузнецкий мост",0,317,312);
	m[79] = new Array("Кузьминки",0,490,645);
	m[60] = new Array("Кунцевская",0,17,262);
	m[48] = new Array("Курская",0,421,317);
	m[55] = new Array("Кутузовская",0,72,317);
	m[98] = new Array("Ленинский проспект",0,191,575);
	m[32] = new Array("Лубянка",0,325,320);
	m[143] = new Array("Люблино",0,407,614);
	m[87] = new Array("Марксистская",0,418,397);
	m[204] = new Array("Марьина роща",0,316,189);
	m[146] = new Array("Марьино",0,407,635);
	m[8] = new Array("Маяковская",0,229,265);
	m[110] = new Array("Медведково",0,390,60);
	m[197] = new Array("Международная",0,128,338);
	m[117] = new Array("Менделеевская",0,265,212);
	m[196] = new Array("Митино",0,17,187);
	m[61] = new Array("Молодежная",0,17,237);
	m[202] = new Array("Мякининская",0,17,207);
	m[124] = new Array("Нагатинская",0,290,558);
	m[125] = new Array("Нагорная",0,290,568);
	m[126] = new Array("Нахимовский проспект",0,290,578);
	m[82] = new Array("Новогиреево",0,509,278);
	m[11] = new Array("Новокузнецкая",0,333,399);
	m[134] = new Array("Новослободская",0,265,224);
	m[89] = new Array("Новоясеневская",0,191,667);
	m[95] = new Array("Новые черемушки",0,191,605);
	m[100] = new Array("Октябрьская",0,241,479);
	m[67] = new Array("Октябрьское поле",0,176,179);
	m[20] = new Array("Орехово",0,390,645);
	m[111] = new Array("Отрадное",0,316,80);
	m[31] = new Array("Охотный Ряд",0,289,356);
	m[12] = new Array("Павелецкая",0,384,451);
	m[28] = new Array("Парк Культуры",0,196,449);
	m[165] = new Array("Парк Победы",0,105,376);
	m[44] = new Array("Партизанская",0,509,199);
	m[42] = new Array("Первомайская",0,509,179);
	m[83] = new Array("Перово",0,509,289);
	m[113] = new Array("Петровско-Разумовская",0,290,130);
	m[141] = new Array("Печатники",0,407,595);
	m[59] = new Array("Пионерская",0,32,277);
	m[63] = new Array("Планерная",0,176,139);
	m[86] = new Array("Площадь Ильича",0,456,362);
	m[49] = new Array("Площадь революции",0,307,374);
	m[68] = new Array("Полежаевская",0,176,189);
	m[121] = new Array("Полянка",0,290,469);
	m[130] = new Array("Пражская",0,290,645);
	m[38] = new Array("Преображенская площадь",0,490,80);
	m[76] = new Array("Пролетарская",0,456,451);
	m[136] = new Array("Проспект Мира",0,353,234);
	m[96] = new Array("Профсоюзная",0,191,595);
	m[72] = new Array("Пушкинская",0,223,303);
	m[1] = new Array("Речной вокзал",0,191,60);
	m[104] = new Array("Рижская",0,390,121);
	m[138] = new Array("Римская",0,456,374);
	m[80] = new Array("Рязанский проспект",0,490,655);
	m[116] = new Array("Савеловская",0,265,189);
	m[108] = new Array("Свиблово",0,390,80);
	m[127] = new Array("Севастопольская",0,290,594);
	m[45] = new Array("Семеновская",0,509,209);
	m[122] = new Array("Серпуховская",0,290,499);
	m[192] = new Array("Скобелевская улица",0,290,725);
	m[201] = new Array("Славянский бульвар",0,63,333);
	m[51] = new Array("Смоленская",0,192,378);
	m[4] = new Array("Сокол",0,191,90);
	m[37] = new Array("Сокольники",0,490,90);
	m[26] = new Array("Спортивная",0,87,615);
	m[200] = new Array("Строгино",0,17,217);
	m[54] = new Array("Студенческая",0,82,327);
	m[102] = new Array("Сухаревская",0,353,265);
	m[64] = new Array("Сходненская",0,176,149);
	m[75] = new Array("Таганская",0,414,409);
	m[9] = new Array("Тверская",0,229,293);
	m[10] = new Array("Театральная",0,298,365);
	m[78] = new Array("Текстильщики",0,490,635);
	m[91] = new Array("Теплый стан",0,191,645);
	m[114] = new Array("Тимирязевская",0,265,169);
	m[88] = new Array("Третьяковская",0,322,399);
	m[199] = new Array("Трубная",0,297,243);
	m[123] = new Array("Тульская",0,290,548);
	m[103] = new Array("Тургеневская",0,353,303);
	m[65] = new Array("Тушинская",0,176,159);
	m[70] = new Array("Улица 1905 года",0,176,209);
	m[194] = new Array("Улица Горчакова",0,290,745);
	m[40] = new Array("Улица Подбельского",0,490,60);
	m[25] = new Array("Университет",0,87,635);
	m[193] = new Array("Ушакова адмирала бульвар",0,290,735);
	m[58] = new Array("Филевский парк",0,42,287);
	m[56] = new Array("Фили",0,62,307);
	m[27] = new Array("Фрунзенская",0,87,605);
	m[19] = new Array("Царицыно",0,390,635);
	m[118] = new Array("Цветной бульвар",0,285,243);
	m[39] = new Array("Черкизовская",0,490,70);
	m[128] = new Array("Чертановская",0,290,625);
	m[119] = new Array("Чеховская",0,235,303);
	m[33] = new Array("Чистые пруды",0,353,291);
	m[137] = new Array("Чкаловская",0,423,329);
	m[99] = new Array("Шаболовская",0,191,565);
	m[84] = new Array("Шоссе энтузиастов",0,509,299);
	m[41] = new Array("Щелковская",0,509,169);
	m[66] = new Array("Щукинская",0,176,169);
	m[46] = new Array("Электрозаводская",0,509,219);
	m[23] = new Array("Юго-Западная",0,87,659);
	m[129] = new Array("Южная",0,290,635);
	m[155] = new Array("Янгеля Академика",0,290,655);
	m[90] = new Array("Ясенево",0,191,655);
	
	function SortSelect(select_id) {
		var sortedVals = $.makeArray($('#'+select_id+' option')).sort(function(a,b){
			return $(a).text() > $(b).text() ? 1 : $(a).text() < $(b).text() ? -1 : 0 ;
		});
		$('#'+select_id).empty().html(sortedVals);
	}
	
	function resetForm(formId) {
		$("#"+formId+" :input").each(function(i, el) {
			if(el.defaultValue) {
				$(el).val(el.defaultValue)
			} else {
				$(el).val("")
			}
		})
		$("#"+formId+" :checkbox").val([])
		$("#"+formId+" :radio").val([])
	}
	
	function AddPoint(id) {
		$("#map").append("<img src='/images/point.gif' style='position:absolute;left:" + m[id][2] + "px;top:" + m[id][3] + "px;height:9px;width:9px;cursor:pointer;' class='ps' mid='" + id + "' id='p" + id + "'/>");
	}
	
	function RemovePoint(id) {
		$("#p" + id).remove();
		metro_cnt--;		
	}
	
	$("nav.left.mainpage li").hover(function() {
		$('.subnav').hide();
		$("nav.left li").removeClass('active');

		$('#' + $(this).attr('layer')).show();
		$(this).addClass('active');
	});
	
	$('#add_metro').click(function() {
		if ((typeof one_flag == 'undefined') || ((one_flag == 1) && (metro_cnt == 0))) {
			metro_cnt++;

			selected_items = $("#all_metro option:selected");

			$(selected_items).each(function(i,selected) {
				AddPoint($(selected).val());
				$("#selected_metro").append("<option value='" + $(selected).val() + "'>" + $(selected).html() + "</option>");
				$(selected).remove();
			});

			SortSelect('selected_metro');
		}
		return false;
	});

	$('#remove_metro').click(function() {
		selected_items = $("#selected_metro option:selected");
		$(selected_items).each(function(i,selected) {
			RemovePoint($(selected).val());
			$("#all_metro").append("<option value='" + $(selected).val() + "'>" + $(selected).html() + "</option>");
			$(selected).remove();
		});
		
		SortSelect('all_metro');
		return false;
	});
	
	$('#reset_metro').click(function() {
		selected_items = $("#selected_metro option");
		$(selected_items).each(function(i,selected) {
			$("#all_metro").append("<option value='" + $(selected).val() + "'>" + $(selected).html() + "</option>");
			$(selected).remove();
		});
		
		$('.ps').remove();
		
		SortSelect('all_metro');
		return false;
	});
	
	if ($("#map")) {
		$.each(m, function(i,j) {
			if (j) {
				$("#map").append("<div style='position:absolute;left:" + (j[2]) + "px;top:" + (j[3]) + "px;height:7px;width:7px;cursor:pointer;' class='pdiv' mid='" + i + "' title='" + j[0] + "' />");
			}
		});
		
		if (typeof one_flag == 'undefined') {
			// кольцо
			$("#map").append("<div style='position:absolute;left:51px;top:467px;height:7px;width:7px;cursor:pointer;' class='pdiv2' mid='28,100,132,122,133,71,7,134,117,136,35,48,137,87,75,12,52,205' title='Выделение кольцевых станций' />");
			// внутри кольца
			$("#map").append("<div style='position:absolute;left:51px;top:483px;height:7px;width:7px;cursor:pointer;' class='pdiv2' mid='121,120,30,53,50,51,29,8,9,72,119,73,32,118,199,102,33,103,34,74,11,88,49,10,31' title='Выделение внутри кольца' />");
			// до кольца
			$("#map").append("<div style='position:absolute;left:509px;top:259px;height:7px;width:7px;cursor:pointer;' class='pdiv2' mid='82,83,84,85,86' title='Выделение станций до кольца' />");
			$("#map").append("<div style='position:absolute;left:509px;top:159px;height:7px;width:7px;cursor:pointer;' class='pdiv2' mid='41,42,43,44,45,46,47' title='Выделение станций до кольца' />");
			$("#map").append("<div style='position:absolute;left:490px;top:51px;height:7px;width:7px;cursor:pointer;' class='pdiv2' mid='36,37,38,39,40' title='Выделение станций до кольца' />");
			$("#map").append("<div style='position:absolute;left:390px;top:51px;height:7px;width:7px;cursor:pointer;' class='pdiv2' mid='104,105,106,107,108,109,110' title='Выделение станций до кольца' />");
			$("#map").append("<div style='position:absolute;left:316px;top:50px;height:7px;width:7px;cursor:pointer;' class='pdiv2' mid='111,112,113,114,115,116,131,135' title='Выделение станций до кольца' />");
			$("#map").append("<div style='position:absolute;left:191px;top:51px;height:7px;width:7px;cursor:pointer;' class='pdiv2' mid='1,2,3,4,5,6' title='Выделение станций до кольца' />");
			$("#map").append("<div style='position:absolute;left:176px;top:129px;height:7px;width:7px;cursor:pointer;' class='pdiv2' mid='63,64,65,66,67,68,69,70' title='Выделение станций до кольца' />");
			$("#map").append("<div style='position:absolute;left:17px;top:177px;height:7px;width:7px;cursor:pointer;' class='pdiv2' mid='201,202,196,203,200,54,55,56,57,58,59,60,61,62,165,197,198' title='Выделение станций до кольца' />");
			$("#map").append("<div style='position:absolute;left:87px;top:765px;height:7px;width:7px;cursor:pointer;' class='pdiv2' mid='23,24,25,26,27,157' title='Выделение станций до кольца' />");
			$("#map").append("<div style='position:absolute;left:191px;top:683px;height:7px;width:7px;cursor:pointer;' class='pdiv2' mid='89,90,91,92,93,94,95,96,97,98,99' title='Выделение станций до кольца' />");
			$("#map").append("<div style='position:absolute;left:290px;top:765px;height:7px;width:7px;cursor:pointer;' class='pdiv2' mid='123,124,125,126,127,128,129,130,155,156,164,191,192,193,194,195' title='Выделение станций до кольца' />");
			$("#map").append("<div style='position:absolute;left:390px;top:698px;height:7px;width:7px;cursor:pointer;' class='pdiv2' mid='13,14,15,16,17,18,19,20,21,22' title='Выделение станций до кольца' />");
			$("#map").append("<div style='position:absolute;left:413px;top:680px;height:7px;width:7px;cursor:pointer;' class='pdiv2' mid='138,139,140,141,142,143,144,145,146' title='Выделение станций до кольца' />");
			$("#map").append("<div style='position:absolute;left:490px;top:685px;height:7px;width:7px;cursor:pointer;' class='pdiv2' mid='76,77,78,79,80,81' title='Выделение станций до кольца' />");
		}		
	}
	
	$('.pdiv').click(function() {
		if ((typeof one_flag == 'undefined') || ((one_flag == 1) && (metro_cnt == 0))) {
			metro_cnt++;

			id = $(this).attr('mid');
			selected = $("#all_metro option[value='"+id+"']");

			AddPoint(id);
			$("#selected_metro").append("<option value='" + id + "'>" + $(selected).html() + "</option>");
			$(selected).remove();

			SortSelect('selected_metro');
		} else if ((typeof one_flag != 'undefined') && (metro_cnt == 10)) {
			$("select[name='metro'] option").attr('selected','');

			metro_cnt++;

			id = $(this).attr('mid');
			AddPoint(id);
			
			$("select[name='metro'] option[value='"+id+"']").attr('selected','selected');
		}
	});
	
	$('.pdiv2').click(function() {
		if (typeof one_flag == 'undefined') {
			metro_cnt++;

			arr_id = $(this).attr('mid').split(',');
			$.each(arr_id, function(i, id) {
				if ($('#p' + id).length > 0) {
					selected = $("#selected_metro option[value='"+id+"']");
					RemovePoint(id);
					$("#all_metro").append("<option value='" + id + "'>" + $(selected).html() + "</option>");
					$(selected).remove();
				} else {
					selected = $("#all_metro option[value='"+id+"']");
					AddPoint(id);
					$("#selected_metro").append("<option value='" + id + "'>" + $(selected).html() + "</option>");
					$(selected).remove();
				}
			});
			
			SortSelect('selected_metro');
		}
	});
	
	$('.ps').live('click', function() {
		id = $(this).attr('mid');
		selected = $("#selected_metro option[value='"+id+"']");

		RemovePoint(id);
		$("#all_metro").append("<option value='" + id + "'>" + $(selected).html() + "</option>");
		$(selected).remove();

		SortSelect('all_metro');
		return false;
	});
	
	$('#reset_form').click(function() {
		resetForm('searchform');
		selected_items = $("#selected_metro option");
		$(selected_items).each(function(i,selected) {
			$("#all_metro").append("<option value='" + $(selected).val() + "'>" + $(selected).html() + "</option>");
			$(selected).remove();
		});
		
		$('.ps').remove();
		
		SortSelect('all_metro');
		
		return false;	
	});
	
	$('#clear_button').click(function() {
		resetForm('add_form');
		$('.ps').remove();
		
		SortSelect('all_metro');

		metro_cnt = 10;
		return false;	
	});
	
	$('#submit_form').click(function() {
		$('#searchform').submit(); 
		return false;
	});
	
	$('#a_metro').click(function() {
		$('.what-metro').show();
		$('#a_metro').addClass("selected");
		$('.what-map').hide();
		$('#a_karta').removeClass("selected");
		$('#sby').val('0');
		
		return false;
	});
	
	$('#a_karta').click(function() {
		$('.what-metro').hide();
		$('#a_metro').removeClass("selected");
		$('.what-map').show();
		$('#a_karta').addClass("selected");
		$('#sby').val('1');
		
		init('YMapsID','37.64','55.76');	
		return false;
	});	
	
	$('.add2notepad').click(function() {
		num = $(this).attr('num');
		img = $(this).children('img');
		$(img).css('width', '15px');
		
		if ($(img).attr('src') == '/images/bg_search-del.png') {
			$(img).attr('src', '/images/process.gif');
			
			$.ajax({
				url: "/catalog/notepad",
				type: "POST",
				data: {act: 'remove_id', id: num},
				success: function(data){
					$(img).css('width', '15px');
					$(img).attr('src', '/images/bg_search-add.png');
				}
			});
		} else {
			$(img).attr('src', '/images/process.gif');
			
			$.ajax({
				url: "/catalog/notepad",
				type: "POST",
				data: {act: 'add_id', id: num},
				success: function(data){
					$(img).css('width', '15px');
					$(img).attr('src', '/images/bg_search-del.png');
				}
			});
		}
		
		return false;
	});
	
	if (!window.opera) {
		$('a.l_star').click(function(event){
			event.preventDefault(); // prevent the anchor tag from sending the user off to the link
			var url = this.href;
			var title = this.title;

			if (window.sidebar) { // Mozilla Firefox Bookmark
				window.sidebar.addPanel(title, url,"");
			} else if(window.external) { // IE Favorite
				window.external.AddFavorite( url, title);
			} else { // for Safari, Konq etc - browsers who do not support bookmarking scripts (that i could find anyway)
				 alert('Для сохранения страницы нажмите сочетание Ctrl-D');
			}
		});
	}
	
	$('.add2favorite').click(function() {
		return false;
	});	
	
	$('#search_street_add').click(function() {
		if (ulica_cnt == 0) {
			ulica_cnt++;
				
			function Request() {
				url = "http://geocode-maps.yandex.ru/1.x/?format=json&geocode=" + $("select[name='city'] option:selected").text() + ', ' + $("input[name='street']").val() + "&key=" + yandex_key;
				$.ajax({
					url: url,
					type: "GET",
					data: {},
					dataType: 'jsonp',
					success: function (data) {
						$("#streets_cont").empty();
						if (data.response.GeoObjectCollection.featureMember.length > 0) {
							streets_select = $("<select class='ctrDropDown' id='streets_select_add' style='margin-bottom:2px;'><option value=''>-- выберите объект --</option></select>");
							$.each(data.response.GeoObjectCollection.featureMember, function(i,v) {
								ll = v.GeoObject.Point.pos.split(" ");
								val = v.GeoObject.metaDataProperty.GeocoderMetaData.text.replace(/Россия, /mg, "");
								streets_select.append($("<option value='"+val+"' lng='"+ll[0]+"' lat='"+ll[1]+"'>"+val+"</option>"));
							});
							sel_cont = $('<div id="sel_cont"></div>').append(streets_select);
							$("#streets_cont").prepend(sel_cont);
						} else {
							alert('Таких объектов в базе не найдено!');
							$('#search_street_add').attr('disabled','');
							$("input[name=street]").attr('disabled','');
							ulica_cnt--;
						}

						$("input[name=street]").val('');
					}
				});
			}
			
			Request();
		}
		return false;
	});
	
	$('#search_street').click(function() {
		if ((typeof one_flag == 'undefined') || ((one_flag == 1) && (ulica_cnt == 0))) {
			ulica_cnt++;
			street = $("input[name=street]").val();
			type = $("#type").val();

			if (street.length <= 2) {
				alert('Пожалуйста, введите более 2 символов');
				ulica_cnt--;
			} else {
				$(this).attr('disabled','disabled');
				$("input[name=street]").attr('disabled','disabled');
				
				url = "http://geocode-maps.yandex.ru/1.x/?format=json&geocode=" + $("select[name='where[]'] option:selected").text() + ', ' + street + "&key=" + yandex_key;
				$.ajax({
					url: url,
					type: "GET",
					data: {},
					dataType: 'jsonp',
					success: function (data) {
						if (data.response.GeoObjectCollection.featureMember.length > 0) {
							streets_select = $("<select class='ctrDropDown' id='streets_select' style='margin-bottom:2px;'><option value=''>-- выберите объект --</option></select>");
							$.each(data.response.GeoObjectCollection.featureMember, function(i,v) {
								ll = v.GeoObject.Point.pos.split(" ");
								val = v.GeoObject.metaDataProperty.GeocoderMetaData.text.replace(/Россия, /mg, "");
								streets_select.append($("<option value='"+val+"' lng='"+ll[0]+"' lat='"+ll[1]+"'>"+val+"</option>"));
							});
							
							sel_cont = $('<div id="sel_cont"></div>').append(streets_select);
							$("#streets_cont").prepend(sel_cont);
						} else {
							alert('Таких объектов в базе не найдено!');
							$('#search_street').attr('disabled','');
							$("input[name=street]").attr('disabled','');
							ulica_cnt--;
						}

						$("input[name=street]").val('');
					}
				});
			}
		}
		return false;
	});
	
	// $('#search_street').click(function() {
		// if ((typeof one_flag == 'undefined') || ((one_flag == 1) && (ulica_cnt == 0))) {
			// ulica_cnt++;	
			// street = $("input[name=street]").val();
			// type = $("#type").val();

			// if (street.length <= 2) {
				// alert('Пожалуйста, введите более 2 символов');
				// ulica_cnt--;
			// } else {
				// $(this).attr('disabled','disabled');
				// $("input[name=street]").attr('disabled','disabled');
				
				// $.ajax({
					// url: "/catalog/ajax",
					// type: "POST",
					// dataType: "json",
					// data: {form: $("#searchform").serialize(), search: street, type: type},
					// success: function (data) {
						// if (data.result == "ok") {
							// streets_select = $("<select id='streets_select' style='margin-bottom:2px;'><option value=''>-- выберите --</option></select>");
							// $.each(data.data, function(i,v) {
								// v = v.replace(/Россия, /mg, "");
								// streets_select.append($("<option value='"+v+"'>"+v+"</option>"));
							// });
							// $("#streets_cont").prepend(streets_select);
						// } else {
							// alert('Таких улиц в базе не найдено!');
							// $('#search_street').attr('disabled','');
							// $("input[name=street]").attr('disabled','');
							// ulica_cnt--;
						// }

						// $("input[name=street]").val('');
					// }
				// });
			// }
		// }
		// return false;
	// });

	$('#streets_select').live('change', function() {
		$("#streets_cont select").remove();
		$("#sel_cont").remove();

		$("#streets_cont").append('<span id="spn'+item_i+'" style="display:block;width:100%;font-style:italic;margin-bottom:3px;"><input type="hidden" name="street[]" value="' + $(this).val() + '" /><p style="display:block;float:left;width:220px;white-space:nowrap;overflow-x:hidden;">' + $(this).val() + '</p><a href="#" style="float:right;color:red;" onclick="$(this).parent().remove(); ulica_cnt--; return false;">удалить</a></span>');

		$('#spn'+item_i).children('a').css('line-height', $('#spn'+item_i).children('p').height() + 'px');
		
		$('#search_street').attr('disabled','');
		$("input[name=street]").attr('disabled','');
		item_i++;
	});
	
	$('#streets_select_add').live('change', function() {
		$("#streets_cont select").remove();
		$("#sel_cont").remove();
		
		$("#streets_cont").append('<span id="spn'+item_i+'" style="display:block;width:100%;font-style:italic;margin-bottom:3px;"><input type="hidden" name="street[]" value="' + $(this).val() + '" /><p style="display:block;float:left;width:220px;white-space:nowrap;overflow-x:hidden;" title="' + $(this).val() + '">' + $(this).val() + '</p><a href="#" style="float:right;color:red;" onclick="$(this).parent().remove(); ulica_cnt--; return false;">удалить</a></span>');

		$("#lat").val($(this).children('option:selected').attr('lat'));
		$("#lng").val($(this).children('option:selected').attr('lng'));
		
		$('#streets_select_add').attr('disabled','');
		$("input[name=street]").attr('disabled','');
		item_i++;
	});
	
	$("#add_button").click(function(){
		$("#add_form").submit();
		return false;
	});
	
	$('#shosse_select').live('change', function() {
		$("#shosse_cont").append('<span style="display:block;width:100%;font-style:italic;text-align:left;"><input type="hidden" name="shosse[]" value="' + $(this).val() + '" /><p style="display:block;float:left;width:220px;white-space:nowrap;overflow-x:hidden;">' + $(this).val() + '</p><a href="#" style="float:right;color:red;" onclick="$(this).parent().remove(); return false;">удалить</a></span>');
		$('#shosse_select option:eq(0)').attr('selected', 'selected');
	});

	if ($.browser.msie) {
		$('body').append('<style>#sel_cont { width: 284px !important; overflow-x: hidden; } .ctrDropDown { width:284px; }</style>');
		
		$('#sel_cont select').live('blur', function() {
				$(this).addClass('ctrDropDown');
			}).live('mousedown', function() {
				width = 0;
				var opts = $(this).children('option');
				opts.each(function(){
				  if ($(this).text().length > width){
					width = $(this).text().length;
				  }
				});
				
				true_width = width * 6 + 35;
				true_width = (true_width.toFixed(0));

				true_width = true_width > 284 ? true_width : 284;
				
				$(this).removeClass('ctrDropDown').css('width', true_width);
			}).live('change', function() {
				$(this).addClass('ctrDropDown');
			});
	}
});
