$(function(){
	
	var $region = $('.hotline-select-region select');
	var $settlement = $('.hotline-select-settlement select')
	$region.change(function(){
		$settlement.empty();
		$.ajax({
			url: 'http://mrsk-yuga.ru/ajax/hotline.php?region='+$(this).val(),
			dataType: 'jsonp',
			success: function(data){
				$settlement.append('<option value="0">Выберите населенный пункт</option>');
				for (var i in data) {
					$settlement.append('<option value="'+data[i].phones+'">'+data[i].title+'</option>');
				}
			}
		})
	});
	
	try {
		if (location.host == 'astrakhanenergo.mrsk-yuga.ru')
			$region.find('option[value="1"]').attr('selected', true).end().change();
		if (location.host == 'volgogradenergo.mrsk-yuga.ru')
			$region.find('option[value="16"]').attr('selected', true).end().change();
		if (location.host == 'kalmenergo.mrsk-yuga.ru')
			$region.find('option[value="59"]').attr('selected', true).end().change();
		if (location.host == 'rostovenergo.mrsk-yuga.ru')
			$region.find('option[value="73"]').attr('selected', true).end().change();
	} catch (e) {}
	
	$settlement.change(function(){
		
		var val = $settlement.val();
		if (val == 0) return;
		
		var region = $region.find('option:selected');
		$('#hotline-infobox-content').html(region.text() + ' &mdash; ' + region.attr('data-filial') + '<br/>' 
			+ $settlement.find('option:selected').text() 
			+ '<div class="hotline-phones">'+$settlement.val()+'</div>'
		);
		
		$('#locker').show();
		$('#hotline-infobox').show();
	});
	
	$('.hotline-infobox-close').click(function(){
		$('#locker').hide();
		$('#hotline-infobox,#presentation').hide();
	});
});

