(function($) {

	$(document).ready(function() {
		
		// clear Четвертого пункта меню в типе Раздел. и одинаковая высота
		/*var height_link = 0;
		$('#subpage a').each(function(i){
			if(i%3 == 0) $(this).addClass('new_line');
			if(height_link < $(this).height()){
				height_link = $(this).height();
			}
		});
		$('#subpage a').height(height_link);*/
		
		var postop=0;
		$('#SecondMenu > li > div.fon').each(function(i) {
			$(this).css('background-position','0 -'+postop+'px');
			postop += $(this).height();
		});
		
		
		var height_section = 0;
		$('.sections_list h2').each(function(i){
			if(height_section < $(this).height()){
				height_section = $(this).height();
			}
		});
		$('.sections_list h2').height(height_section);
		
		$('.sections_list .text_part p:last').css('margin-bottom','0');
		
		
		if ($('#second_menu_area ul li').length==0) {
			$('#second_menu_area .bottom').css('top','0');
		}
		
		if ($('.searchblock').offset.top != $('#MainMenu .sub_menu.deep_2').offset.top) {
			$('.searchblock').css('display','none');
		}
		
		// высота галереи
		var height_gal = 40;
		$('.gallery li').each(function(i){
			//alert($(this).find('a').height());
			//if(i%3 == 0) $(this).addClass('new_line');
			if(height_gal < $(this).find('a').height()){
				height_gal = $(this).find('a').height();
			}
		});
		$('.gallery li a').height(height_gal);
		
		
		var height_gal = 30;
		$('#subpage a').each(function(i){
			if ( (i+1) % 3 == 0 )
				$(this).css('margin-right','0');
			
			if(height_gal < $(this).find('div').height()){
				height_gal = $(this).find('div').height();
			}
		});
		$('#subpage a').height(height_gal);
		$('#subpage a div').height(height_gal);
		$('#subpage a').each(function(i){
			var span_h = $(this).find('span').outerHeight();
			$(this).find('span').css('margin-top', (height_gal-span_h)/2 );
		});
		
		var o = $('#Workspace div#title_page');
		o.find('h1').css('padding-top', (o.height() - o.find('h1').height()) / 2 );
		
		$('.table_style th').each(function() {
			var html = $(this).html();
			var reg = / /;
			if ( /<p[^>]*>/g.test(html) == false ) {
				html  = '<p>'+html+'</p>';
			}
			$(this).html( '<div class="arc"></div>'+html );
			var arc = $(this).find('.arc');
			var p = $(this).find('p');
			
			if ( p.height() > arc.height() ) {
				arc.height(p.height());
			} else {
				if (p.height()>0) {
					p.css('padding-top', (arc.height() - p.height() - 2)/2 );
					p.css({ 'float':'left', 'width': ($(this).width()-arc.width()-8)  });
				}
			}
		});
		$('.table_style tr').each(function() {
			$(this).find('td:first').addClass('first');
		});
		
		
		/* Убираем стрелочки у путых элементов меню */
		$('ul#SecondMenu li.item').each(function(i){
			if($(this).find('.sub_menu').length == 0) {
				$(this).find('a.link').addClass('without_arrow');
			}
		});
		/* Убираем стрелочки у путых элементов меню - END */
		
	});
	
	gotoPage = function(self, page) {
		$('.lifestyle .nav_block a').removeClass('active');
		self.addClass('active');
		
		var row_num1 = page;
		var row_num2 = page+1;
		
		$('.lifestyle .sections_list tr').css('display','none');
		$('.lifestyle .sections_list tr#lifestyle_row'+row_num1).css('display','table-row');
		$('.lifestyle .sections_list tr#lifestyle_row'+row_num2).css('display','table-row');
	}
	
})(jQuery);
