$(document).ready(function(){
	
	if($("#nav").find("div.a").is("div.a")){
		if($("#nav").find("div.a").parents("ul").is("ul")){
			$("#nav").find("div.a").parents("ul").slideDown("fast");
		}
		if($("#nav").find("div.a").parents("ul").is("#nav")){
			$("#nav").find("div.a").next("ul").slideDown("fast");
		}
		
	}
	
//		$("#nav").find("div.a").parents("ul").slideDown("fast");
	
	//$("a[@name='togglemenu']").toggle(
	$("a[name='togglemenu']").toggle(
		function () {
			if($(this).parents("li:last").children("ul").is("ul")){
				$(this).parents("li:last").children("ul").slideDown("fast");
			}else{
				var href=$(this).attr("href");
				document.location.href=href;
			};
		},
		function () {
			if($(this).parents("li:last").children("ul").is("ul")){
				$(this).parents("li:last").children("ul").slideUp("fast");
			}else{
				var href=$(this).attr("href");
				document.location.href=href;
			};
		}
	);
});

jQuery(document).ready(function(){
	$img = '<img src="/bitrix/templates/main/images/ajax-loader.gif" width="16" height="16" />';
	
	

	
	
	jQuery('#city').change(function(){
		jQuery('#vacancy').html(' ');
		jQuery('#vacancy').append($img);
		//alert('1');
		jQuery.ajax({
			async: false,
			url: "/ajax/add_vacancy.php",
			data: ({
				city_id: jQuery(this).attr('value'),
				special_id: jQuery('#special').attr('value'),
			}),
			type: 'POST',
			dataType: 'html',
			success: function(msg){
				jQuery('#vacancy').find('img').remove();
				jQuery('#vacancy').html(msg);
				jQuery('.text a').click(add_vacancy);
				jQuery('.text a').click(function(){return false;});
			}
		});
	});
	jQuery('#special').change(function(){
		jQuery('#vacancy').html(' ');
		jQuery('#vacancy').append($img);
		jQuery.ajax({
			async: false,
			url: "/ajax/add_vacancy.php",
			data: ({
				city_id: jQuery('#city').attr('value'),
				special_id: jQuery(this).attr('value'),
			}),
			type: 'POST',
			dataType: 'html',
			success: function(msg){
				jQuery('#vacancy').find('img').remove();
				jQuery('#vacancy').html(msg);
				jQuery('.text a').click(add_vacancy);
				jQuery('.text a').click(function(){return false;});
			}
		});
	});
	
	var add_vacancy = function(){
		var href = jQuery(this).attr("href");
		var params = href.split('/ajax/add_vacancy.php?');
		var city = jQuery('#city').attr('value');
		var special = jQuery('#special').attr('value');
		var get_info = params[1]+'&city_id='+city+'&special_id='+special;
		jQuery('#vacancy').html(' ');
		jQuery('#vacancy').append($img);
		jQuery.ajax({
			async: false,
			url: "/ajax/add_vacancy.php",
			data: get_info,
			type: 'get',
			dataType: 'html',
			success: function(msg){
				jQuery('#vacancy').find('img').remove();
				jQuery('#vacancy').html(msg);

				jQuery('.text a').click(add_vacancy);
				jQuery('.text a').click(function(){return false;});
			}
		});
	}
	jQuery(document).ready(function(){
		if(jQuery('.map').length > 0){
			jQuery(this).find('div:last-child').addClass('last');
			jQuery('.map .submap').each(function(){
				//alert('1');
				jQuery(this).find('div:last-child').addClass('last');
			});
		}
	});
});
