	var link_url;
	var foto_load = 0;
	var base_url = 'http://'+location.host;
	
$(document).ready(function(){
	var comment_sending = 0;

	$(".commetn_box_link").live("click",function(){
	$("#commentbox").slideToggle("fast");
	$("#comment_body").focus();
 return false;
	});
	
	$(".comment_page_link").live("click",function(event){
	event.preventDefault();	
	$('#loading').show();
		 $.ajax({
	             url: this.href,             
	             dataType : 'html',               
	             success: function(data){
		         $('#comments').html(data);
				 $('#loading').hide();
		         }  
	});
 return false;
	}); 
	
	
	var comtab;
	get_Rtabcomment();
	
	function get_Rtabcomment(){
		clearInterval(comtab);
		$.ajax({
	             url: base_url+'/Rtabcomment.php',             
	             dataType : 'html',               
	             success: function(data){
				 $("#Rtabcomment").slideUp('slow', function() { $("#Rtabcomment").html(data);  $("#Rtabcomment").slideDown('slow'); });
				 comtab = setInterval(get_Rtabcomment, 30000);
		         }
	             }); 
	}
	
	$("#Rtabcomment").live("mouseover mouseout",function(ev){
	
	if (ev.type == 'mouseover') {
		clearInterval(comtab);
		$("#Rtabcomment").slideDown();
     }

    if (ev.type == 'mouseout') {
		clearInterval(comtab);
       comtab = setInterval(get_Rtabcomment, 30000);
    }
	});
	
	$(".comment_delete").live("click",function(event){
	event.preventDefault();	
	link_url = this.href;
    $(this).parents(".comment_txt").animate({ opacity: "hide" }, 1000, "", get_comment);								             
    return false;
    }); 
	
	$(".bonch_foto").live("click",function(e){
	e.preventDefault();
	var img_id = $(this).attr('rel');
	link_url = base_url+'/comment_ajax.php?commode=fotos&stena_id='+img_id;
	if(foto_load == 0){
	foto_load = 1;	
	$.ajax({
	             url: base_url+'/bonch_foto_ajax.php?mode=media&media_id='+img_id,             
	             dataType : 'html',               
	             success: function(data){
		         $('#media_foto_box').html(data);
				 get_comment();	
		         }
	             });  	
	}
    }); 
	
	
	$(".bonch_tagfoto").live("click",function(e){
	e.preventDefault();
	var img_id = $(this).attr('rel');
	var uid = $(this).attr('user_id');
	link_url = base_url+'/comment_ajax.php?commode=fotos&stena_id='+img_id;
	if(foto_load == 0){
	foto_load = 1;	
	$.ajax({
	             url: base_url+'/tag_foto_ajax.php?mode=media&media_id='+img_id+'&user_id='+uid,             
	             dataType : 'html',               
	             success: function(data){
		         $('#media_foto_box').html(data);
				 get_comment();	
		         }
	             });  	
	}
    }); 
	
	
	 function get_comment(){
		 $('#loading').show();
	 $.ajax({
	             url: link_url,             
	             dataType : 'html',               
	             success: function(data){
		         $('#comments').html(data);
				 $('#loading').hide();
				 foto_load = 0;	
				 if(stopcheck) stopcheck = 0; 
		         }
	             });  
	     link_url = '';	
	 }


function comment_valid() {
	var form_url = $("#comment_form").attr('action');
	var qString = $("#comment_form").formSerialize();
	if ($('#comment_body').val() == '') { 
	$("#comment_submit").disabled = true;
	$('#comment_error').html('Вы не написали текст сообщения!');
	$("#comment_error").show();
	return false;
	}
	if(comment_sending == 0){
    comment_sending = 1;
	$("comment_body").blur();
	$.ajax({
	             url: form_url,  
				 type: "POST",   
				 data: qString,        
	             dataType : 'html',               
	             success: function(data){
				 $("#comments").html(data);
				 if(stopcheck) stopcheck = 0; 
				 comment_sending = 0;
				 //get_comment();
				 $("#comment_submit").disabled = false;
		         }  
	});
	}
    return false;	
}

$("#comment_form").live("submit",function(event){
	event.preventDefault();	
	comment_valid();
    return false;
	}); 
	
	 $('#user_avatar_form').ajaxForm({target:'#user_avatar', success: function(){$('#user_avatar_msg').show(); $('#user_avatar_msg').fadeOut(3000);}, resetForm: true});
	 $('#change_psw').ajaxForm({target:'#change_psw_msg', success: function(){$('#change_psw_msg').show(); $('#change_psw_msg').fadeOut(3000);}, resetForm: true});
	 $('#edit_foto_nik').ajaxForm({target:'#edit_foto_nik_msg', success: function(){$('#edit_foto_nik_msg').show(); $('#edit_foto_nik_msg').fadeOut(3000);}, resetForm: false});
	 $('#change_info_form').ajaxForm({target:'#change_info_msg', beforeSubmit: validate, success: function(){$('#change_info_msg').show(); $('#change_info_msg').fadeOut(3000);}, resetForm: false});
	 $('#confim_reg').ajaxForm({beforeSubmit: validate, success: function() { window.location.href='index.php'; } });
	 function validate(formData, jqForm, options) {
		 var form = jqForm[0];
		 if (!form.user_fname.value) { $('div.user_fname_msg').show(); $('div.user_fname_msg').fadeOut(3000); return false; }
		 if (!form.user_lname.value) { $('div.user_lname_msg').show(); $('div.user_lname_msg').fadeOut(3000); return false; }
	 }
	 
	 $("#bonch_user").click(function(){
		 if($(this).attr("checked") == true){
			 $('#bocnh_box').show();
			 $('#university').val('СПбГУТ им. проф. М.А. Бонч-Бруевича');
		 } else {
			  $('#university').val('');
			  $('#bocnh_box').hide();			 
		 }
	 });
	 
	 
	 
	 $(".btn-slide").live("click",function(){
		 $("#panel").slideToggle("fast");
		 return false;
	});
	
	$(".rate").live("click", function(event){
	event.preventDefault();	
		$.ajax({
	    url: this.href,             
	    dataType : "html",               
	    success: function(data){
		$('#rating').html(data);
		$("#panel").slideToggle("fast");
		}
	});
	return false;
	});
	
	$(".tag_link").live("click",function(event){
	event.preventDefault();	
		$.ajax({
	    url: this.href,             
	    dataType : "html",               
	    success: function(data){
			$('#tags_user').html(data);
		}
	});
   return false;
	}); 
	
	$(".link_message_history").click(function(event){
	event.preventDefault();	
	$('#hist_link').hide();
		$.ajax({
	    url: this.href,             
	    dataType : "html",               
	    success: function(data){
		$('#message_history').html(data);
		}
	});
 return false;
	}); 
	
	$(".h_msg_delete").live("click",function(event){
	event.preventDefault();	
		$.ajax({
	    url: this.href,             
	    dataType : "html",               
	    success: function(data){
		$('#message_history').html(data);
		}
	});
 return false;
	}); 
	
	$(".status_edit").live("click",function(event){
	event.preventDefault();	
	$('#status_box').hide();
	$('#status_form').show();	
    return false;
	}); 
	
	$("#status_cansel").live("click",function(event){
	event.preventDefault();	
	$('#status_box').show();
	$('#status_form').hide();	
    return false;
	}); 
	
	$("#status_save").live("click",function(event){
	event.preventDefault();	
	$('#status_form').hide();
	var st_txt = $('#status_text').val();
	$.ajax({
	    url: base_url+'/profile.php?mode=status_change&status_text='+st_txt,             
	    dataType : "html",               
	    success: function(data){
		$('#status_box').html(data);
		$('#status_box').show();

		}
	});
    return false;
	}); 
	
	
	 
$(document).keyup(function(e){
        if(e.ctrlKey && e.keyCode == 13)
        {
                comment_valid();
				//$('#comment_submit').click();
                return false;
        }
});	


});


