$(document).ready(function(){
	var weatherURL = '/pages/gisweather?town=';
	var msgLoading = '<div style="padding:10px;"><img src="/assets/templates/z/images/loader.gif" alt="Загрузка..." /></div>';
	var msgError = '<div style="padding:5px;">Прогноз не найден</div>';
	$('.jot-form').hide();
	var townNames = new Array();
	townNames[28411]='Ижевск';
	townNames[28214]='Глазов';
	townNames[99690]='Сюмси';
	townNames[28318]='Воткинск';
	townNames[28409]='Можга';
	townNames[99680]='Яр';
	townNames[99684]='Юкаменское';
	townNames[99683]='Балезино';
	townNames[99687]='Кез';
	townNames[28312]='Дебессы';
	townNames[28315]='Игра';
	townNames[28309]='Селты';
	townNames[99682]='Якшур-Бодья';
	townNames[99681]='Шаркан';
	townNames[99691]='Ува';
	townNames[28403]='Вавож';
	townNames[28418]='Сарапул';
	townNames[99689]='Киясово';
	townNames[89134]='Камбарка';
	townNames[99688]='Кизнер';
	townNames[99686]='Каракулино';
	townNames[99685]='Грахово';
// раскраска нечетных строк таблиц
	$("input, textarea, select, button").uniform();
	$("#content table tr:odd").css("background-color","#F4F4F4");
// навешиваем hover на строки таблиц
	var oldBgColor;
	$("#content table tr").hover(
	      function () {
		oldBgColor = $(this).css("background-color");
		$(this).css("background-color","#D6F2FF");
		},
	      function () {
		$(this).css("background-color",oldBgColor);	
		});
// определеям город
	var town = $.cookie("zagorod_town_weather");
	if (!town) town = 28411;
// вывод погодного информера через ajax
	$.ajax({
	  url: weatherURL+town,
	  cache: false,
	  success: function(html){
	    $("#info-weather").html(html);
	    $("#now-town").text(townNames[town]);
	  },
	  error: function(){
	   $("#info-weather").html(msgError);	
	  }
	});
// выбор города для погодного информера
	$('small.choose-town').click(function(){
		if ($('.town-form').hasClass('active')){
			$('.town-form').removeClass('active').animate({top: -600});
		}else{
			var infoWeatherTop = $("#info-weather").offset();
			infoWeatherTop = infoWeatherTop.top - 40; 
			$('.town-form').addClass('active').animate({top: infoWeatherTop});
		}
		return false;
	});
	$('.town-form .close').click(function(){
		$('.town-form').removeClass('active').animate({top: -600});
	});
	$('span.town').click(function(){
		var townID = $(this).attr('id');
		$('.town-form').removeClass('active').animate({top: -600});
		$("#info-weather").html(msgLoading);
		// здесь вызов ajax
		$.ajax({
		  url: weatherURL+townID,
		  cache: false,
		  success: function(html){
    		    $("#info-weather").html(html);
 		// и в случае успеха меняем название города
		    $('small.choose-town').text(townNames[townID]);
		    $.cookie("zagorod_town_weather", townID, {expires: 100, path: '/'});		
		  },
		  error: function(){
		   $("#info-weather").html(msgError);
		   $('small.choose-town').text(townNames[townID]);	
		  }
		});
	});
// ajax запрос для быстрого поиска
	var baseType = '';
	var baseRaion = '';
		$('#tvBaseType,#tvBaseRaion').change(function(){
		$('#sidebarResultNum').html('<span><img src="/assets/images/ajax-loader.gif" alt="load"/></span>');
		baseType = $('#tvBaseType').val();
		baseRaion = $('#tvBaseRaion').val();
		$('#sidebarResultNum').load('/pages/numfinds?id=1&tvBaseType='+baseType+'&tvBaseRaion='+baseRaion+'&search=');
	});
	$('#sidebarResultNum').text('›100');
	//$("#tvBaseType").trigger('change');
	$('#commentLink').click(function(){
		$('.jot-form').toggle('fast');
	});
// делаем блок сравнения "плавающим"
/*
		var offset = $(".sticky div.div-color").offset();
		if (offset)
		{
		var maxOffset = $("#footer").offset();
		var stopOffset = maxOffset.top - $("#footer").height()-20;
		var topPadding = 0;
		$(window).scroll(function() {
			if (($(window).scrollTop() > offset.top) && ($(window).scrollTop() < stopOffset)) {
				$(".sticky div.div-color").stop().animate({marginTop: $(window).scrollTop() - offset.top + topPadding});
			}
			else if (($(window).scrollTop() <= offset.top)) {$(".sticky div.div-color").stop().animate({marginTop: 0});};});
		}
*/
});
