$.fn.important_input = function(text) {
	var elements = $(this);
	elements.addClass('important');
	elements.each(function(){
		if (!text) {
			text = 'Empty!!!'; }
			
		element = $(this);
		form = element.parents("form");
		
		if (!form.hasClass('important_input_replaced')) {
			submit = form.find("input[type='submit'], button[type='submit']");
			inputs = form.find("input.important, textarea.important").not("input[type='radio']");
			
			form.submit(function(){
				all_ok = true;
				form = $(this);
				inputs = form.find("input.important, textarea.important").not("input[type='radio']");
				for (i = 0; i < inputs.size(); i++) {
					if ((!inputs[i].value)||(inputs[i].value == text)) {
						all_ok = false;
						input = $(inputs[i]);
						inputs[i].value = text;
						input.addClass('alert_message');
					}
				}

				inputs.click(function(){
					input = $(this);
					if ((!input[0].value)||(input[0].value == text)) {
						cantainer = $(".ballon_message_container");
						input[0].value = '';
						input.removeClass('alert_message');
					}
				});

				if (!all_ok) {
					return false;}
			
			});
		
			form.addClass('important_input_replaced');
		}
	});
}
	
$(document).ready(function() {

	//$(document).pngFix();
	
	$("label").each(function(){
		label = $(this);
		//alert(label.text());
		if (label.text().search(/\*/) >= 0) {
			//alert("input#"+label.attr('for')+", textarea#"+label.attr('for'));
			input = $("input#"+label.attr('for')+", textarea#"+label.attr('for')).important_input("Это поле обязательно для заполнения!");
		}
	});
	
	$("#main_menu li").addClass('main_menu_item');
	$(".submenu li").removeClass('main_menu_item');
	$("#main_menu li.main_menu_item").css({'height':'20px'});
	$(".submenu").not("a").css({'background':'#000000', 'opacity':'0.65'});
	
	active_items = $("#main_menu li.main_menu_item.hover_now");
	passive_items = $("#main_menu li.main_menu_item").not(".hover_now");
	
	$("#main_menu li.main_menu_item").hover(function(){
			$(this).stop().animate({'height':'160px'})/*.find(".submenu").animate({'opacity':'0.5'})*/;
		},									function(){
			$(this).stop().animate({'height':'20px'})/*.find(".submenu").animate({'opacity':'0'})*/;
		}
	);
	
	$(".submenu li a").hover(function(){
			$(this).css({'backgroundColor':'black','opacity':'1'});},
							function(){
			$(this).removeAttr('style');}
	);
	
	$("#main_menu li.main_menu_item").click(function(){
		$(this).stop();
		return true;
	});
/*	
	$(".page_menu li a").each(function(){
		var button = $(this);
		var container = button.parents("li");
		if (submenu = container.find("ul")) {
			submenu.hide();
			button.click(function(){
				var button = $(this);
				var submenu = button.parent("li").children("ul");
				submenu.slideToggle('fast');
				
				return false;
			});
		}
	});*/
	
	
	
	$(".page_menu li ul").hide();
	
	$(".page_menu li a").each(function(){
		var button = $(this);
		var container = button.parents("li");
		if (button.attr('href') == '#') {
			button.click(function(){
				var button = $(this);
				var active_ul = button.next("ul");
				active_ul.toggle();
				$(".page_menu li ul").hide();
				button_tree = button.parents("ul").add(active_ul).show();
				
				return false;
			});
		}
	});
	
	$(".page_menu li a").each(function(){
		button = $(this);
		if ((document.location.href.search(button.attr('href')) > -1)&&(button.attr('href') != '/')) {
			button.parent("li").addClass('active');}
	});
	
	$(".page_menu li").children("ul").each(function(){
		submenu = $(this);
		container = submenu.parent("li");
	//	alert(container.children("a").attr('href'));
		if ((container.hasClass('active'))||(container.find('.active').size())) {
			submenu.show();}
	});
	
	$("#map1, #map2").each(function(){
		var map_conainer = $(this);
		var map = map_conainer.find("img");
		var map_href = $("<a href='"+map.attr('src')+"' target='_blank'>Посмотреть карту</a>");
		map_href.insertBefore(map);
		map_href.click(function(){
			var container = $(this).parent("p");
			var map = container.find("img");
			map.slideToggle();
			return false;
		});
		map.hide();
	});
	
	$(".print_me").each(function(){
		map = $("img");
		$("a").hide();
		map.show();
		map.load(function(){
			window.print();
			history.back();
		});
	});
	
});































