			$(document).ready(function(){

					  var parent;
						var child;

			$(".hidden").hide();
		$("#sortable").sortable({
                    placeholder: 'ui-state-highlight',


                     stop: function(event, ui) {
                         //console.log("stopped");
                        parent=$(this).sortable('serialize');

                         $(".hidden").show();
                         //console.log(parent);

                        $.ajax({
                           type: "POST",
                           url: "/contents/order/",
                           data: parent
										

                         });

                    }
                });
		$("#sortable").disableSelection();
                $("ul.children").sortable({
                    placeholder: 'ui-state-highlight',

                    connectWith: '.children',

                     receive: function(event, ui) {
                      parent = $(this).parents("li").attr("id");
                     child = $(this).sortable('serialize');
                     //console.log("new parent");
                    },
                     stop: function(event, ui) {
					 	//console.log('stopped ul.children');
                        if(parent==null){
                            child = $(this).sortable('serialize');
                            parent = $(this).parents("li").attr("id");
                            //console.log("no new parents");

                        }
						var sendParams = child;
						if(parent){
							sendParams += '&parent=' + parent;
						}
                       $(".hidden").show();
                        //console.log(parent);
						//console.log(child);
                        $.ajax({
                           type: "POST",
                           url: "/contents/order/",
                           data: sendParams


                         });

                    }
                });
		$("ul.children").disableSelection();



				});

