﻿$(function(){
	// Фильт таблицы
	$('.filtertable').tableFilter({
		'selectOptionLabel': 'Все...',
		'filterDelay':0
	});
	$('#filter_0,#filter_3,#filter_4').hide();
	$('.filters').css('background','#eee')
	
	// Текст в строке поиска
	var sText = 'Поиск по сайту...';
	$('.stext').attr('value', sText);
	$('.stext').focus(function(){if ( $(this).attr('value') == sText ) {$(this).attr('value', '');}});
	$('.stext').blur(function() {if ( $(this).attr('value') == '') {$(this).attr('value', sText);}});
	
	// Бордюры в верхнем меню
	$('#top li:first').css('border', 'none');
	$('#top li:eq(1)').css('border-left', 'none');
	$('#top li:last').css('border-right', 'none');
	
	// Зебра для новостей
	$('.news:odd').addClass('odd');
	$('.zebratable').each(function(){
		$(this).find('tr:even td').css('background', '#e3eef5')
	})
	//$('.zebratable tr:even td').css('background', '#e3eef5')
	
	// Меню
	menu();
	$('.menu a').each(function(){
		var href = $(this).attr('href');
		var href_moderniz = "http://www.kamchatka.gov.ru/index.php?cont=oiv_din&menu=4&menu2=0&id=171&oiv_id=3640";
		if ( href.indexOf('obespDost') != -1)
			$(this).css({'color':'red'});
		if ( href.indexOf('fgos') != -1)
			$(this).css({'color':'red'});
		if ( href.indexOf('Moderniz') != -1)
			$(this).css({'color':'red'}).attr({'href':href_moderniz, 'target':'_blank'});


		if ( href.match(/extLink_/i) ) {
			href = href.match(/extLink_(.+)\//)[1];
			switch(href) {
				case 'contest': // Конкурсы профессионального мастерства
					href = 'http://www.kamipkpk.ru/activity/konk_profmasterstva/'
					break;
				case 'edu_contest':
					href = "http://www.kamchatka.gov.ru/index.php?cont=oiv_din&mcont=783&menu=4&menu2=0&id=171";
					break;
				case 'vospitanie':
					href = "http://www.kamchatka.gov.ru/index.php?cont=oiv_din&menu=4&menu2=0&id=171&oiv_id=729";
					break;
				case 'official':
					href = 'http://kamchatka.gov.ru/index.php?cont=oiv_din&menu=4&menu2=0&id=171';
					break;
			}
			$(this).attr({'href':href, 'target':'_blank'});
		}
	});
	
	
	// Помечаем ткущий раздел
	var part = window.location.href.replace(/http:\/\//, '').split(/\//).slice(1);
	$(".left ul > li > a[href^='/" + part[0] + "']:first").parent().addClass('cur');;
	if (part.length > 1 && !part[1].match(/aspx/) ) $(".left a[href^='/" + part[0] + '/' + part[1] + "']").addClass('subsel'); // главное меню, подразделы
	
	
	// Вопрос ответ
	$('.answer').hide();
	$('.question em').css({'cursor':'pointer', 'border-bottom':'1px dashed #000'});
	$('.question em').click(function(){
		$('.answer').slideUp();
		$('.answer').eq( $('.question em').index(this) ).slideDown();
	});
});

var block = false;
function menu(){
	$('.menu li ul').prepend('<div class="ptr"></div><li class="mt"><div class="mr"></div><div class="mc"></div></li>');
	$('.menu li ul').append('<li class="mb"><div class="ml"></div><div class="mr"></div><div class="mc"></div></li>');
	$('.menu li').addClass('root').find('li').removeClass('root');
	$('.menu li:last').css('border','none');
	
	$('.menu li.root').each(function(){
		$(this).find('li a:first').css({'border-top':'none', 'padding-top':'1px'});
		$(this).find('li a:last').css({'border-bottom':'none', 'padding-bottom':'5px'});
		$(this).mouseover(function(){
			$(this).addClass('sel');
			$(this).find('ul').show();
		});
		$(this).mouseout(function(){
			$(this).removeClass('sel');
			$(this).find('ul').hide();
		});
	});
}
