var check=1;
$(document).ready(function() {
	$(function(){
	  $("ul.gallery a").lightBox({
		overlayBgColor: '#363',
		txtImage: 'Фото',
		txtOf: 'из',
		txtPrev: '&nbsp;Назад',
		txtNext: '&nbsp;Вперед',
		keyToClose: 'q',
		keyToPrev: 'z',
		keyToNext: 'c'
	  });
	});
	$(function() {//http://keith-wood.name/datepick.html
		$('#popupDatepicker').datepick({
			rangeSelect: true,
			minDate: $.datepick.today(), 
			maxDate: '+6m'
		});
	});
	$('.lightBox a').lightBox();
	$("a.group").fancybox({
		'hideOnContentClick': true,
		'frameWidth': 450,
		'frameHeight': 450,
		'zoomSpeedIn': 200,
		'zoomSpeedOut': 300,
		'overlayShow': false 
	});
	
	$("#comment").bind("submit", function() {
		var dd = $(this).serializeArray();
		$.ajax({
			type		: "POST",
			cache		: false,
			url			: "/includes/_comment.php",
			data		: $(this).serializeArray(),
			complete: function(data,msg) {
				$('#comm_msg').html('Ваш комментарий отправлен');
			},
			success: function(data) {
				$.get('/includes/_comment.php', { out_comm: data },
					function(data1){
						$('#comment_out').append(data1);
				});
			}
		});
		return false;
	});
	$(".fpass").bind("submit", function() {
		var dd = $(this).serializeArray();
		$.ajax({
			type		: "POST",
			cache		: false,
			url			: "/includes/_pass.php",
			data		: $(this).serializeArray(),
			complete: function(data,msg) {
				//$('.pass').html('Ваш комментарий отправлен');
			},
			success: function(data) {
				if (data!=0) $('.pass').html(data);
				else $('.pass').append('<font color="red">Ошибка при вводе пароля!</font>');
			}
		});
		return false;
	});
	
	$('#comment_shw').click(function(){
		$('#comment_out').toggle('slow');
		$('#comment_add').toggle('slow');
		if(check==1){
			$(this).attr('src','/templates/mgtu/images/bullet_arrow_down.png');
			check=0;
		} else {
			$(this).attr('src','/templates/mgtu/images/bullet_arrow_up.png');
			check=1;
		}
	});
	$('.comm_but_0').click(function(){
		var tmp = $(this).attr('id').split('|');
		//alert( $(this).attr('id')+'='+tmp[0]+'-'+tmp[1] );
		$(this).toggle('slow');
		$.ajax({
			type: 'POST',
			url: '/includes/_comment.php',
			data: 'rt&id='+tmp[0]+'&dd='+tmp[1]+'',
			success: function(msg){
				//alert( "Data Saved: " + msg );
				var tmp1 = msg.split('|');
				$('#'+tmp[0]+'').html(tmp1[1]);
				if (tmp1[0]<0) $('#'+tmp[0]+'').closest('.comm_id').removeClass('comm_id').addClass('comm_id_min');
				else $('#'+tmp[0]+'').closest('.comm_id_min').removeClass('comm_id_min').addClass('comm_id');
			}
		});
	});
});
