$(document).ready(function(){

	$('.main-content img').css({'border-radius':'6px'})
	$('.main-content p img').css({'border':'1px solid #5481AE'})

	var textQuote = $('blockquote').html()
	$('blockquote').html('')
	$('blockquote').addClass('fright')
	$('blockquote').append('<div><div><div><div>'+textQuote+'</div></div></div></div>')

	//Переключатель языка сайта
	var curLang = $('#langSelector .styled option:selected')
	$('#langSelector .styled').change(function(){	
		var selectLang = $(this).children('option:selected').val()
		if( selectLang != curLang)
			window.location.href = selectLang
	})

	//Главное меню
	$('ul.mainNav li').hover(function(){
		$(this).toggleClass('hover');
	});	
	
	//Слайдер минигалереи
	$('#cSliderWrapper').slides({
		preload: true,
		preloadImage: '/i/loading.gif',
		effect: 'fade',
		hoverPause: true,				
		crossfade: false,			
		fadeSpeed: 1200,
		play:5000,
		pause:5000,
		pagination: true,
		generateNextPrev: false,
		generatePagination: false
	});	

	//Расположение пагинации слайдера на главной странице
	var arChildrenWidth = $('#slider ul.pagination').children('li').css('width');
	var arChildrenPL = $('#slider ul.pagination').children('li').css('paddingLeft');
	var arChildrenPR = $('#slider ul.pagination').children('li').css('paddingRight');
	var arSize = $('#slider ul.pagination li').size();
	if(arChildrenPL){arChildrenPL = parseFloat(arChildrenPL.replace('px',''));}		
	if(arChildrenPR){arChildrenPR = parseFloat(arChildrenPR.replace('px',''));}
	if(arChildrenWidth){arChildrenWidth = parseFloat(arChildrenWidth.replace('px',''));}		
	var ulWidth = ((arChildrenPR + arChildrenPL + arChildrenWidth)*arSize + 2);
	$('#slider ul.pagination').css('width', ulWidth);

	//Форма обратной связи
	$('.feedbackShow').click(function(){	
		$.post('/feedback/add_feedback.html', { 'action' : 'getForm' }, function(data){	
			$('.feedbackWrapp .fbForm').html(data)	
		});		
		button = $(this)		
		if($('.feedbackLayout').css('display') == 'none'){
			$('.feedbackLayout').show(500, function(){ button.addClass('active') } );
		} else {
			$('.feedbackLayout').hide(500, function(){ button.removeClass('active') } );
		}
		$('.close').click(function(){
			$('.feedbackLayout').hide( 500, function(){ $('.feedbackShow').removeClass('active') } );
		});
	});
		
	//Fancybox для конструкций типа <a> <img/> </a>
	$('a[href$=\'jpg\']').fancybox();
	$('a[href$=\'gif\']').fancybox();
	$('a[href$=\'png\']').fancybox();

	//Fancybox для минигалереи
	$("a[rel=fancyBox]").fancybox()

	//Карусель для минигалереи
	$('#mycarousel').jcarousel({  	
		scroll: 1
    });
	
	//Левое меню
	$('.leftModuleMenu li').hover(function(){
		$(this).toggleClass('hover');
	});
	
	//Карта сайта
	$('ul.siteMapList li').hover(function(){
		$(this).toggleClass('hover');
	});
	
	//Архив новостей по годам и месяцам
	var regexp = /^\/news\/$/i;
	path = regexp.exec(window.location.pathname);
	if(path != null){	
		$('.yearItem:first-child .yearHead').next('div').show();
		$('.yearItem:first-child .yearHead').addClass('active');	
	}
	$('.yearItem.open .monthWrapper').show();
	$('.yearItem.open .yearHead').addClass('active');
	$('.yearItem .yearHead').click(function(){
		$('.yearItem .yearHead').next('div').slideUp('slow');
		$('.yearItem .yearHead').removeClass('active');
		if($(this).next('div').css('display') == 'none'){
			$(this).addClass('active');
			$(this).next('div').slideDown('slow', function(){ });
		} else {
			$(this).removeClass('active');
			$(this).next('div').slideUp('slow', function(){	});
		}			
	});
	
	//Дерево каталога
	/*$('.leftSidebarWrapper .tree .leftModuleMenu .c-block-inner ul li a').click(function(){
		if($(this).next('ul').length == 0)
			location.href = $(this).attr('href')
		else
			$(this).parent('li').toggleClass('close')
		return false
	})*/

	//Accordion разделов каталога
	$('.catElementList a').click(function(){
		window.location.href($(this).attr('href'))
	})
	$('.catRubricList a').toggle(function(){			
		$(this).next('ul').slideDown(300)
		return false
	}, function(){
		$(this).next('ul').slideUp(300)
		return false
	});	

	//Контакты
	$('.sBottom').hide();
	$('.sTop .toggleThis').click(function(){
		$(this).toggleClass('active');
		$('.sBottom').slideUp('1250');
		sTop = $(this).parent().parent('.sTop');
		sBottom = $(sTop).next();
		if($(sBottom).css('display') == 'none'){
			$(sBottom).slideDown('1250');
		} else {
			$(sBottom).slideUp('1250');
		}
	});
	$('.cSubRow').hover(function(){			
		$(this).children('.sTop').children('.cSubRow-check').children('input').attr('checked','checked');
		$(this).children('.sTop').children('.cSubRow-check').children('span').css('background-position','0 -28px');
		$(this).children('.sTop').children('.cSubRow-my').children('input').css('display','inline');
	}, function(){			
		$(this).children('.sTop').children('.cSubRow-check').children('input').attr('checked','');
		$(this).children('.sTop').children('.cSubRow-check').children('span').css('background-position','0 0');
		$(this).children('.sTop').children('.cSubRow-my').children('input').css('display','none');
	});	
	
	//Растягиваем правый блок по высоте левого
	if($('.leftSidebarWrapper').height() > $('.contentOuter').height()){
		$('.contentOuter .contentInner .c-block-inner.main-content').css('min-height', $('.leftSidebarWrapper').height() - $('.contentOuter .pathway').height() - $('.contentOuter .mainTitle').height() - 59)
	}
	$(function(){	
		$('div.aboutItem .c-block-inner a').append('<div class="transpLayer"></div>');
		$('div.aboutItem').hover(function(){
			$(this).find('.transpLayer').fadeTo('1200','1');
		}, function(){
			$(this).find('.transpLayer').fadeTo('1200','0');
		});		
	});
	$(function(){
		$('div.contentInner table tr:odd').addClass('odd');
		$('div.contentInner table tr:even').addClass('even');
	});
	
	$('div.vacancies h4').toggle(function(){
	
		$(this).next('div').slideDown()
	
	}, function(){
	
		$(this).next('div').slideUp()
	
	})
	
});
