 $(document).ready(function(){
    
    $.fn.corner.defaults.useNative = false;
 	
	//все загругления
	$('.box_bl_content').corner("6px");
	$('.box_green').corner("6px");
	$('.box_red').corner("6px");
	$('.box_pink').corner("6px");
	$('.box_violet').corner("6px");
	$('.box_black').corner("6px");
	$('.box_orange').corner("6px");
    $('.box_gray').corner("6px");
    $('.avatar_corner').corner("10px");
	//
    
    // Dialog			
    $('#dialog').dialog({
		autoOpen: false,
		width: 600
	});
    
    $(document).pngFix();
	
 });
 
 /*
 * Create boxy
 */
 
 function create_boxy(id,title,data){
    $("#dialog_content").html("<span id='"+id+"'>"+data+"</span>");
 	if($("#"+id).attr("active")!='1'){
        $('#dialog').dialog('open');
        $('#dialog').dialog('option', 'title', title);
	}
 }
 
 /*
 * Put preloader
 */
 
 function put_preloader(element){
 	element.html('<img src="/images/preload_1.gif" width="100" heigth="15" />');
 }
 
 /*
 * Put small preloader
 */
 
 function put_small_preloader(element){
 	element.html('<img src="/images/loading_small.gif" width="16" heigth="16" class=\"icon\" />');
 }
 
 /*
 * Disable button
 */
 
 var buttons_value = new Array();
 
 function disable_button(element){
    buttons_value[element.attr('id')] = new Array();
    buttons_value[element.attr('id')]['onclick'] = element.attr('onclick');
    buttons_value[element.attr('id')]['class']   = element.attr('class');
 	element.attr("class","sp_button_disabled").attr("onclick","");
 }
 
 function enable_button(element){
 	element.attr("class",buttons_value[element.attr('id')]['class']);
    element.bind("click",buttons_value[element.attr('id')]['onclick']);
 }
 
 /*
 * rating vote
 */
 
 function blog_vote(id,type){
    
    $.post('ajax/ajax_user.x?act=blog_vote',{
		id:id,
		type:type
		}, function(data){
			data = eval(data);
			if(data['answer']==2){
				$("#blog_rating_box_"+id).html(data['rating']).attr("class",data['total_class']);
                $("#user_votes_box").html(data['votes']);
			}else{
                create_boxy('blog_rating_box','Ошибка',data['text']);
			}
	});
    
 }
 
 /*
 * post rating
 */
 
 function post_vote(id,type){
    
    $.post('ajax/ajax_user.x?act=post_vote',{
		id:id,
		type:type
		}, function(data){
			data = eval(data);
			if(data['answer']==2){
				$("#post_rating_box_"+id).html(data['rating']).attr("class",data['total_class']);
                $("#user_votes_box").html(data['votes']);
                $("#blog_rating_box_"+data['blog_id']).html(data['blog_rating']).attr("class",data['total_class_2']);
			}else{
			    create_boxy('post_rating_box','Ошибка',data['text']); 
			}
	});
    
 }
 
 /*
 * user vote
 */
 
 function user_vote(id,type){
    
    $.post('ajax/ajax_user.x?act=user_vote',{
		id:id,
		type:type
		}, function(data){
			data = eval(data);
			if(data['answer']==2){
				$("#user_rating_box_"+id).html(data['carma']).attr("class",data['total_class']);
                $("#user_votes_box").html(data['votes']);
			}else{
                create_boxy('user_rating_box','Ошибка',data['text']);
			}
	});
    
 }
 
 /*
 * commnet vote
 */
 
 function comment_vote(id,type){
    
    $.post('ajax/ajax_user.x?act=comment_vote',{
		id:id,
		type:type
		}, function(data){
			data = eval(data);
			if(data['answer']==2){
				$("#comm_voter_"+id).html(data['rating']).attr("class",data['class_total']);
                $("#user_votes_box").html(data['votes']);
			}else{
                create_boxy('comm_rating_box','Ошибка',data['text']);
			}
	});
    
 }
 
 /*
 * join blog
 */
 
 function join_blog(b_id){
    
    $.post('ajax/ajax_user.x?act=join_blog',{
		b_id:b_id
		}, function(data){
			data = eval(data);
			if(data['answer']==2){
				$("#blog_entry_box").html(data['blog_role']);
                $("#user_votes_box").html(data['votes']);
			}else{
                create_boxy('join_blog_box','Ошибка',data['text']);
			}
	});
    
 }
 
 /*
 * exit blog
 */
 
 function exit_blog(b_id){
    
    $.post('ajax/ajax_user.x?act=exit_blog',{
		b_id:b_id
		}, function(data){
			data = eval(data);
			if(data['answer']==2){
				$("#blog_entry_box").html(data['blog_role']);
                $("#user_votes_box").html(data['votes']);
			}else{
                create_boxy('exit_blog_box','Ошибка',data['text']);
			}
	});
    
 }
 
 /*
 * exit blog 2
 */
 
 function exit_blog_2(b_id){
    
    var temp = $("#act_place_"+b_id).html();
    
    put_small_preloader($("#act_place_"+b_id));
    
    $.post('ajax/ajax_user.x?act=exit_blog',{
		b_id:b_id
		}, function(data){
			data = eval(data);
			if(data['answer']==2){
				$("#blog_"+b_id).html("<td colspan='4' style='padding-left: 10px;'><span class='green'>Вы покинули блог.</span></td>");
			}else{
                create_boxy('exit_blog_box','Ошибка',data['text']);
			}
	});
    
 }
 
 /*
 * show user edit title form
 */
 
 function show_edit_user_title(){
    $("#user_title_edit_place").html("<input id=\"user_title_edit_input\" size=\"20\" value=\""+$("#user_title_edit_place").html()+"\">");
    $("#user_title_edit_button").html("<a href=\"javascript:void(0);\" onclick=\"save_user_title();\" title=\"сохранить\"><img src=\"images/icons/disk.gif\" class=\"icon\"></a>");
 }
 
 function save_user_title(){
    $("#user_title_edit_button").html("<a href=\"javascript:void(0);\" style=\"cursor:default;\" onclick=\"\" title=\"сохранить\"><img src=\"images/icons/disk_off.gif\" class=\"icon\"></a>");
    put_small_preloader($("#user_title_edit_preloader"));
    
    $.post('ajax/ajax_user.x?act=save_user_title',{
		title:$("#user_title_edit_input").val()
		}, function(data){
			data = eval(data);
			if(data['answer']=='1'){
                 create_boxy("user_title_edit_boxy","Ошибка",data['text']);
                 $("#user_title_edit_preloader").html("");
                 $("#user_title_edit_button").html("<a href=\"javascript:void(0);\" onclick=\"save_user_title();\" title=\"сохранить\"><img src=\"images/icons/disk.gif\" class=\"icon\"></a>");
			}else if(data['answer']=='2'){
			     $("#user_title_edit_preloader").html("");
                 $("#user_title_edit_button").html("<a href=\"javascript:void(0);\" onclick=\"show_edit_user_title();\" title=\"редактировать\"><img src=\"images/icons/pencil.png\" class=\"icon\"></a>");
                 $("#user_title_edit_place").html(data['title']);
			}
	});
    
 }
 
 /*
 * show tag edit form
 */
 
 function show_edit_post_tag(id){
    $("#post_tag_edit_place_"+id).html("<input id=\"post_tag_edit_input_"+id+"\" size=\"70\" value=\""+$("#post_just_tag_text_"+id).attr('title')+"\">");
    $("#post_tag_edit_button_"+id).html("<a href=\"javascript:void(0);\" onclick=\"save_post_tag("+id+");\" title=\"сохранить\"><img src=\"images/icons/disk.gif\" class=\"icon\"></a>");
 }
 
 function save_post_tag(id){
    $("#post_tag_edit_button_"+id).html("<a href=\"javascript:void(0);\" style=\"cursor:default;\" onclick=\"\" title=\"сохранить\"><img src=\"images/icons/disk_off.gif\" class=\"icon\"></a>");
    put_small_preloader($("#post_tag_edit_preloader_"+id));
    
    $.post('ajax/ajax_blog.x?act=save_post_tag',{
        id:id,
		tag_text:$("#post_tag_edit_input_"+id).val()
		}, function(data){
			data = eval(data);
			if(data['answer']=='1'){
                 create_boxy("post_tag_edit_boxy_"+id,"Ошибка",data['text']);
                 $("#post_tag_edit_preloader_"+id).html("");
                 $("#post_tag_edit_button_"+id).html("<a href=\"javascript:void(0);\" onclick=\"save_post_tag("+id+");\" title=\"сохранить\"><img src=\"images/icons/disk.gif\" class=\"icon\"></a>");
			}else if(data['answer']=='2'){
			     $("#post_tag_edit_preloader_"+id).html("");
                 $("#post_tag_edit_button_"+id).html("<a href=\"javascript:void(0);\" onclick=\"show_edit_post_tag("+id+");\" title=\"редактировать\"><img src=\"images/icons/pencil.png\" class=\"icon\"></a>");
                 $("#post_tag_edit_place_"+id).html(data['tag_text']);
                 $("#post_just_tag_text_"+id).attr('title',data['just_tag_text']);
			}
	});
    
 }
 
 /*
 * add friend
 */
 
 function add_to_friend(id){
    
    $.post('ajax/ajax_user.x?act=add_to_friend',{
		id:id
		}, function(data){
			data = eval(data);
			if(data['answer']==2){
				create_boxy('add_to_friend','Дружба',data['text']);
			}else{
                create_boxy('add_to_friend','Ошибка',data['text']);
			}
	});
    
 }
 
 function friend_delete(id){
    
    put_small_preloader($("#act_place_"+id));
    
    $.post('ajax/ajax_user.x?act=friend_delete',{
		id:id
		}, function(data){
			data = eval(data);
			if(data['answer']==2){
				$("#friend_"+id).html("<td colspan='5' style='padding-left: 10px;'>"+data['text']+"</td>");
			}else{
                $("#friend_"+id).html("<td colspan='5' style='padding-left: 10px;'>"+data['text']+"</td>");
			}
	});
    
 }
 
 function friend_approve(id){
    
    put_small_preloader($("#act_place_"+id));
    
    $.post('ajax/ajax_user.x?act=friend_approve',{
		id:id
		}, function(data){
			data = eval(data);
			if(data['answer']==2){
				$("#friend_"+id).html("<td colspan='5' style='padding-left: 10px;'>"+data['text']+"</td>");
			}else{
                $("#friend_"+id).html("<td colspan='5' style='padding-left: 10px;'>"+data['text']+"</td>");
			}
	});
    
 }
 
 function user_delete(id){
    
    put_small_preloader($("#act_place_"+id));
    
    $.post('ajax/ajax_blog.x?act=user_delete',{
		id:id
		}, function(data){
			data = eval(data);
			if(data['answer']==2){
				$("#user_"+id).html("<td colspan='5' style='padding-left: 10px;'>"+data['text']+"</td>");
			}else{
                $("#user_"+id).html("<td colspan='5' style='padding-left: 10px;'>"+data['text']+"</td>");
			}
	});
    
 }
 
 function user_ban(id){
    
    var temp = $("#act_place_"+id).html();
    
    put_small_preloader($("#act_place_"+id));
    
    $.post('ajax/ajax_blog.x?act=user_ban',{
		id:id
		}, function(data){
			data = eval(data);
			if(data['answer']==2){
			    $("#act_place_"+id).html(temp);
                $("#active_"+id).html(data['active']);
				$("#ban_button_"+id).attr("src","/images/icons/"+data['img_src']).attr("title",data['title']);
			}else{
                $("#user_"+id).html("<td colspan='5' style='padding-left: 10px;'>"+data['text']+"</td>");
			}
	});
    
 }
 
 function user_status(id,type){
    
    var temp = $("#act_place_"+id).html();
    
    put_small_preloader($("#act_place_"+id));
    
    $.post('ajax/ajax_blog.x?act=user_status',{
		id:id,
        type:type
		}, function(data){
			data = eval(data);
			if(data['answer']==2){
			    $("#act_place_"+id).html(temp);
                $("#up_down_"+id).html(data['up_down']);
                $("#permis_"+id).html(data['permis_level']);
			}else{
                $("#user_"+id).html("<td colspan='5' style='padding-left: 10px;'>"+data['text']+"</td>");
			}
	});
    
 }
 
 function comm_delete(id){
    put_small_preloader($("#act_place_"+id));
    
    $.post('ajax/ajax_blog.x?act=comm_delete',{
		id:id
		}, function(data){
			data = eval(data);
			if(data['answer']==2){
				$("#comment_layer_"+id).hide();
			}else{
                create_boxy('comm_delete','Ошибка',data['text']);
			}
	});
 }
 
 function set_new_box_type(n){
    if(n=='1'){
        $("#scroll_text").show();
        $("#scroll_text_online").hide();
        $("#lenta_type_title").html("<span class='scroll_selected'>Комментарии</span> &nbsp; <a href='javascript:void(0);' onclick='set_new_box_type(2);'>Посты</a>");
    }
    if(n=='2'){
        $("#scroll_text").hide();
        $("#scroll_text_online").show();
        $("#lenta_type_title").html("<a href='javascript:void(0);' onclick='set_new_box_type(1);'>Комментарии</a> &nbsp; <span class='scroll_selected'>Посты</span>");
    }
 }