$(document).ready(function(){

	//	поиск

	if ($('div.search-analytics').length){
		var stype = '';
		var town = $('dl.towns ul li.active span').attr('rel');
		var mtype = $('dl.mtype ul li.active span').attr('rel');

		$('ul.list-type span').click(function(){
			stype = $(this).attr('rel');
			mtype = $('dl.mtype ul li.active span').attr('rel');
			$(this).parents('ul.list-type').find('li.active').animate({top:$(this).parent().position().top},500);
			$(this).parents('ul.list-type').find('span').removeClass('ltactive');
			$(this).addClass('ltactive');

			$('a#all-town').removeClass('active');
			$('dl.mtype').removeClass('disabled');
			anal_tableload();
		});

		$('dl.towns, dl.mtype').hover(function(){
			$(this).find('dd').show();
		},function(){
			$(this).find('dd').hide();
		});

		$('dl.towns ul span').click(function(){
			$('dl.towns dt').html($(this).html());
			town = $(this).attr('rel');
			$('dl.towns ul li.active').removeClass('active');
			$(this).parent().addClass('active');
			anal_tableload();
			$('dl.towns dd').hide();

			$('a#all-profile').removeClass('active');
			$('dl.towns').removeClass('disabled');
		});

		$('dl.mtype ul span').click(function(){
			$('dl.mtype dt').html($(this).html());
			mtype = $(this).attr('rel');
			$('dl.mtype ul li.active').removeClass('active');
			$(this).parent().addClass('active');
			anal_tableload();
			$('dl.mtype dd').hide();

			$('ul.specialization').hide();
			if (mtype=='verstka'){
				$('div.list-type h4').hide();
			}else{
				$('div.list-type h4').show();
				$('ul.spz'+mtype).show();
				styp = $('ul.spz'+mtype+' span.ltactive').attr('rel');
			}
			$('a#all-town').removeClass('active');
			$('dl.mtype').removeClass('disabled');
		});

		function anal_tableload(){
			$('div.results').css('height',$('div.results').height()).addClass('loading');
			$('div.results').empty();
			$.get("/ajax/",{
				'stype': 'analytics',
				'town': town,
				'type': stype,
				'mtype': mtype
			},function (data, textStatus){
				$('div.results').empty();
				$(data).prependTo('div.results');
				$('div.results').animate({
					height: ($('div.result-wrap').height())? $('div.result-wrap').height(): $('div.results p').height()
				},500,'',function(){
					if ($.browser.msie)	$('div.footer .copyright span').get(0).innerHTML+='';
				}).removeClass('loading');
			});
		}

		$('a#all-town').click(function(){
			town = $('dl.towns ul li.active span').attr('rel');
			mtype = 0;
			$('dl.towns').removeClass('disabled');
			$('dl.mtype').addClass('disabled');

			$(this).addClass('active');
			$('a#all-profile').removeClass('active');
			specialisttableload();
			return false;
		});

		$('a#all-profile').click(function(){
			town = 0;
			mtype = $('dl.mtype ul li.active span').attr('rel');
			$('dl.towns').addClass('disabled');
			$('dl.mtype').removeClass('disabled');

			$(this).addClass('active');
			$('a#all-town').removeClass('active');
			anal_tableload();
			return false;
		});
	}

});