# This patch file was generated by NetBeans IDE
# This patch can be applied using context Tools: Apply Diff Patch action on respective folder.
# It uses platform neutral UTF-8 encoding.
# Above lines and this line are ignored by the patching process.
--- C:\wamp\www\ndbquest\sites\all\modules\panels\plugins\layouts\flexible\flexible.inc
+++ C:\wamp\www\automobius\sites\all\modules\panels\plugins\layouts\flexible\flexible_1.inc
@@ -628,15 +628,9 @@
   if ($item['type'] == 'column') {
     $title = t('Column');
     $settings = t('Column settings');
-    if (empty($item['children'])) {
       $remove = t('Remove column');
       $add = t('Add row');
     }
-    else {
-      $add = t('Add row to top');
-      $add2 = t('Add row to bottom');
-    }
-  }
   else if ($item['type'] == 'row') {
     if ($id == 'canvas') {
       $title = t('Canvas');
@@ -1029,7 +1023,6 @@
   $siblings = &$form_state['siblings'];
   $settings = &$form_state['settings'];
   $id = &$form_state['id'];
-
   if ($item['type'] == 'region') {
     $form['title'] = array(
       '#title' => t('Region title'),
@@ -1146,7 +1139,17 @@
           'column' => t('Columns'),
         ),
       );
-
+      $i = 0;
+      while ($i <= count($settings['items'][$item['parent']]['children'])) {
+        $options[$i] = $i + 1;
+        $i++;
+      }
+      $form['rung'] = array(
+        '#type' => 'select',
+        '#title' => t('Row position'),
+        '#default_value' => $item['rung'],
+        '#options' => $options,
+      );
       if (!empty($item['children'])) {
         $form['contains']['#disabled'] = TRUE;
         $form['contains']['#value'] = $item['contains'];
@@ -1191,6 +1194,7 @@
   }
   else {
     $item['contains'] = $form_state['values']['contains'];
+    $item['rung'] = $form_state['values']['rung'];
   }
 
 }
@@ -1217,6 +1221,7 @@
       $item = array(
         'type' => 'row',
         'contains' => 'region',
+        'rung' => 0,
         'children' => array(),
         'parent' => $id,
       );
@@ -1297,6 +1302,7 @@
 
     // render the item
     $parent_class =  $renderer->base[$parent['type']] . '-' . $id;
+    $prev_row_class =  $renderer->base[$item['type']] . '-' . $parent['children'][$item['rung'] - 1];
     $item_output = panels_flexible_render_item($renderer, $item, $content, $form_state['key'], 0, 0, $item['type'] == 'row');
 
     // Get all the CSS necessary for the entire row (as width adjustments may
@@ -1332,12 +1338,22 @@
         $output[] = ctools_ajax_command_append('#panels-dnd-main .' . $parent_class . '-right', $item_output);
         break;
       case 'middle':
+//      dsm($parent);
+//      dsm($settings);
+//      dsm($form_state);
+//      dsm($id);
+//      dsm($item);
         if ($location == 'left') {
           if (!empty($form_state['sibling'])) {
             $item_output .= panels_flexible_render_splitter($renderer, $form_state['key'], $form_state['sibling']);
           }
+          if ($item['type'] == 'row' && $item['rung'] != 0) {
+            $output[] = ctools_ajax_command_after('#panels-dnd-main .' . $parent_class . '-middle .' . $prev_row_class, $item_output);
+          }
+          else {
           $output[] = ctools_ajax_command_prepend('#panels-dnd-main .' . $parent_class . '-middle', $item_output);
         }
+        }
         else {
           if (!empty($form_state['sibling'])) {
             $item_output = panels_flexible_render_splitter($renderer, $form_state['sibling'], $form_state['key']) .  $item_output;
@@ -1371,7 +1387,6 @@
 
     $output[] = ctools_modal_command_dismiss();
   }
-
   $handler->commands = $output;
 }
 /**
@@ -1449,7 +1464,18 @@
         'column' => t('Columns'),
       ),
     );
+    $i = 0;
+    while ($i <= count($parent['children'])) {
+      $options[$i] = $i + 1;
+      $i++;
   }
+    $form['rung'] = array(
+      '#type' => 'select',
+      '#title' => t('Row position'),
+      '#default_value' => $item['rung'],
+      '#options' => $options,
+    );
+  }
 
   $form['save'] = array(
     '#type' => 'submit',
@@ -1477,6 +1503,7 @@
   }
   else {
     $item['contains'] = $form_state['values']['contains'];
+    $item['rung'] = $form_state['values']['rung'];
   }
 
   if ($item['type'] == 'region') {
@@ -1515,7 +1542,10 @@
 
   // Place the item.
   $settings['items'][$key] = $item;
-  if ($location == 'left') {
+  if ($item['type'] == 'row') {
+    array_splice($parent['children'], $item['rung'], 0, $key);
+  }
+  elseif ($location == 'left') {
     array_unshift($parent['children'], $key);
   }
   else {
