(function($){
$(function()
{
	$('#em_form').addClass('hide_label');
	var label = $('#em_form label').text();
	$('#em_form #i_subscribe_email').
		val(label).
		live('focus', function(){
			if (label == $(this).val())
			{
				$(this).val('');
			}
		}).
		live('blur', function(){
			if ('' == $(this).val())
			{
				$(this).val(label);
			}
		});
	
	$('#em_form form').live('submit', function(){
		$(this).ajaxSubmit(function(data){
			$('#em_form').html(data);
		});
		return false;
	});
	
	// submenu
	function show_submenu()
	{
		$(this).addClass('hover');
		var $first_ul = $('ul', $(this)).first();
		if ($first_ul.innerWidth() > 300)
		{
			$first_ul.addClass('max_width');
		}	
		$('ul', $(this)).first().show();
	}
	function hide_submenu()
	{
		$(this).removeClass('hover');
		$('ul', $(this)).first().hide();
	}
	$('#menu li:has(ul)').hoverIntent({
		interval: 150,
		over: show_submenu,
		timeout: 500,
		out: hide_submenu
	});
	// \submenu
	
	$('#show_gram').click(function(){
		$('#it_text').removeClass('not_show_bold');
		$('#centercol').addClass('show_gram');
		return false;
	});
	
	$('#show_trans').click(function(){
		$('#centercol').removeClass('show_gram');
		return false;
	});
	
	// search
	var search_default_word = 'Поиск';
	$('#search_keywords')
		.focus(function(){
			if (search_default_word == $(this).val())
			{
				$(this).val('');
			}})
		.keyup(function(key){
			if (($(this).val() == '') || ($(this).val().length <= 3))
			{
				$('#search_result').hide().empty();
			}
			else
			{
				var url = $(this).parent().attr('action');
				var q = $(this).val();
				$('#ajax-loader').show();
				$('#search_result').load(url, {query: q}, function(){
					$(this).show();
					$('#ajax-loader').hide();
				});
			}
	});
	$('body').bind('click', function(event){
		if ($(event.target).parent().attr('id') != 'search_result')
		{
			$('#search_result').hide().empty();
		}
	});
	// \search
	
	$('strong.l2').toggle(
		function(){
			$(this).nextAll('ul').slideDown();
		},
		function() {
			$(this).nextAll('ul').slideUp();
		 }
	).nextAll('ul').hide();

	
});
})(jQuery);