		var simpleTreeCollection;	
		$(document).ready(function(){
			
			simpleTreeCollection = $('.simpleTree').simpleTree({
				autoclose: false,
				
				afterMove:function(){	
					var serialStr = "";
					var order = "";
					$("ul.simpleTree ul span").each(function(){			
						parentId = $(this).parent("li").parent("ul").parent("li").attr("id");
						if (parentId == undefined) parentId = "root";
						order = (($(this).parent("li").prevAll("li").size()+1))/2; 
						if ( parentId != "root") serialStr += ""+parentId+":"+$(this).parent("li").attr("id")+":"+order+"|";
					});
					$.ajax({
					   type: "POST",
					   url: "/bookmarks_save_data.pl",
					   data: "serialized="+serialStr,
					   success: function(asd){
 					   // window.location.replace("site-map");

 					  }
					 });
			
					return false;
					
				},
				afterClick:function(el){
					if($(el).attr("shref")!=''){
		var newWindow = window.open($(el).attr("shref"), '_blank');
		newWindow.focus();
						}
					}
				,	
				animate:true,
				docToFolderConvert:true
			});	
			
			
			$(".delete_category").live("click",function(){
				if(confirm('Удалить запись?')){
												 
				var categoryId = $(this).parent("li").attr("id");
				$.ajax({
					   type: "POST",
					   url: "/bookmarks_save_data.pl",
					   data: "delete="+categoryId,
					   success: function(asd){
						window.location.reload(true)
 					  }
					 });
				}
			});			
			
			$(".add_category").live("click",function(){
												 
				var categoryId = $(this).parent("li").attr("id");
				$.ajax({
					   type: "POST",
					   url: "/bookmarks_save_data.pl",
					   data: "add="+categoryId,
					   success: function(asd){
						window.location.reload(true)
 					  }
					 });
//                var branches = $("<li id='-1'><span>новый элемент</span></li>").appendTo(".simpleTree");
//                $(".simpleTree").simpleTree({
//                        add: branches
//                });

			});			
			
		});

function favThis(fav,favid,redirect){
	var editwin=document.getElementById('editwin');
	var editwin_frame=document.getElementById('editwin_frame');
//	editwin.style.display='block';
//	editwin.style.visibility='visible';

//	var parentli = document.getElementById('ed'+id);
//        var x = getPageOffsetLeft(parentli);
//        var y = getPageOffsetTop(parentli);

//	editwin.style.left=x+'px';
//	editwin.style.top=y+'px';
	
	editwin_frame.src='/bookmarkadd.pl?action=add&id='+favid+'&group='+fav+'&redirect='+redirect;
}


function editThis(id,redirect){
	var editwin=document.getElementById('editwin');
	var editwin_frame=document.getElementById('editwin_frame');
	editwin.style.display='block';
	editwin.style.visibility='visible';

	var parentli = document.getElementById('ed'+id);
        var x = getPageOffsetLeft(parentli);
        var y = getPageOffsetTop(parentli);

	editwin.style.left=x+'px';
	editwin.style.top=y+'px';
	
	editwin_frame.src='/bookmarkedit.pl?id='+id+'&redirect='+redirect;
}

function closeEditwin(){
        var editwin=document.getElementById('editwin');
        var editwin_frame=document.getElementById('editwin_frame');
        editwin.style.display='none';
        editwin.style.visibility='hidden';
	editwin_frame.src='/empty.htm';
}


