--- nodehierarchy.module-1.1-ORIG	2008-09-28 22:19:05.000000000 -0400
+++ nodehierarchy.module	2008-12-03 22:25:40.000000000 -0500
@@ -221,6 +221,16 @@ function nodehierarchy_nodeapi(&$node, $
       nodehierarchy_invoke_api("update_parent", $node);
       break;
     case 'load':
+    
+    	// Start hack
+  		// Set nodehierarchy.order_by equal to menu_link.weight only on page load
+  		// and not on AJAX updates
+			if (strpos($_GET['q'], 'ajax') === FALSE)
+			{		
+	    	nodehierarchy_set_order_by_to_weight($node);
+	    }
+    	// End hack
+    	
       return nodehierarchy_load_node($node);
     break;
     case 'delete':
@@ -882,7 +892,11 @@ function _nodehierarchy_create_menu(&$no
 
     $item['link_title'] = trim($node->title);
     $item['link_path'] = "node/$node->nid";
-    $item['weight']   = $node->order_by - 11; // Editable menu weight range used to start at -10.
+
+    // Hack start
+		// $item['weight']   = $node->order_by - 11; // Editable menu weight range used to start at -10.
+		// Hack end
+
     if (!menu_link_save($item)) {
       drupal_set_message(t('There was an error saving the menu link.'), 'error');
     }
@@ -906,9 +920,21 @@ function _nodehierarchy_set_menu_order($
   // This is not possible for top level items, so we rearrange them anyway, since
   // this is usually the desired behaviour.
   if ($parent_menu = _nodehierarchy_get_parent_menu($parent, $nid)) {
-    if ($child_menu = _nodehierarchy_get_child_menu($nid, $parent_menu['mlid'])) {
+
+		// Hack start
+    if ($child_menu = _nodehierarchy_get_child_menu($nid, $parent_menu['plid'])) {
+    //if ($child_menu = _nodehierarchy_get_child_menu($nid, $parent_menu['mlid'])) {
+    // Hack end
+
       $link = menu_link_load($child_menu['mlid']);
-      $link['weight'] = ($order_by-11);
+
+			// Hack start
+			$node->nid = $nid;
+			$node_additions = nodehierarchy_load_node($node);
+			$link['weight'] = $node_additions['order_by'];
+      //$link['weight'] = ($order_by-11);
+      // Hack end
+
       menu_link_save($link);
       return TRUE;
     }
@@ -920,7 +946,11 @@ function _nodehierarchy_set_menu_order($
  * Find the menu ID for the given node.
  */
 function _nodehierarchy_get_menu($nid) {
-  return db_fetch_array(db_query_range("SELECT mlid FROM {menu_links} WHERE link_path = '%s'", "node/$nid", 0, 1));
+
+	// Hack start
+  return db_fetch_array(db_query_range("SELECT mlid, plid FROM {menu_links} WHERE link_path = '%s'", "node/$nid", 0, 1));
+  //return db_fetch_array(db_query_range("SELECT mlid FROM {menu_links} WHERE link_path = '%s'", "node/$nid", 0, 1));  
+  // Hack end
 }
 
 /**
@@ -944,6 +974,16 @@ function _nodehierarchy_get_child_menu($
     return db_fetch_array(db_query_range("SELECT mlid FROM {menu_links} WHERE link_path = '%s' AND plid = '%d'", "node/$nid", $plid, 0, 1));
 }
 
+
+/**
+ * Set nodehierarchy.order_by equal to menu_link.weight
+ */
+function nodehierarchy_set_order_by_to_weight($node) {
+	db_query("UPDATE {nodehierarchy}, {menu_links} SET {nodehierarchy}.order_by = {menu_links}.weight 
+						WHERE {menu_links}.link_path = '%s'
+							AND {nodehierarchy}.nid = %d", "node/" . $node->nid, $node->nid);
+}
+
 /**
  * Get the parent selector pulldown.
  */
