function publications_J(data)
{
	if (data.length > 0)
		$(".junior img").attr("src", data);
}
function publications_S(data)
{
	if (data.length > 0)
		$(".senior img").attr("src", data);
}
function calendar(data)
{
	$(".calendar").empty().append(data);
	$(".cal-year .prev").unbind("click").click(function(){$.post('/system/modules/ajax/calendar.php',{year: $(".cal-year div ul li").text() * 1 - 1, month: $(".cal-month div ul li").attr("value") * 1, uri: $(".lang").text()},calendar);})
	$(".cal-year .next").unbind("click").click(function(){$.post('/system/modules/ajax/calendar.php',{year: $(".cal-year div ul li").text() * 1 + 1, month: $(".cal-month div ul li").attr("value") * 1, uri: $(".lang").text()},calendar);})
	$(".cal-mons .prev").unbind("click").click(function(){$.post('/system/modules/ajax/calendar.php',{year: $(".cal-year div ul li").text() * 1, month: $(".cal-mons div ul li").attr("value") * 1 - 1, uri: $(".lang").text()},calendar);})
	$(".cal-mons .next").unbind("click").click(function(){$.post('/system/modules/ajax/calendar.php',{year: $(".cal-year div ul li").text() * 1, month: $(".cal-mons div ul li").attr("value") * 1 + 1, uri: $(".lang").text()},calendar);})
}
function actcalendar(data)
{
	$(".calendar").empty().append(data);
	$(".act-cal-year .prev").unbind("click").click(function(){var ac_check = ac_func(); ac_check["year"] = $(".act-cal-year div ul li").text() * 1 - 1; ac_check["month"] = $(".act-cal-mons div ul li").attr("value") * 1 ; $.post('/system/modules/ajax/activity.php', ac_check, actcalendar);})
	$(".act-cal-year .next").unbind("click").click(function(){var ac_check = ac_func(); ac_check["year"] = $(".act-cal-year div ul li").text() * 1 + 1; ac_check["month"] = $(".act-cal-mons div ul li").attr("value") * 1; $.post('/system/modules/ajax/activity.php', ac_check, actcalendar);})
	$(".act-cal-mons .prev").unbind("click").click(function(){var ac_check = ac_func(); ac_check["year"] = $(".act-cal-year div ul li").text() * 1; ac_check["month"] = $(".act-cal-mons div ul li").attr("value") * 1 - 1; $.post('/system/modules/ajax/activity.php', ac_check, actcalendar);})
	$(".act-cal-mons .next").unbind("click").click(function(){var ac_check = ac_func(); ac_check["year"] = $(".act-cal-year div ul li").text() * 1; ac_check["month"] = $(".act-cal-mons div ul li").attr("value") * 1 + 1; $.post('/system/modules/ajax/activity.php', ac_check, actcalendar);})
	$(".act-cal-day a").unbind("click").click(function(event){
		event.preventDefault();
		var ac_check = ac_func();
		ac_check["date"] =  $(this).attr("rel");
		$.post(
				'/system/modules/ajax/list.activity.php',
				ac_check,
				list_activity
			);
	})
	if ($(".lang").text() == "index")
		$(".square-type").hide();
}
function ac_func()
{
	var ac = new Object;
	$(".events ul input").map(function(i){
		if ($(this).attr("checked") == true)
			ac[i] = $(this).val();
	})
	ac["year"] = $(".act-cal-year div ul li").text();
	ac["month"] = $(".act-cal-mons div ul li").attr("value");
	return ac;
}
function list_activity(data)
{
	$(".event-list").empty().append(data);
}
function activity(data)
{
	$(".calendar").empty().append(data);
	$(".act-cal-year .prev").unbind("click").click(function(){var ac_check = ac_func(); ac_check["year"] = $(".act-cal-year div ul li").text() * 1 - 1; ac_check["month"] = $(".act-cal-mons div ul li").attr("value") * 1 ; $.post('/system/modules/ajax/activity.php', ac_check, actcalendar);})
	$(".act-cal-year .next").unbind("click").click(function(){var ac_check = ac_func(); ac_check["year"] = $(".act-cal-year div ul li").text() * 1 + 1; ac_check["month"] = $(".act-cal-mons div ul li").attr("value") * 1; $.post('/system/modules/ajax/activity.php', ac_check, actcalendar);})
	$(".act-cal-mons .prev").unbind("click").click(function(){var ac_check = ac_func(); ac_check["year"] = $(".act-cal-year div ul li").text() * 1; ac_check["month"] = $(".act-cal-mons div ul li").attr("value") * 1 - 1; $.post('/system/modules/ajax/activity.php', ac_check, actcalendar);})
	$(".act-cal-mons .next").unbind("click").click(function(){var ac_check = ac_func(); ac_check["year"] = $(".act-cal-year div ul li").text() * 1; ac_check["month"] = $(".act-cal-mons div ul li").attr("value") * 1 + 1; $.post('/system/modules/ajax/activity.php', ac_check, actcalendar);})
	$(".act-cal-day a").unbind("click").click(function(event){
		event.preventDefault();
		var ac_check = ac_func();
		ac_check["date"] =  $(this).attr("rel");
		$.post(
				'/system/modules/ajax/list.activity.php',
				ac_check,
				list_activity
			);
	})
}
function post_opinion(from)
{
	$.post(
			'/system/modules/ajax/opinion.php',
			{from: from},
			opinion
		);
}
function opinion(data)
{
	$(".verdict-t").empty().append(data);
	$(".verdict-t img").map(function(){
		if ($(this).width() > $(this).height())
			$(this).css("width", "100px");
		else
			$(this).css("height", "100px");
	})
}

function checkmail(email) {
	return (/^([a-z0-9_\-]+\.)*[a-z0-9_\-]+@([a-z0-9][a-z0-9\-]*[a-z0-9]\.)+[a-z]{2,4}$/i).test(email);
}

$(function() {
	// Форма FAQ
	$(".connect .button").click(function(){
		if (!checkmail($(".connect input[name='mail']").val()))
		{
			alert("Неверно введен E-mail!");
			return false;
		}
		if(!$(".connect input[name='name']").val() || !$(".connect textarea").val()){
			alert("Не заполнено одно из обязательных полей");
			return false;
		}
		$.post(
			'/system/modules/ajax/faq.php',
			{
				name: $(".connect input[name='name']").val(),
				mail: $(".connect input[name='mail']").val(),
				text: $(".connect textarea").val(),
				page: $(".connect input[name='page']").val(),
				captcha: true
			},
			function(data){
				alert(data);
			}
		);
	})
	
	$(".nav > table td a").map(function(){
		if ($(this).text() == "Форум")
			$(this).attr("target", "_blank");
	})
	
	
	// Календарь
	$(".cal-year .prev").click(function(){$.post('/system/modules/ajax/calendar.php',{year: $(".cal-year div ul li").text() * 1 - 1, month: $(".cal-month div ul li").attr("value") * 1, uri: $(".lang").text()},calendar);})
	$(".cal-year .next").click(function(){$.post('/system/modules/ajax/calendar.php',{year: $(".cal-year div ul li").text() * 1 + 1, month: $(".cal-month div ul li").attr("value") * 1, uri: $(".lang").text()},calendar);})
	$(".cal-mons .prev").click(function(){$.post('/system/modules/ajax/calendar.php',{year: $(".cal-year div ul li").text() * 1, month: $(".cal-mons div ul li").attr("value") * 1 - 1, uri: $(".lang").text()},calendar);})
	$(".cal-mons .next").click(function(){$.post('/system/modules/ajax/calendar.php',{year: $(".cal-year div ul li").text() * 1, month: $(".cal-mons div ul li").attr("value") * 1 + 1, uri: $(".lang").text()},calendar);})
	
	// Фотогалерея	
	$(".big-photo .pic a").fancybox();
	$(".cont-foto a").fancybox();
	$(".list-photo .list").jCarouselLite({
		btnNext: ".list-photo .next",
		btnPrev: ".list-photo .prev",
		visible: 4,
		start:0,
		circular: false
	});
	var current_photo = 1;
	$(".info .navi div:eq(0)").jCarouselLite({
		btnNext: ".navi .next",
		btnPrev: ".navi .prev",
		start:0,
		visible:1,
		circular: false,
		afterEnd: function(a){
			$(".big-photo .pic img").attr("src", a.children("a").attr("href"));
			$(".big-photo .pic a").attr("href", a.children("a").attr("href"));
			$(".big-photo .pic a").unbind("fancybox").fancybox();
			$(".info .navi div:eq(1) b").empty().append($(".info .navi div:eq(0) ul li").index(a) + 1);
			$(".big-photo .info p").empty().append(a.children("a").children("img").attr("title"));
		}
	});
	$(".list-photo .list li").click(function(event){
		event.preventDefault();
		$(".big-photo .pic img").attr("src", $(this).children("a").attr("href"));
		$(".big-photo .pic a").attr("href", $(this).children("a").attr("href"));
		$(".big-photo .pic a").unbind("fancybox").fancybox();
		$(".info .navi div:eq(1) b").empty().append($(".list-photo .list li").index($(this)) + 1);
		$(".big-photo .info p").empty().append($(this).children("a").children("img").attr("title"));
		//$.post('/system/modules/ajax/photo.php',{album: $(".big-photo .pic img").attr("longdesc"), month: $(".cal-mons div ul li").attr("value") * 1 + 1, uri: $(".lang").text()},calendar);
	})
	
	// Календарь мероприятий
	$(".allcheck").change(function(){
		if ($(this).attr("checked") == true) $(".events ul input").attr("checked", true); else $(".events ul input").attr("checked", false);
		var ac_check = ac_func();
		$.post(
			'/system/modules/ajax/activity.php',
			ac_check,
			activity
		);
	})
	$(".events ul input").change(function(){
		var ac_check = ac_func();
		$.post(
			'/system/modules/ajax/activity.php',
			ac_check,
			activity
		);
	})
	$(".act-cal-year .prev").click(function(){var ac_check = ac_func(); ac_check["year"] = $(".act-cal-year div ul li").text() * 1 - 1; ac_check["month"] = $(".act-cal-mons div ul li").attr("value") * 1 ; $.post('/system/modules/ajax/activity.php', ac_check, actcalendar);})
	$(".act-cal-year .next").click(function(){var ac_check = ac_func(); ac_check["year"] = $(".act-cal-year div ul li").text() * 1 + 1; ac_check["month"] = $(".act-cal-mons div ul li").attr("value") * 1; $.post('/system/modules/ajax/activity.php', ac_check, actcalendar);})
	$(".act-cal-mons .prev").click(function(){var ac_check = ac_func(); ac_check["year"] = $(".act-cal-year div ul li").text() * 1; ac_check["month"] = $(".act-cal-mons div ul li").attr("value") * 1 - 1; $.post('/system/modules/ajax/activity.php', ac_check, actcalendar);})
	$(".act-cal-mons .next").click(function(){var ac_check = ac_func(); ac_check["year"] = $(".act-cal-year div ul li").text() * 1; ac_check["month"] = $(".act-cal-mons div ul li").attr("value") * 1 + 1; $.post('/system/modules/ajax/activity.php', ac_check, actcalendar);})
	$(".act-cal-day a").click(function(event){
		event.preventDefault();
		var ac_check = ac_func();
		ac_check["date"] =  $(this).attr("rel");
		$.post(
				'/system/modules/ajax/list.activity.php',
				ac_check,
				list_activity
			);
	})
	
	// Достижения школы
	$(".student a").fancybox();
	
	// Актуальные мнения на главной
	if ($(".verdict .list li").length > 1)
		$(".verdict .list li:first a").addClass("active");
	else
		$(".verdict .list").hide();
	var current_op = 0;
	$(".verdict-t img").map(function(){
		if ($(this).width() > $(this).height())
			$(this).css("width", "100px");
		else
			$(this).css("height", "100px");
	})
	$(".verdict .list li a").click(function(event){
		event.preventDefault();
		$(".verdict .list li a").removeClass("active");
		$(this).addClass("active");
		current_op = $(".verdict .list li").index($(this).parent());
		$(".verdict .list .prev").attr("rel", current_op * 1 - 1);
		$(".verdict .list .next").attr("rel", current_op * 1 + 1);
		post_opinion($(".verdict .list li:eq(" + current_op + ") a").attr("rel"));
	})
	$(".verdict .list .prev").click(function(event){
		event.preventDefault();
		if (current_op > 0)
		{
			current_op = current_op * 1 - 1;
			$(".verdict .list li a").removeClass("active");
			$(".verdict .list li:eq(" + current_op + ") a").addClass("active");
			$(".verdict .list .prev").attr("rel", current_op * 1 - 1);
			$(".verdict .list .next").attr("rel", current_op * 1 + 1);
			post_opinion($(".verdict .list li:eq(" + current_op + ") a").attr("rel"));
		}
	})
	$(".verdict .list .next").click(function(event){
		event.preventDefault();
		if (current_op < $(".verdict .list li").length)
		{
			current_op = current_op * 1 + 1;
			$(".verdict .list li a").removeClass("active");
			$(".verdict .list li:eq(" + current_op + ") a").addClass("active");
			$(".verdict .list .prev").attr("rel", current_op * 1 - 1);
			$(".verdict .list .next").attr("rel", current_op * 1 + 1);
			post_opinion($(".verdict .list li:eq(" + current_op + ") a").attr("rel"));
		}
	})
	
	// Публукации
	$(".junior img:first").show();
	$(".senior img:first").show();
	$(".junior a").mouseover(function(){
		$(".junior img").hide();
		$(".junior img[longsrc=" + $(this).attr("rel") + "]").show();
	})
	$(".senior a").mouseover(function(){
		$(".senior img").hide();
		$(".senior img[longsrc=" + $(this).attr("rel") + "]").show();
	})
	
	//Раскривушка на главной
	$(".readMore").click(function(){
		$(".texto").slideDown("fast");
		$(".readMore").css("display", "none");
		$(".hack").css("display", "block");
	});
	$(".closeMore").click(function(){
		$(".texto").slideUp("fast");
		$(".readMore").css("display", "block");
		$(".hack").css("display", "none");
	});
	$(".read-more").click(function(){
		$(".texto").css("display", "block");
	});
	$(".ttitle b").click(function(){
		$(".texto").css("display", "none");
	});

});
