Index: quicktabs.css
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/quicktabs/quicktabs.css,v
retrieving revision 1.6.2.1
diff -u -p -r1.6.2.1 quicktabs.css
--- quicktabs.css	26 Nov 2008 06:12:24 -0000	1.6.2.1
+++ quicktabs.css	26 Nov 2008 15:56:48 -0000
@@ -1,40 +1,42 @@
+/* $Id */
+
 /* Edit QT section */
 
 #qt-tablist-table label{
-	float:left;
-	clear:left;
-	width:120px;
+  float:left;
+  clear:left;
+  width:120px;
 }
 #qt-tablist-table .form-item{
-	margin-bottom:5px;
+  margin-bottom:5px;
 }
 #qt-tablist-table .form-item .description{
-	margin-top:3px;
+  margin-top:3px;
 }
 #qt-tablist-table .qt-tab-title{
-	padding-right:35px;
+  padding-right:35px;
 }
 #qt-tablist-table .qt-tab-title, #qt-tablist-table .qt-tab-type{
-	width:100px;
+  width:100px;
 }
 #qt-tablist-table .qt-tab-type label.option{
-	width:auto;
+  width:auto;
 }
 #qt-tablist-table .qt-tab-bvid .form-item .form-text{
-	width:150px;
+  width:150px;
 }
 #qt-tablist-table .qt-tab-title .form-item .form-text{
-	width:80px;
+  width:80px;
 }
 
 #quicktabs-form #delete-tabs-button label,
 #quicktabs-form #add-more-tabs-button label, #quicktabs-aj-form #delete-tabs-button label, #quicktabs-aj-form #add-more-tabs-button label{
-	font-weight:bold;
+  font-weight:bold;
 }
 #quicktabs-form #delete-tabs-button,
 #quicktabs-form #add-more-tabs-button, #quicktabs-aj-form #delete-tabs-button, #quicktabs-aj-form #add-more-tabs-button {
-	padding:20px;
-	float:left;
+  padding:20px;
+  float:left;
 }
 
 #quicktabs-form .add-tab,
@@ -71,7 +73,7 @@ form>.add-tab { /* For non-IE browsers*/
 iframe.quicktabs-preview {
   border: none;
   width: 200px;
-  height: 50px;
+  height: 80px;
 }
 
 iframe.quicktabs-preview body {
@@ -86,42 +88,38 @@ ul.quicktabs_tabs li {
   padding: 2px;
 }
 
-#quicktabs-settings .quicktabs-tabstyles .form-item{
-	width:200px;
-	float:left;
-	margin:0 10px 10px 0;
-	border:1px solid #ccc;
-	background-color:#fff;
-}
-
-#quicktabs-settings .quicktabs-tabstyles .form-item .option{
-	display:block;
-	background-color:#bfe3ff;
-	font:bold 12px/18px verdana;
-	color:#0a5793;
-}
-
-#quicktabs-settings .quicktabs-tabstyles .form-item .option:hover{
-	background-color:#aadaff;
-	cursor:pointer;
-	color:#003863;
-}
-
-#quicktabs-settings .quicktabs-tabstyles .form-item .option .form-radio{
-	margin-right:5px;
-	float:left;
-	height:15px;
-	margin-top:2px;
+#quicktabs-settings .quicktabs-tabstyles .form-item {
+  width:200px;
+  float:left;
+  margin:0 10px 10px 0;
+  border:1px solid #ccc;
+  background-color:#fff;
+}
+
+#quicktabs-settings .quicktabs-tabstyles .form-item .option {
+  display:block;
+  background-color:#bfe3ff;
+  font:bold 12px/18px verdana;
+  color:#0a5793;
+}
+
+#quicktabs-settings .quicktabs-tabstyles .form-item .option:hover {
+  background-color:#aadaff;
+  cursor:pointer;
+  color:#003863;
+}
+
+#quicktabs-settings .quicktabs-tabstyles .form-item .option .form-radio {
+  margin-right:5px;
+  float:left;
+  height:15px;
+  margin-top:2px;
 }
 
 /* Misc */
 
-td.qt-tab-bvid input.form-submit {
-	display: none;
-}
-
-td.qt-tab-bvid div.form-item {
-	clear: both;
+td.qt-tab-view-content input.form-submit {
+  display: none;
 }
 
 body.quicktabs_iframe ul#simplemenu {
@@ -130,4 +128,18 @@ body.quicktabs_iframe ul#simplemenu {
 
 html.js div.quicktabs {
   display: none;
-}
\ No newline at end of file
+}
+
+td.qt-tab-title, td.qt-tab-type {
+  width: 150px;
+}
+
+td.qt-tab-block-content, td.qt-tab-view-content, td.qt-tab-node-content {
+  height: 120px;
+}
+
+td.qt-tab-view-content div.form-item {
+  padding-right: 15px;
+  float: left;
+}
+
Index: quicktabs.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/quicktabs/quicktabs.install,v
retrieving revision 1.4
diff -u -p -r1.4 quicktabs.install
--- quicktabs.install	3 Nov 2008 03:31:29 -0000	1.4
+++ quicktabs.install	26 Nov 2008 11:51:40 -0000
@@ -1,45 +1,62 @@
 <?php
 // $Id: quicktabs.install,v 1.4 2008/11/03 03:31:29 katbailey Exp $
 
-
+/**
+ * Implementation of hook_schema().
+ */
 function quicktabs_schema() {
   $schema['quicktabs'] = array(
-    'description' => t('The quicktabs table.'),
+    'description' => 'The quicktabs table.',
     'fields' => array(
       'qtid' => array(
-        'description' => t('The primary identifier for a qt block.'),
+        'description' => 'The primary identifier for a qt block.',
         'type' => 'serial',
         'unsigned' => TRUE,
         'size' => 'big',
         'not null' => TRUE,
-        'disp-width' => '10'),
+        'disp-width' => '10',
+      ),
       'ajax' => array(
-        'description' => t('Whether this is an ajax views block'),
+        'description' => 'Whether this is an ajax views block.',
         'type' => 'int',
         'unsigned' => TRUE,
         'not null' => TRUE,
-        'default' => 0),
+        'default' => 0,
+      ),
       'title' => array(
-        'description' => t('The title of this quicktabs block.'),
+        'description' => 'The title of this quicktabs block.',
         'type' => 'varchar',
         'length' => 255,
-        'not null' => TRUE),
+        'not null' => TRUE,
+      ),
       'tabs' => array(
-        'description' => t('A serialized array of the contents of this qt block.'),
+        'description' => 'A serialized array of the contents of this qt block.',
         'type' => 'text',
         'size' => 'medium',
-        'not null' => TRUE),
+        'not null' => TRUE,
+      ),
+      'style' => array(
+        'description' => 'The CSS file used to style the tabs.',
+        'type' => 'varchar',
+        'length' => 255,
+        'not null' => TRUE,
       ),
+    ),
     'primary key' => array('qtid'),
   );
   return $schema;
 }
 
-
+ /**
+ * Implementation of hook_install().
+ */
 function quicktabs_install() {
   drupal_install_schema('quicktabs');
 }
 
+ /**
+ * Implementation of hook_uninstall().
+ */
 function quicktabs_uninstall() {
   drupal_uninstall_schema('quicktabs');
   // Delete any variables that have been set.
@@ -49,10 +66,21 @@ function quicktabs_uninstall() {
   }
 }
 
-function quicktabs_update_1() {
+/**
+ * Add style column.
+ */
+function quicktabs_update_6002() {
   $ret = array();
-  db_add_field($ret, 'quicktabs', 'ajax', array('description' => t('Whether this is an ajax views block'), 'type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0));
+  db_add_field($ret, 'quicktabs', 'style', array('description' => 'The CSS file used to style the tabs.', 'type' => 'varchar', 'length' => 255, 'not null' => TRUE));
   return $ret;
 }
 
+/**
+ * Add ajax column.
+ */
+function quicktabs_update_6001() {
+  $ret = array();
+  db_add_field($ret, 'quicktabs', 'ajax', array('description' => 'Whether this is an ajax views block.', 'type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0));
+  return $ret;
+}
 
Index: quicktabs.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/quicktabs/quicktabs.module,v
retrieving revision 1.10.2.2
diff -u -p -r1.10.2.2 quicktabs.module
--- quicktabs.module	26 Nov 2008 06:12:24 -0000	1.10.2.2
+++ quicktabs.module	26 Nov 2008 17:29:33 -0000
@@ -1,7 +1,5 @@
 <?php
-
-// $Id: quicktabs.module,v 1.10.2.2 2008/11/26 06:12:24 katbailey Exp $ 
-
+// $Id: quicktabs.module,v 1.10.2.2 2008/11/26 06:12:24 katbailey Exp $
 
 /**
  * Implementation of hook_help().
@@ -13,22 +11,29 @@ function quicktabs_help($path, $arg) {
 <p>Once created, the Quick Tabs blocks show up in your block listing, ready to be configured and enabled like other blocks.</p>
 <p>Multiple Quick Tabs blocks can be placed on a single page.</p>
 <p>Visit the <a href="@configuration">Quick Tabs configuration page</a> to choose a style for your Quick Tabs blocks.</p>
-<p>Click on the "New QT block" tab below to get started.</p>', array('@configuration' => url('admin/settings/quicktabs')));
+<p>Click on the "New QT block" tab above to get started.</p>', array('@configuration' => url('admin/settings/quicktabs')));
+
     case 'admin/build/quicktabs/add':
       return '<p>'. t('Here you can create a new Quick Tabs block. Once you have created this block you will be taken to the <a href="@overview">blocks</a> page to configure and enable it.', array('@overview' => url('admin/build/block'))) .'</p>';
   }
 }
 
+/**
+ * Implementation of hook_theme().
+ */
 function quicktabs_theme() {
   return array(
     'quicktabs_settings' => array(
       'arguments' => array('form' => NULL),
+      'file' => 'includes/admin.inc',
     ),
     'quicktabs_preview_page' => array(
-      'arguments' => array(),
+      'arguments' => array('style'),
+      'file' => 'includes/admin.inc'
     ),
-    'qt_tabs' => array(
+    'quicktabs_admin_form_tabs' => array(
       'arguments' => array('form' => NULL),
+      'file' => 'includes/admin.inc'
     ),
     'quicktabs_block' => array(
       'arguments' => array('block', 'title' => TRUE),
@@ -39,243 +44,340 @@ function quicktabs_theme() {
   );
 }
 
-/** 
- * Implementation of hook_menu(). 
- */ 
-function quicktabs_menu() { 
-  $items = array(); 
-
-    $items['admin/build/quicktabs'] = array( 
+/**
+ * Implementation of hook_menu().
+ */
+function quicktabs_menu() {
+    $items['admin/build/quicktabs'] = array(
       'title' => 'Quick Tabs',
       'file' => 'includes/admin.inc',
-      'description' => 'Create blocks of tabbed content - content for each tab can be a view or a block',
-      'page callback' => 'quicktabs_list', 
-      'access arguments' => array('administer quicktabs blocks'), 
+      'description' => 'Create blocks of tabbed content - content for each tab can be a view or a block.',
+      'page callback' => 'quicktabs_list',
+      'access arguments' => array('administer quicktabs blocks'),
     );
     $items['admin/build/quicktabs/list'] = array(
       'title' => 'List',
-      'file' => 'includes/admin.inc',
-      'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -10);    
+      'type' => MENU_DEFAULT_LOCAL_TASK,
+    );
     $items['admin/build/quicktabs/add'] = array(
       'title' => 'New QT block',
       'file' => 'includes/admin.inc',
-      'access arguments' => array('create quicktabs block'),
-      'page callback' => 'quicktabs_new',
-      'type' => MENU_LOCAL_TASK);
-    $items['admin/build/quicktabs/ajax/add'] = array(
-      'title' => 'New QT AJAX block',
-      'file' => 'includes/admin.inc',
-      'access arguments' => array('create quicktabs block'),
-      'page callback' => 'quicktabs_new',
-      'page arguments' => array(TRUE),
-      'weight' => 1,
-      'type' => MENU_LOCAL_TASK);
-    $items['admin/build/quicktabs/delete'] = array(
+      'access arguments' => array('administer quicktabs blocks'),
+      'page callback' => 'quicktabs_block_edit',
+      'page arguments' => array(array(), 'add'),
+      'type' => MENU_LOCAL_TASK,
+    );
+    $items['admin/build/quicktabs/delete/%quicktabs'] = array(
       'title' => 'Delete QT block',
       'file' => 'includes/admin.inc',
-      'access arguments' => array('administer blocks'),
+      'access arguments' => array('administer quicktabs blocks'),
       'page callback' => 'drupal_get_form',
-      'page arguments' => array('quicktabs_block_delete'),
-      'type' => MENU_CALLBACK);
-    $items['admin/build/quicktabs/edit'] = array(
+      'page arguments' => array('quicktabs_block_delete', 4),
+      'type' => MENU_CALLBACK,
+    );
+    $items['admin/build/quicktabs/edit/%quicktabs'] = array(
       'title' => 'Edit QT block',
       'file' => 'includes/admin.inc',
-      'access arguments' => array('administer blocks'),
+      'access arguments' => array('administer quicktabs blocks'),
       'page callback' => 'quicktabs_block_edit',
-      'type' => MENU_CALLBACK);
+      'page arguments' => array(4, 'edit'),
+      'type' => MENU_CALLBACK,
+    );
+
     $items['admin/settings/quicktabs'] = array(
-      'title'    => 'Quick Tabs',
+      'title' => 'Quick Tabs',
       'file' => 'includes/admin.inc',
-      'description' => 'Select a style for your Quick Tabs blocks',
+      'description' => 'Select a style for your Quick Tabs blocks.',
       'page callback' => 'drupal_get_form',
       'page arguments' => array('quicktabs_settings'),
-      'type'     => MENU_NORMAL_ITEM,
-      'access arguments'   => array('administer site configuration'),
+      'type' => MENU_NORMAL_ITEM,
+      'access arguments' => array('administer quicktabs blocks'),
     );
+
     $items['quicktabs/preview'] = array(
       'page callback' => 'quicktabs_preview_page',
-      'type'     => MENU_CALLBACK,
-      'access arguments'   => array('administer site configuration'),
+      'file' => 'includes/admin.inc',
+      'type' => MENU_CALLBACK,
+      'access arguments' => array('administer quicktabs blocks'),
     );
+
     $items['quicktabs/ahah'] = array(
       'page callback' => 'quicktabs_ahah',
       'file' => 'includes/admin.inc',
       'type' => MENU_CALLBACK,
-      'access arguments' => array('administer site configuration'),
+      'access arguments' => array('administer quicktabs blocks'),
     );
+
     $items['quicktabs/ajax/node'] = array(
       'page callback' => 'quicktabs_ajax_node',
       'type' => MENU_CALLBACK,
+       'access arguments' => array('access content'),
+    );
+    $items['quicktabs/ajax/block'] = array(
+      'page callback' => 'quicktabs_ajax_block',
+      'access arguments' => array('access content'),
+      'type' => MENU_CALLBACK,
+    );
+    $items['quicktabs/ajax/views'] = array(
+      'page callback' => 'quicktabs_ajax_views',
       'access arguments' => array('access content'),
+      'type' => MENU_CALLBACK,
     );
-  return $items; 
+
+  return $items;
 }
 
-/** 
- * Implementation of hook_perm(). 
- */ 
+/**
+ * Implementation of hook_perm().
+ */
 function quicktabs_perm() {
-  return array('create quicktabs block', 'administer quicktabs blocks');
+  return array('administer quicktabs blocks');
 }
 
 /**
- * Implementation of hook_block
+ * Implementation of hook_block().
  */
 function quicktabs_block($op = 'list', $delta = 0, $edit = array()) {
 
   switch ($op) {
     case 'list':
+      $blocks = array();
       $jqueryblocks = array();
       $result = db_query('SELECT * FROM {quicktabs}');
       while ($row = db_fetch_object($result)) {
         $jqueryblocks[$row->qtid] = $row->title;
       }
       foreach ($jqueryblocks as $key => $val) {
-	$blocks[$key]['info'] = t($val);
+        $blocks[$key]['info'] = t($val);
       }
       return $blocks;
       break;
+
     case 'view':
-      
-      if ($qtblock = db_fetch_object(db_query('SELECT qtid, ajax, title, tabs FROM {quicktabs} WHERE qtid = %d', $delta))) {
-        quicktabs_add_css();
-        drupal_add_js(drupal_get_path('module', 'quicktabs') .'/js/quicktabs.js');
-        if ($qtblock->ajax == 0) {
-          $mainblock['subject'] = $qtblock->title;
-          $tabs = unserialize($qtblock->tabs);
-          foreach ($tabs as $key => $tab) {
-            $weight[$key]  = $tab['weight'];
-          }
-          array_multisort($weight, SORT_ASC, $tabs);
-          $tabtitles = array();
-          foreach ($tabs as $tab) {
-            $tabtitles[] = $tab['title'];
-          }
-          $output = '<div class="quicktabs_wrapper">';
-          $output .= theme('quicktabs_tabs', $tabtitles);
-          $output .= '<div class="quicktabs_main">';
-          foreach ($tabs as $j => $tab) {
-            $output .= '<div class="quicktabs">';
-            if ($tab['type'] == 'view') {
-              if (module_exists('views')) {
-                $args = array();
-                if ($tab['args'] != '') {
-                  $args_array = explode(',', $tab['args']);
-                  foreach($args_array as $arg) {
-                    $args[] = trim($arg);
-                  }
-                }
-                $func_args = array_merge(array($tab['bvid'], $tab['display']), $args);
-                $output .= call_user_func_array('views_embed_view', $func_args);
-              }
-              else {
-                $output .= 'Views module not enabled, cannot display tab content';
-              }
-            }
-            else {
-              $pos = strpos($tab['bvid'], '_delta_');
-              $blockmodule = substr($tab['bvid'], 0, $pos);
-              $blockdelta = substr($tab['bvid'], $pos+7);
-              $block = (object) module_invoke($blockmodule, 'block', 'view', $blockdelta);
-              $block->module = $blockmodule;
-              $block->delta = $blockdelta;
-              if ($tab['hide_title'] != 1) {
-                $output .= $block->content ? theme('quicktabs_block', $block, TRUE) : '';
-              } else {
-                $output .= $block->content ? theme('quicktabs_block', $block, FALSE) : '';
-              }
-            }
-            $output .= '</div>';  
-          }
-          $output .= '</div></div>';	
-          $mainblock['content'] = $output;
-        } else {
-          $mainblock['subject'] = $qtblock->title;
-          $tabs = unserialize($qtblock->tabs);
-          foreach ($tabs as $key => $tab) {
-            $weight[$key]  = $tab['weight'];
-            if ($tab['type'] == 'view') {
-             $args_array = explode(',', $tab['args']);
-              foreach($args_array as $arg) {
-                $args[] = trim($arg);
-              }
-              // we need to pass view details to js in case there is ajax paging
-              $settings = array(
-                'views' => array(
-                  'ajax_path' => url('views/ajax'),
-                  'ajaxViews' => array(
-                    array(
-                      'view_name' => $tab['bnid'],
-                      'view_display_id' => $tab['display'],
-                      'view_args' => implode('/', $args),
-                      'view_path' => $_GET['q'],
-                    ),
-                  ),
-                ),
-              );
-            }
-            drupal_add_js($settings, 'setting');
-            views_add_js('ajax_view');
-          }
-          // sort the tabs by weight
-          array_multisort($weight, SORT_ASC, $tabs);
-          
-          // need to construct a path for the tab links for when js is disabled
-          $fullpath = explode('?', $_SERVER['REQUEST_URI']);
-          $queries = $_GET;
-          unset($queries['quicktabs_'. $delta]);
-          unset($queries['q']);
-          unset($queries['page']);
-          $querystring = '';
-          if (!empty($queries)) {
-            $i = 0;
-            foreach ($queries as $key => $value) {
-              $querystring .= $i > 0 ? '&'. $key .'='. $value : $key .'='. $value;
-              $i++;
-            }
-            $querystring .= '&';
-          }
-          $path = $fullpath[0];
-          $path .= '?'. $querystring;
-          // find out which tab is active
-          $active_tab = $_GET['quicktabs_'. $delta] ? $_GET['quicktabs_'. $delta] : 0;
-          
-          // begin output of Quick Tabs mark-up
-          $output = '<div class="quicktabs_wrapper">';
-          // theme the tabs
-          $output .= theme('quicktabs_tabs', $tabs, TRUE, $path, $delta, $active_tab);
-          // the main content area begins
-          $output .= '<div class="quicktabs_main">';
-          // each quick tabs container needs a unique id so that multiple instances work with ajax
-          $output .= '<div id="quicktabs_ajax_container_'. $delta .'">';
-          if ($tabs[$active_tab]['type'] == 'view') {
-            $args = array();
-            if ($tabs[$active_tab]['args'] != '') {
-              $args_array = explode(',', $tabs[$active_tab]['args']);
-              foreach($args_array as $arg) {
-                $args[] = trim($arg);
-              }
-            }
-            $func_args = array_merge(array($tabs[$active_tab]['bnid'], $tabs[$active_tab]['display']), $args);
-            $output .= call_user_func_array('views_embed_view', $func_args);
-          } else {
-            $node = node_load($tabs[$active_tab]['bnid']);
-            $output .= theme('node', $node);
+      if ($qtblock = quicktabs_load($delta)) {
+        $mainblock['subject'] = $qtblock['title'];
+        if ($qtblock['ajax']) {
+          $mainblock['content'] = quicktabs_ajax_render($qtblock['tabs'], $qtblock['style'], $qtblock['qtid']);
+        }
+        else {
+          $mainblock['content'] = quicktabs_render($qtblock['tabs'], $qtblock['style']);
+        }
+        return $mainblock;
+      }
+      break;
+  }
+}
+
+/**
+ * Implementation of hook_quicktabs_tabstyles().
+ *
+ * This hook allows other modules to create additional tab styles for
+ * the quicktabs module.
+ *
+ * @return array
+ *   An array of key => value pairs suitable for inclusion as the #options in a
+ *   select or radios form element. Each key must be the location of a css
+ *   file for a quick tabs style. Each value should be the name of the style.
+ */
+function quicktabs_quicktabs_tabstyles() {
+  $tabstyles_directory = drupal_get_path('module', 'quicktabs') .'/tabstyles';
+  $files = file_scan_directory($tabstyles_directory, '\.css$');
+
+  $tabstyles = array();
+  foreach ($files as $file) {
+    $tabstyles[$file->filename] = drupal_ucfirst($file->name);
+  }
+  return $tabstyles;
+}
+
+/**
+ * Render quicktabs tabpage.
+ */
+function quicktabs_render_tabpage($tab) {
+  $output = '';
+  switch ($tab['type']) {
+    case 'view':
+      if (module_exists('views')) {
+        $args = array();
+        if ($tab['view']['args'] != '') {
+          $args_array = explode(',', $tab['view']['args']);
+          foreach ($args_array as $arg) {
+            $args[] = trim($arg);
           }
-          
-          $output .= '</div>';  
-          $output .= '</div></div>';	
-          $mainblock['content'] = $output;
         }
-      }        
-      return $mainblock;
-    break;
+        $func_args = array_merge(array($tab['view']['vid'], $tab['view']['display']), $args);
+        $output = call_user_func_array('views_embed_view', $func_args);
+      }
+      else {
+        $output = 'Views module not enabled, cannot display tab content';
+      }
+      break;
+
+    case 'block':
+      $pos = strpos($tab['block']['bid'], '_delta_');
+      $blockmodule = substr($tab['block']['bid'], 0, $pos);
+      $blockdelta = substr($tab['block']['bid'], $pos+7);
+      $block = (object) module_invoke($blockmodule, 'block', 'view', $blockdelta);
+      if (isset($block->content)) {
+        $block->module = $blockmodule;
+        $block->delta = $blockdelta;
+        $output = $block->content ? theme('quicktabs_block', $block, !$tab['block']['hide_title']) : '';
+      }
+      break;
+
+    case 'node':
+      $node = node_load($tab['node']['nid']);
+      if (!empty($node)) {
+        if ($tab['node']['hide_title']) {
+          $node->title = NULL;
+        }
+        $output = theme('node', $node, $tab['node']['teaser']);
+      }
+      else {
+        $output = '';
+      }
+      break;
+
+    case 'freetext':
+      $output = $tab['freetext']['text'];
+      break;
+    }
+
+  return $output;
+}
+
+/**
+ * Render quicktabs.
+ */
+function quicktabs_render($tabs, $style = NULL) {
+  $tabstyle_css = NULL;
+  if (isset($style)) {
+    // Get the css file for given style.
+    $tabstyles = module_invoke_all('quicktabs_tabstyles');
+    foreach ($tabstyles as $css_file => $tabstyle) {
+      if (drupal_strtolower($style) == drupal_strtolower($tabstyle)) {
+        $tabstyle_css = $css_file;
+      }
+    }
+  }
+
+  quicktabs_add_css($tabstyle_css);
+  drupal_add_js(drupal_get_path('module', 'quicktabs') .'/js/quicktabs.js');
+
+  foreach ($tabs as $key => $tab) {
+    $weight[$key] = isset($tab['weight']) ? $tab['weight'] : 0;
+  }
+  // sort the tabs by weight
+  array_multisort($weight, SORT_ASC, $tabs);
+  $tabtitles = array();
+  foreach ($tabs as $tab) {
+    $tabtitles[] = $tab['title'];
   }
+  $output = '<div class="quicktabs_wrapper">';
+  $output .= theme('quicktabs_tabs', $tabtitles);
+  $output .= '<div class="quicktabs_main">';
+  foreach ($tabs as $tab) {
+    $output .= '<div class="quicktabs">';
+    $output .= quicktabs_render_tabpage($tab);
+    $output .= '</div>';
+  }
+  $output .= '</div></div>';
+  return $output;
 }
 
-function quicktabs_ajax_node($nid) {
-  $node = node_load($nid);
-  $output = theme('node', $node);
+/**
+ * Render ajax quicktabs.
+ */
+function quicktabs_ajax_render($tabs, $style = NULL, $qtid) {
+  $tabstyle_css = NULL;
+  if (isset($style)) {
+    // Get the css file for given style.
+    $tabstyles = module_invoke_all('quicktabs_tabstyles');
+    foreach ($tabstyles as $css_file => $tabstyle) {
+      if (drupal_strtolower($style) == drupal_strtolower($tabstyle)) {
+        $tabstyle_css = $css_file;
+      }
+    }
+  }
+
+  quicktabs_add_css($tabstyle_css);
+  drupal_add_js(drupal_get_path('module', 'quicktabs') .'/js/quicktabs.js');
+  foreach ($tabs as $key => $tab) {
+    $weight[$key] = $tab['weight'];
+    if ($tab['type'] == 'view') {
+      $args_array = explode(',', $tab['view']['args']);
+      foreach($args_array as $arg) {
+        $args[] = trim($arg);
+      }
+      // we need to pass view details to js in case there is ajax paging
+      $settings = array(
+        'views' => array(
+          'ajax_path' => url('views/ajax'),
+          'ajaxViews' => array(
+            array(
+              'view_name' => $tab['view']['vid'],
+              'view_display_id' => $tab['view']['display'],
+              'view_args' => implode('/', $args),
+              'view_path' => $_GET['q'],
+            ),
+          ),
+        ),
+      );
+    }
+  }
+  // sort the tabs by weight
+  array_multisort($weight, SORT_ASC, $tabs);
+
+   // Need to construct a path for the tab links for when js is disabled.
+  $fullpath = explode('?', request_uri());
+  $queries = $_GET;
+  unset($queries['quicktabs_'. $qtid]);
+  unset($queries['q']);
+  unset($queries['page']);
+  $querystring = '';
+  if (!empty($queries)) {
+    $i = 0;
+    foreach ($queries as $key => $value) {
+      $querystring .= $i > 0 ? '&'. $key .'='. $value : $key .'='. $value;
+      $i++;
+    }
+    $querystring .= '&';
+  }
+  $path = $fullpath[0];
+  $path .= '?'. $querystring;
+  // find out which tab is active
+  $active_tab = isset($_GET['quicktabs_'. $qtid]) ? $_GET['quicktabs_'. $qtid] : 0;
+
+  // begin output of Quick Tabs mark-up
+  $output = '<div class="quicktabs_wrapper">';
+  // Render the tabs.
+  $output .= theme('quicktabs_tabs', $tabs, TRUE, $path, $qtid, $active_tab);
+  // the main content area begins
+  $output .= '<div class="quicktabs_main">';
+  // each quick tabs container needs a unique id so that multiple instances work with ajax
+  $output .= '<div id="quicktabs_ajax_container_'. $qtid .'">';
+  // Render the active tabpgage.
+  $output .= quicktabs_render_tabpage($tabs[$active_tab]);
+  $output .= '</div>';
+  $output .= '</div></div>';
+
+  return $output;
+}
+
+/**
+ * Ajax callback for node tabpage.
+ */
+function quicktabs_ajax_node($nid, $teaser, $hide_title) {
+  $tabpage = array(
+    'type' => 'node',
+    'node' => array(
+      'nid' => $nid,
+      'teaser' => $teaser,
+      'hide_title' => $hide_title,
+    ),
+  );
+
+  $output = quicktabs_render_tabpage($tabpage);
   print drupal_to_js(array('status' => TRUE, 'data' => $output));
 }
 
@@ -283,39 +385,66 @@ function quicktabs_ajax_node($nid) {
  * Theme function for output of the tabs. Use this to ADD extra classes.
  * The general structure 'ul.quicktabs_tabs li a' needs to be maintained
  * for the jQuery to work.
+ *
+ * @ingroup themeable
  */
-function theme_quicktabs_tabs($tabs, $ajax = FALSE, $path = NULL, $delta = 0, $active_tab = 0) {
+function theme_quicktabs_tabs($tabs, $ajax = FALSE, $path = NULL, $qtid = 0, $active_tab = 0) {
+  $output = '';
+  $tabs_count = count($tabs);
+  if ($tabs_count <= 0) {
+    return $output;
+  }
+
+  $i = 1;
   $output .= '<ul class="quicktabs_tabs">';
-  foreach ($tabs as $i => $tab) {
-    $class = ($i == $active_tab ? 'active' : '');
-    if ($ajax) {
-      $qtpath = 'quicktabs_'. $delta . '='. $i;
-      if ($tab['type'] == 'view') {
-        if (module_exists('views')) {              
-          if ($tab['args'] != '') {
-            $argstring = '-'. str_replace(',', '|', $tab['args']);
-          } else {
-            $argstring = '';
-          }
-          $id = 'view-'. $delta .'-'. $i .'-'. $tab['bnid'] .'-'. $tab['display'] . $argstring;
-        } else {
-          $output .= 'Views module not enabled, cannot display tab content';
+  foreach ($tabs as $key => $tab) {
+    $class = 'qtab-'. $key;
+    // Add first, last and active classes to the list of tabs to help out themers.
+    $class .= ($i == $active_tab ? ' active' : '');
+    $class .= ($i == 1 ? ' first' : '');
+    $class .= ($i == $tabs_count ? ' last': '');
+
+    $i++;
+    if (!$ajax) {
+      $output .= '<li'. drupal_attributes(array('class' => $class)) .'><a href="#">'. $tab .'</a></li>';
+    }
+    else {
+      $qtpath = 'quicktabs_'. $qtid .'='. $i;
+      switch ($tab['type']) {
+      case 'view':
+        if ($tab['view']['args'] != '') {
+          $argstring = '--'. str_replace(',', '|', $tab['view']['args']);
+        }
+        else {
+          $argstring = '';
         }
-      } else {
-        $id = 'node-'. $delta .'-'. $i .'-'. $tab['bnid'];
+        $id = 'view--'. $qtid .'--'. $i .'--'. $tab['view']['vid'] .'--'. $tab['view']['display'] . $argstring;
+        break;
+
+      case 'node':
+        $id = 'node--'. $qtid .'--'. $i .'--'. $tab['node']['nid'] .'--'. $tab['node']['teaser'] .'--'. $tab['node']['hide_title'];
+        break;
+
+      case 'block':
+        $id = 'block--'. $qtid .'--'. $i .'--'. $tab['block']['bid'] .'--'. $tab['block']['hide_title'];
+        break;
       }
-      $output .= '<li class="'. $class .'"><a href="'. $path . $qtpath .'" class="qt_ajax_tabs" id="'. $id .'">'. $tab['title'] .'</a></li>';	
-    } else {
-      $output .= '<li class="'. $class .'"><a href="#">'. $tab .'</a></li>';
+
+      $output .= '<li'. drupal_attributes(array('class' => $class)) .'><a href="'. $path . $qtpath .'" class="qt_ajax_tabs '. $tab['type'] .'" id="'. $id .'">'. $tab['title'] .'</a></li>';
     }
   }
+
   $output .= '</ul>';
   return $output;
 }
 
-// the theme function for the overall final block
+/**
+ * Theme function for the overall final quicktabs block.
+ *
+ * @ingroup themeable
+ */
 function theme_quicktabs_block($block, $title = TRUE) {
-  $output  = "<div class=\"block block-$block->module\" id=\"block-$block->module-$block->delta\">\n";
+  $output = "<div class=\"block block-$block->module\" id=\"block-$block->module-$block->delta\">\n";
   if ($title) {
     $output .= " <h2 class=\"title\">$block->subject</h2>\n";
   }
@@ -324,7 +453,6 @@ function theme_quicktabs_block($block, $
   return $output;
 }
 
-
 /**
  * Fetch the necessary CSS files for the tab styles.
  */
@@ -341,3 +469,63 @@ function quicktabs_add_css($tabstyle_css
     drupal_add_css($tabstyle_css, 'module');
   }
 }
+
+/**
+ * Ajax callback for views tabpage.
+ */
+function quicktabs_ajax_views($vid, $display, $args = NULL) {
+  $tabpage = array(
+    'type' => 'view',
+    'view' => array(
+      'vid' => $vid,
+      'display' => $display,
+      'args' => $args,
+    ),
+  );
+
+  $output = quicktabs_render_tabpage($tabpage);
+  print drupal_to_js(array('status' => TRUE, 'data' => $output));
+}
+
+/**
+ * Ajax callback for block tabpage.
+ */
+function quicktabs_ajax_block($bid, $hide_title) {
+  $tabpage = array(
+    'type' => 'block',
+    'block' => array(
+      'bid' => $bid,
+      'hide_title' => $hide_title,
+    ),
+  );
+
+  $output = quicktabs_render_tabpage($tabpage);
+  print drupal_to_js(array('status' => TRUE, 'data' => $output));
+}
+
+/**
+ * Load the quicktabs data.
+ */
+function quicktabs_load($qtid) {
+  $qtblock = db_fetch_object(db_query('SELECT title, tabs, ajax, style FROM {quicktabs} WHERE qtid = %d', $qtid));
+  if (!$qtblock) {
+    return FALSE;
+  }
+
+  $tabs = unserialize($qtblock->tabs);
+  foreach ($tabs as $key => $tab) {
+    $weight[$key] = $tab['weight'];
+  }
+  array_multisort($weight, SORT_ASC, $tabs);
+
+  $quicktabs = array(
+    'qtid' => $qtid,
+    'title' => $qtblock->title,
+    'tabs' => $tabs,
+    'ajax' => $qtblock->ajax,
+    'style' => $qtblock->style,
+  );
+
+  return $quicktabs;
+}
+
Index: includes/admin.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/quicktabs/includes/Attic/admin.inc,v
retrieving revision 1.1.2.1
diff -u -p -r1.1.2.1 admin.inc
--- includes/admin.inc	26 Nov 2008 06:12:24 -0000	1.1.2.1
+++ includes/admin.inc	26 Nov 2008 17:54:26 -0000
@@ -1,13 +1,21 @@
 <?php
+// $Id$
 
+/**
+ * Page callback for quicktabs admin landing page.
+ */
 function quicktabs_list() {
-  $result = db_query('SELECT * FROM {quicktabs}');
-  $header = array(t('Quick Tabs Block Name'), t('Delete'));
+  $result = db_query('SELECT qtid, title FROM {quicktabs} ORDER BY title');
+  $header = array(
+    array('data' => t('Quick Tabs Block Name')),
+    array('data' => t('Operations'), 'colspan' => 2),
+  );
   $rows = array();
   while ($row = db_fetch_object($result)) {
     $tablerow = array(
-    array('data' => $row->title .' ('. l('edit', 'admin/build/quicktabs/edit/'. $row->qtid) .')'),
-    array('data' => l(t('Delete'), 'admin/build/quicktabs/delete/'. $row->qtid)),
+      array('data' => $row->title),
+      array('data' => l('Edit', 'admin/build/quicktabs/edit/'. $row->qtid)),
+      array('data' => l('Delete', 'admin/build/quicktabs/delete/'. $row->qtid)),
     );
     $rows[] = $tablerow;
   }
@@ -15,155 +23,104 @@ function quicktabs_list() {
   return $output;
 }
 
+/*
+ * The admin page to create or modify QT blocks.
+ */
+function quicktabs_form(&$form_state, array $quicktabs) {
+  // Add our JS file, which has some Drupal core JS overrides, and ensures ahah behaviours get re-attached
+  drupal_add_js(drupal_get_path('module', 'quicktabs') . '/js/quicktabs_ahah.js', 'module', 'footer');
+
+  $form = _qt_admin_main_form($form_state, $quicktabs);
 
-function quicktabs_new($ajax = FALSE) {
-  drupal_add_js(drupal_get_path('module', 'quicktabs') .'/js/quicktabs_form.js');
-  drupal_add_css(drupal_get_path('module', 'quicktabs') .'/quicktabs.css');
-  if (!$ajax) {
-    return drupal_get_form('quicktabs_form');
-  } else {
-    return drupal_get_form('quicktabs_aj_form');
+  if ($quicktabs['formtype'] == 'edit') {
+    $form['qtid'] = array(
+      '#type' => 'hidden',
+      '#value' => $quicktabs['qtid']
+    );
   }
-}
 
-/** 
- * build the Quick Tabs (normal) creation and edit form
- */ 
-function quicktabs_form($form_state = NULL, $quicktabs = NULL) {
-  // Add our JS file, which has some Drupal core JS overrides, and ensures ahah behaviours get re-attached
-  drupal_add_js(drupal_get_path('module', 'quicktabs') . '/js/quicktabs_ahah.js', 'footer');
-  
-  $form = _qt_admin_main_form($form_state, $quicktabs, FALSE);
-
-  $formtype = $quicktabs['formtype'];
-  if ($formtype == 'edit') {
-
-    $form['qtid'] = array( 
-    '#type' => 'hidden', 
-    '#value' => $quicktabs['qtid'] 
-    );          
-  }
-  
-  $tabcontent = $quicktabs['tabs'];
-  
-  if (isset($form_state['qt_count'])) {
-    $qt_count = $form_state['qt_count'];
+  if (isset($quicktabs['tabs'])) {
+    $tabcontent = $quicktabs['tabs'];
   }
   else {
-    $qt_count = max(2, empty($tabcontent) ? 2 : count($tabcontent));
+    $tabcontent = array();
   }
 
-  // Add the current tabs to the form.
-  for ($delta = 0; $delta < $qt_count; $delta++) {
-
-    $weight = isset($tabcontent[$delta]['tabweight']) ? $tabcontent[$delta]['tabweight'] : $delta-10;
-    $title = isset($tabcontent[$delta]['tabtext']) ? $tabcontent[$delta]['tabtext'] : '';
-    $type = isset($tabcontent[$delta]['tabtype']) ? $tabcontent[$delta]['tabtype'] : 'block';
-    $bid = isset($tabcontent[$delta]['bid']) ? $tabcontent[$delta]['bid'] : NULL;
-    $hide_title = isset($tabcontent[$delta]['hide_title']) ? $tabcontent[$delta]['hide_title'] : 1;
-    $vid = isset($tabcontent[$delta]['vid']) ? $tabcontent[$delta]['vid'] : 'default';
-    $args = isset($tabcontent[$delta]['args']) ? $tabcontent[$delta]['args'] : NULL;
-    $display = isset($tabcontent[$delta]['display']) ? $tabcontent[$delta]['display'] : 'default';
-    $details = array(
-      'delta' => $delta,
-      'weight' => $weight,
-      'title' => $title,
-      'type' => $type,
-      'bid' => $bid,
-      'hide_title' => $hide_title,
-      'vid' => $vid,
-      'args' => $args,
-      'display' => $display,
-    );
-    $form['qt_wrapper']['tabs'][$delta] = _quicktabs_form($details, FALSE);
-  }
-  
-  return $form;
-}
-
-/** 
- * build the Quick Tabs (ajax) creation and edit form
- */ 
-function quicktabs_aj_form($form_state = NULL, $quicktabs = NULL) {
-  // Add our JS file, which has some Drupal core JS overrides, and ensures ahah behaviours get re-attached
-  drupal_add_js(drupal_get_path('module', 'quicktabs') . '/js/quicktabs_ahah.js', 'footer');
-  
-  $form = _qt_admin_main_form($form_state, $quicktabs, TRUE);
-
-  $formtype = $quicktabs['formtype'];
-  if ($formtype == 'edit') {
-
-    $form['qtid'] = array( 
-    '#type' => 'hidden', 
-    '#value' => $quicktabs['qtid'] 
-    );          
-  }
-  
-  $tabcontent = $quicktabs['tabs'];
-  
   if (isset($form_state['qt_count'])) {
     $qt_count = $form_state['qt_count'];
   }
   else {
-    $qt_count = max(2, empty($tabcontent) ? 2 : count($tabcontent));
+    $qt_count = empty($tabcontent) ? 2 : count($tabcontent);
   }
 
   // Add the current tabs to the form.
   for ($delta = 0; $delta < $qt_count; $delta++) {
-
-    $weight = isset($tabcontent[$delta]['tabweight']) ? $tabcontent[$delta]['tabweight'] : $delta-10;
-    $title = isset($tabcontent[$delta]['tabtext']) ? $tabcontent[$delta]['tabtext'] : '';
-    $type = isset($tabcontent[$delta]['tabtype']) ? $tabcontent[$delta]['tabtype'] : 'node';
-    $nid = isset($tabcontent[$delta]['nid']) ? $tabcontent[$delta]['nid'] : NULL;
-    $vid = isset($tabcontent[$delta]['vid']) ? $tabcontent[$delta]['vid'] : 'default';
-    $args = isset($tabcontent[$delta]['args']) ? $tabcontent[$delta]['args'] : NULL;
-    $display = isset($tabcontent[$delta]['display']) ? $tabcontent[$delta]['display'] : 'default';
-    $details = array(
-      'delta' => $delta,
-      'weight' => $weight,
-      'title' => $title,
-      'type' => $type,
-      'nid' => $nid,
-      'vid' => $vid,
-      'args' => $args,
-      'display' => $display,
-    );
-    $form['qt_wrapper']['tabs'][$delta] = _quicktabs_form($details, TRUE);
+    $details = isset($tabcontent[$delta]) ? $tabcontent[$delta] : array();
+    $details['delta'] = $delta;
+    $form['qt_wrapper']['tabs'][$delta] = _quicktabs_form($details);
   }
+
   return $form;
 }
 
-function _qt_admin_main_form($form_state = NULL, &$quicktabs = NULL, $ajax = FALSE) {
-  $form = array(
-    '#cache' => TRUE,
-  );
+/*
+ * The main section of admin page.
+ */
+function _qt_admin_main_form($form_state, array &$quicktabs) {
+  $form['#cache'] = TRUE;
+
   // the contents of $quicktabs will either come from the db or from $form_state
   if (isset($form_state['quicktabs'])) {
     $quicktabs = $form_state['quicktabs'] + (array)$quicktabs;
   }
-  
+
   $form['title'] = array(
-  '#title' => t('Block Title'),
-  '#type' => 'textfield',
-  '#description' => t('The title of the whole block'),
-  '#default_value' => ($quicktabs['title'] ? $quicktabs['title'] : ''),
-  '#weight' => -5
-  );      
+    '#title' => t('Block Title'),
+    '#type' => 'textfield',
+    '#description' => t('The title of the whole block.'),
+    '#default_value' => isset($quicktabs['title']) ? $quicktabs['title'] : '',
+    '#weight' => -5,
+  );
+
+  $styles = module_invoke_all('quicktabs_tabstyles');
+  // The keys used for radios options must be valid html ids. Removing path to css files.
+  foreach ($styles as $style) {
+    $style_options[drupal_strtolower($style)] = $style;
+  }
+
+  $form['style'] = array(
+    '#type' => 'select',
+    '#title' => t('Tab Style'),
+    '#options' => array('default' => t('No style')) + $style_options,
+    '#default_value' => isset($quicktabs['style']) ? $quicktabs['style'] : variable_get('quicktabs_tabstyle', 'default'),
+    '#description' => t('Choose the tab style for your Quick Tabs blocks.'),
+    '#weight' => -4,
+  );
+
+  $form['ajax'] = array(
+    '#type' => 'radios',
+    '#title' => t('Ajax'),
+    '#options' => array(TRUE => t('Yes: Tabpages will be loaded at tab click'), FALSE => t('No: Tabpages will be loaded at page load')),
+    '#default_value' => isset($quicktabs['ajax']) ? $quicktabs['ajax'] : FALSE,
+    '#description' => t('Choose how the tabpages shoud be loaded.'),
+    '#weight' => -3,
+  );
 
   // Add a wrapper for the tabs and Add Another Tab button.
   $form['qt_wrapper'] = array(
     '#tree' => FALSE,
-    '#weight' => -4,
+    '#weight' => -2,
     '#prefix' => '<div class="clear-block" id="quicktabs-tabs-wrapper">',
     '#suffix' => '</div>',
   );
 
   $form['qt_wrapper']['tabs'] = array(
+    '#tree' => TRUE,
     '#prefix' => '<div id="quicktabs-tabs">',
     '#suffix' => '</div>',
-    '#theme' => 'qt_tabs',    
+    '#theme' => 'quicktabs_admin_form_tabs',
   );
-  
+
   $form['qt_wrapper']['tabs_more'] = array(
     '#type' => 'submit',
     '#prefix' => '<div id="add-more-tabs-button">',
@@ -194,171 +151,185 @@ function _qt_admin_main_form($form_state
       'effect' => 'fade',
     ),
   );
-  
-  $form['submit'] = array(
-  '#type' => 'submit',
-  '#weight' => 10,
-  '#value' => t('Save'),
+
+  $form['submit_form'] = array(
+    '#type' => 'submit',
+    '#weight' => 10,
+    '#value' => t('Save'),
   );
-  
+
   return $form;
 }
 
-/** 
- * build the form elements for each tab
- */ 
-function _quicktabs_form($details, $ajax = FALSE) {
-
-  $form = array(
-    '#tree' => TRUE,
-  );
+/*
+ * One row on the QT admin form.
+ */
+function _quicktabs_form(array $details) {
   $delta = $details['delta'];
+  $weight = isset($details['weight']) ? $details['weight'] : $delta-10;
+  $title = isset($details['title']) ? $details['title'] : '';
+  $type = isset($details['type']) ? $details['type'] : '';
+
+  if ($type == 'block') {
+    $block_bid = $details['block']['bid'];
+    $block_hide_title = $details['block']['hide_title'];
+  }
+  else {
+    $block_bid = NULL;
+    $block_hide_title = 1;
+  }
+
+  if ($type == 'node') {
+    $node_nid = $details['node']['nid'];
+    $node_teaser = $details['node']['teaser'];
+    $node_hide_title = $details['node']['hide_title'];
+  }
+  else {
+    $node_nid = NULL;
+    $node_teaser = 0;
+    $node_hide_title = 1;
+  }
+
+  if ($type == 'view') {
+    $view_vid = $details['view']['vid'];
+    $view_args = $details['view']['args'];
+    $view_display = $details['view']['display'];
+  }
+  else {
+    $view_vid = 'default';
+    $view_args = NULL;
+    $view_display = 'default';
+  }
 
-  // We'll manually set the #parents property of these fields so that
-  // their values appear in the $form_state['values']['tabs'] array.
-  $form['tabweight'] = array(
+  $form['#tree'] = TRUE;
+  $form['weight'] = array(
     '#type' => 'weight',
-    '#default_value' => $details['weight'],
-    '#parents' => array('tabs', $delta, 'tabweight'),    
+    '#default_value' => $weight,
   );
-  
-  $form['tabtext'] = array(
+  $form['title'] = array(
     '#type' => 'textfield',
     '#size' => '10',
     '#title' => t('Tab @n', array('@n' => ($delta + 1))),
-    '#default_value' => $details['title'],
-    '#parents' => array('tabs', $delta, 'tabtext'),
+    '#default_value' => $title,
+  );
+
+  $tabtypes = array(
+    'block' => t('Block'),
+    'node' => t('Content'),
   );
 
   if (module_exists('views')) {
     $views = quicktabs_get_views();
-    if (!$ajax) {
-      $blocks = quicktabs_get_blocks();
-
-      $form['type_options'] = array(
-      '#type' => 'value',
-      '#value' => array(
-      'block' => 'block',
-      'view' => 'view',
-      )
-      );
-    }
-    else {
-      $nodes = quicktabs_get_nodes();
-      
-      $form['type_options'] = array(
-      '#type' => 'value',
-      '#value' => array(
-      'node' => 'node',
-      'view' => 'view',
-      )
-      );
-    }
-    $form['tabtype'] = array(
-    '#type' => 'radios',
-    '#options' => $form['type_options']['#value'],
-    '#title' => t('Tab Content'),
-    '#default_value' => $details['type'],
-    '#parents' => array('tabs', $delta, 'tabtype'),
-    );
+    $tabtypes['view'] = t('View');
     $views_keys = array_keys($views);
-    $selected_view = ($details['vid'] ? ($details['vid'] == 'default' ? $views_keys[0] : ($details['type'] != 'view' ? $views_keys[0] : $details['vid'])) : $views_keys[0]);
-    $form['vid'] = array(
-    '#type' => 'select',
-    '#options' => $views,
-    '#default_value' => $selected_view,
-    '#title' => t('Select a view'),
-    '#parents' => array('tabs', $delta, 'vid'),
-    '#ahah' => array(
-      'path' => 'quicktabs/ahah/',
-      'wrapper' => 'quicktabs-tabs',
-      'method' => 'replace',
-      'event' => 'change',
+    $selected_view = ($view_vid ? ($view_vid == 'default' ? (isset($views_keys[0]) ? $views_keys[0] : '') : $view_vid) : $views_keys[0]);
+    $form['view']['vid'] = array(
+      '#type' => 'select',
+      '#options' => $views,
+      '#default_value' => $selected_view,
+      '#title' => t('Select a view'),
+      '#ahah' => array(
+        'path' => 'quicktabs/ahah/',
+        'wrapper' => 'quicktabs-tabs',
+        'method' => 'replace',
+        'event' => 'change',
       ),
     );
-    $form['args'] = array(
-    '#type' => 'textfield',
-    '#title' => 'arguments',
-    '#size' => '10',
-    '#required' => false,
-    '#default_value' => $details['args'],
-    '#description' => t('Provide a comma separated list of arguments to pass to the view.'),
-    '#parents' => array('tabs', $delta, 'args')
-    );        
-
-    $form['display'] = array(
-    '#type' => 'select',
-    '#title' => 'display',
-    '#options' => _quicktabs_get_views_displays($selected_view),
-    '#default_value' => $details['display'],
-    '#description' => t('Choose a display for your view.'),
-    '#parents' => array('tabs', $delta, 'display')
-    );
-    $form['get_displays'] = array(
-    '#type' => 'submit',
-    '#value' => 'vdisp_'. $delta,
-    '#parents' => array('tabs', $delta, 'get_displays'),
-    '#submit' => array('qt_get_displays_submit'),
-    );
-  } else {
-    $form['tabtype'] = array(
-      '#type' => 'hidden',
-      '#title' => t('Type for tab @n', array('@n' => ($delta + 1))),
-      '#value' => $details['type'],
-      '#parents' => array('tabs', $delta, 'tabtype'),
+    $form['view']['args'] = array(
+      '#type' => 'textfield',
+      '#title' => 'arguments',
+      '#size' => '20',
+      '#required' => FALSE,
+      '#default_value' => $view_args,
+      '#description' => t('Provide a comma separated list of arguments to pass to the view.'),
     );
-  }
-  if (!$ajax) {
-    $form['bid'] = array(
+    $form['view']['display'] = array(
       '#type' => 'select',
-      '#options' => $blocks,
-      '#default_value' => $details['bid'],      
-      '#title' => t('Select a block'),
-      '#parents' => array('tabs', $delta, 'bid'),
-    );
-    $form['hide_title'] = array(
-      '#type' => 'checkbox',
-      '#title' => t('Hide the title of this block'),
-      '#default_value' => $details['hide_title'],
-      '#parents' => array('tabs', $delta, 'hide_title'),
+      '#title' => 'display',
+      '#options' => _quicktabs_get_views_displays($selected_view),
+      '#default_value' => $view_display,
+      '#description' => t('Choose a display for your view.'),
     );
-  }
-  else {
-    $form['nid'] = array(
-      '#type' => 'select',
-      '#options' => $nodes,
-      '#default_value' => $details['nid'],      
-      '#title' => t('Select a node'),
-      '#parents' => array('tabs', $delta, 'nid'),
+    $form['view']['get_displays'] = array(
+      '#type' => 'submit',
+      '#value' => 'vdisp_'. $delta,
+      '#submit' => array('qt_get_displays_submit'),
     );
   }
+
+  $form['node']['nid'] = array(
+    '#type' => 'textfield',
+    '#maxlength' => 5,
+    '#size' => 20,
+    '#default_value' => $node_nid,
+    '#title' => t('Node'),
+    '#description' => t('Insert the node ID.'),
+  );
+  $form['node']['teaser'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Teaser view'),
+    '#default_value' => $node_teaser,
+  );
+  $form['node']['hide_title'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Hide the title of this node'),
+    '#default_value' => $node_hide_title,
+  );
+
+  $form['block']['bid'] = array(
+    '#type' => 'select',
+    '#options' => quicktabs_get_blocks(),
+    '#default_value' => $block_bid,
+    '#title' => t('Select a block'),
+  );
+  $form['block']['hide_title'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Hide the title of this block'),
+    '#default_value' => $block_hide_title,
+  );
+
+  $form['type'] = array(
+    '#type' => 'radios',
+    '#options' => $tabtypes,
+    '#title' => t('Tab Content'),
+    '#default_value' => (!empty($type) ? $type : 'block'),
+  );
+
   return $form;
 }
 
-/** 
- * theme the form elements for the tabs as draggable table rows
- */ 
-function theme_qt_tabs($form) {
+/**
+ * Theme function for quicktabs admin page.
+ *
+ * @ingroup themeable
+ */
+function theme_quicktabs_admin_form_tabs($form) {
+  // Change the button title to reflect the behavior when using JavaScript.
   drupal_add_tabledrag('qt-tablist-table', 'order', 'sibling', 'qt-tabs-weight');
+
   $rows = array();
   $headers = array(
-    t('Tab Title'),
-    t('Weight'),
-    module_exists('views') ? t('Tab type') : '',
-    t('Content'),
+    array('data' => t('Tab Title')),
+    array('data' => t('Weight')),
+    array('data' => t('Tab type')),
+    array('data' => t('Tab content')),
   );
 
   foreach (element_children($form) as $key) {
     // No need to print the field title every time.
-    unset($form[$key]['tabtext']['#title'], $form[$key]['tabtype']['#title']);
-    $form[$key]['tabweight']['#attributes']['class'] = 'qt-tabs-weight';
+    unset($form[$key]['title']['#title'], $form[$key]['type']['#title']);
+    $form[$key]['weight']['#attributes']['class'] = 'qt-tabs-weight';
     // Build the table row.
     $row = array(
       'data' => array(
-        array('data' => drupal_render($form[$key]['tabtext']), 'class' => 'qt-tab-title'),
-        array('data' => drupal_render($form[$key]['tabweight']), 'class' => 'qt-tab-weight'),
-        module_exists('views') ? array('data' => drupal_render($form[$key]['tabtype']), 'class' => 'qt-tab-type') : array('data' => '', 'class' => 'qt-tabtype-hidden'),
-        array('data' => ($form[$key]['bid'] ? drupal_render($form[$key]['bid']) . drupal_render($form[$key]['hide_title']) : drupal_render($form[$key]['nid'])) . (module_exists('views') ? drupal_render($form[$key]['vid']) . drupal_render($form[$key]['args']) . drupal_render($form[$key]['limit']) . drupal_render($form[$key]['display']) . drupal_render($form[$key]['get_displays']) : ''), 'class' => 'qt-tab-bvid'),
+        array('data' => drupal_render($form[$key]['title']), 'class' => 'qt-tab-title'),
+        array('data' => drupal_render($form[$key]['weight']), 'class' => 'qt-tab-weight'),
+        array('data' => drupal_render($form[$key]['type']), 'class' => 'qt-tab-type'),
+        // tab content start (only 1 tab content (block, node or view) will be displayed. see: quicktabs_form.js)
+        array('data' => drupal_render($form[$key]['block']), 'class' => 'qt-tab-block-content'),
+        array('data' => (module_exists('views') ? drupal_render($form[$key]['view']) : ''), 'class' => 'qt-tab-view-content'),
+        array('data' => drupal_render($form[$key]['node']), 'class' => 'qt-tab-node-content'),
+        // tab content end
       ),
       'class' => 'draggable',
     );
@@ -375,11 +346,9 @@ function theme_qt_tabs($form) {
   return $output;
 }
 
-
-
-/** 
- * submit handler for the "Add Tab" button
- */ 
+/**
+ * Submit handler for the "Add Tab" button.
+ */
 function qt_more_tabs_submit($form, &$form_state) {
   unset($form_state['submit_handlers']);
   form_execute_handlers('submit', $form, $form_state);
@@ -387,29 +356,39 @@ function qt_more_tabs_submit($form, &$fo
   $form_state['quicktabs'] = $quicktabs;
   $form_state['rebuild'] = TRUE;
   if ($form_state['values']['tabs_more']) {
-    $form_state['qt_count'] = count($form_state['values']['tabs']) + 1;
+    if (isset($form_state['values']['tabs'])) {
+      $form_state['qt_count'] = count($form_state['values']['tabs']) + 1;
+    }
+    else {
+      $form_state['qt_count'] = 1;
+    }
   }
   return $quicktabs;
 }
 
-/** 
- * submit handler for the "Remove Tab" button
- */ 
+/**
+ * Submit handler for the "Remove Tab" button.
+ */
 function qt_remove_tab_submit($form, &$form_state) {
   unset($form_state['submit_handlers']);
   form_execute_handlers('submit', $form, $form_state);
   $quicktabs = $form_state['values'];
   $form_state['quicktabs'] = $quicktabs;
   $form_state['rebuild'] = TRUE;
-  unset($form['qt_wrapper']['tabs'][0]);
-  $form_state['values']['tabs'] = array_values($form_state['values']['tabs']);
-  $form_state['qt_count'] = count($form_state['values']['tabs']) - 1;
+  //unset($form['qt_wrapper']['tabs'][0]);
+  if (isset($form_state['values']['tabs'])) {
+    $form_state['values']['tabs'] = array_values($form_state['values']['tabs']);
+    $form_state['qt_count'] = count($form_state['values']['tabs']) - 1;
+  }
+  else {
+    $form_state['qt_count'] = 0;
+  }
   return $quicktabs;
 }
 
-/** 
- * submit handler for the Views drop down
- */ 
+/**
+ * Submit handler for the Views drop down.
+ */
 function qt_get_displays_submit($form, &$form_state) {
   unset($form_state['submit_handlers']);
   form_execute_handlers('submit', $form, $form_state);
@@ -419,9 +398,9 @@ function qt_get_displays_submit($form, &
   return $quicktabs;
 }
 
-/** 
- * ahah callback
- */ 
+/**
+ * AHAH callback.
+ */
 function quicktabs_ahah() {
   $form_state = array('storage' => NULL, 'submitted' => FALSE);
   $form_build_id = $_POST['form_build_id'];
@@ -444,230 +423,183 @@ function quicktabs_ahah() {
   ));
 }
 
+/**
+ * Validation handler for quicktabs admin page.
+ */
 function quicktabs_form_validate($form, &$form_state) {
-  // we don't want it to validate when we're just adding or removing tabs
-  if ($form_state['values']['op'] == t('Save')) {
+  // We don't want it to validate when we're just adding or removing tabs.
+  if ($form_state['clicked_button']['#id'] == 'edit-submit-form') {
     if (empty($form_state['values']['title'])) {
       form_set_error('title', t('You must give your Quick Tabs block a title.'));
     }
     else {
+      if (!isset($form_state['values']['tabs'])) {
+        form_set_error('', t('At least one tab should be created.'));
+      }
       foreach ($form_state['values']['tabs'] as $j => $tab) {
-        if (empty($tab['tabtext'])) {
-          form_set_error('tabs]['. $j .'][tabtext', t('You must give each tab a title.'));	  
+        if (empty($tab['title'])) {
+          form_set_error('tabs]['. $j .'][title', t('You must give each tab a title.'));
         }
-      }  
+      }
     }
   }
 }
 
-function quicktabs_form_submit($form, $form_state) {
-  // we don't want it to submit when we're just adding or removing tabs
-  if ($form_state['values']['op'] == t('Save')) {
+/**
+ * Submit handler for quicktabs admin page.
+ */
+function quicktabs_form_submit($form, &$form_state) {
+  // We don't want it to submit when we're just adding or removing tabs.
+  if ($form_state['clicked_button']['#id'] == 'edit-submit-form') {
     $formvalues_tabs = array();
-    foreach ($form_state['values']['tabs'] as $j => $tab) {
-      $formvalues_tabs[] = array(
-      'title' => $form_state['values']['tabs'][$j]['tabtext'],
-      'type' => $form_state['values']['tabs'][$j]['tabtype'],
-      'bvid' => ($form_state['values']['tabs'][$j]['tabtype'] == 'block' ? $form_state['values']['tabs'][$j]['bid'] : $form_state['values']['tabs'][$j]['vid']),
-      'hide_title' => ($form_state['values']['tabs'][$j]['tabtype'] == 'block' ? $form_state['values']['tabs'][$j]['hide_title'] : 0),
-      'weight' => $form_state['values']['tabs'][$j]['tabweight'],
-      'args' => ($form_state['values']['tabs'][$j]['tabtype'] == 'block' ? '' : $form_state['values']['tabs'][$j]['args']),
-      'display' => ($form_state['values']['tabs'][$j]['tabtype'] == 'block' ? '' : $form_state['values']['tabs'][$j]['display']),
-      );
-    }
-    $fullcontent = array(
-      'blocktitle' => $form_state['values']['title'],
-      'blockcontent' => $formvalues_tabs,
-    );
-  
-    if ($form_state['values']['qtid']) {
-      $qtid = $form_state['values']['qtid'];
-      quicktabs_updateblock($qtid, $fullcontent);
-      $msg = t('Your Quick Tabs block has been updated.');    
-    }
-    else {
-      quicktabs_createblock($fullcontent);
-      $msg = t('Your Quick Tabs block has been created and can now be enabled.');  
-    }
-    drupal_set_message($msg); 
-    drupal_goto('admin/build/quicktabs');
-  }
-}
-
-function quicktabs_aj_form_validate($form, &$form_state) {
-  // we don't want it to validate when we're just adding or removing tabs
-  if ($form_state['values']['op'] == t('Save')) {
-    if (empty($form_state['values']['title'])) {
-      form_set_error('title', t('You must give your Quick Tabs block a title.'));
-    }
-    else {
-      foreach ($form_state['values']['tabs'] as $j => $tab) {
-        if (empty($tab['tabtext'])) {
-          form_set_error('tabs]['. $j .'][tabtext', t('You must give each tab a title.'));	  
-        }
-      }  
-    }
-  }
-}
 
-function quicktabs_aj_form_submit($form, $form_state) {
-  // we don't want it to submit when we're just adding or removing tabs
-  if ($form_state['values']['op'] == t('Save')) {
-    $formvalues_tabs = array();
-    foreach ($form_state['values']['tabs'] as $j => $tab) {
-      $formvalues_tabs[] = array(
-      'title' => $form_state['values']['tabs'][$j]['tabtext'],
-      'type' => $form_state['values']['tabs'][$j]['tabtype'],
-      'bnid' => ($form_state['values']['tabs'][$j]['tabtype'] == 'node' ? $form_state['values']['tabs'][$j]['nid'] : $form_state['values']['tabs'][$j]['vid']),
-      'weight' => $form_state['values']['tabs'][$j]['tabweight'],
-      'args' => ($form_state['values']['tabs'][$j]['type'] == 'node' ? '' : $form_state['values']['tabs'][$j]['args']),
-      'display' => ($form_state['values']['tabs'][$j]['type'] == 'node' ? '' : $form_state['values']['tabs'][$j]['display']),
-      );
+    foreach ($form_state['values']['tabs'] as $tab_num => $tab) {
+      $formvalues_tabs[$tab_num]['title'] = $tab['title'];
+      $formvalues_tabs[$tab_num]['weight'] = $tab['weight'];
+      $formvalues_tabs[$tab_num]['type'] = $tab['type'];
+
+      switch ($tab['type']) {
+        case 'block':
+          $formvalues_tabs[$tab_num]['block']['bid'] = $tab['block']['bid'];
+          $formvalues_tabs[$tab_num]['block']['hide_title'] = $tab['block']['hide_title'];
+          break;
+        case 'view':
+          $formvalues_tabs[$tab_num]['view']['vid'] = $tab['view']['vid'];
+          $formvalues_tabs[$tab_num]['view']['args'] = $tab['view']['args'];
+          $formvalues_tabs[$tab_num]['view']['display'] = $tab['view']['display'];
+          break;
+        case 'node':
+          $formvalues_tabs[$tab_num]['node']['nid'] = $tab['node']['nid'];
+          $formvalues_tabs[$tab_num]['node']['teaser'] = $tab['node']['teaser'];
+          $formvalues_tabs[$tab_num]['node']['hide_title'] = $tab['node']['hide_title'];
+          break;
+      };
     }
     $fullcontent = array(
-      'blocktitle' => $form_state['values']['title'],
-      'blockcontent' => $formvalues_tabs,
+      'title' => $form_state['values']['title'],
+      'style' => $form_state['values']['style'],
+      'ajax' => $form_state['values']['ajax'],
+      'tabs' => $formvalues_tabs,
     );
-  
-    if ($form_state['values']['qtid']) {
+
+    if (isset($form_state['values']['qtid'])) {
       $qtid = $form_state['values']['qtid'];
       quicktabs_updateblock($qtid, $fullcontent);
-      $msg = t('Your Quick Tabs block has been updated.');    
+      $msg = t('Your Quick Tabs block has been updated.');
     }
     else {
-      quicktabs_createblock($fullcontent, TRUE);
-      $msg = t('Your Quick Tabs block has been created and can now be enabled.');  
+      quicktabs_createblock($fullcontent);
+      $msg = t('Your Quick Tabs block has been created and can now be enabled.');
     }
-    drupal_set_message($msg); 
-    drupal_goto('admin/build/quicktabs');
+    drupal_set_message($msg);
+    $form_state['redirect'] = 'admin/build/quicktabs';
+    //drupal_goto('admin/build/quicktabs');
   }
 }
 
-function quicktabs_createblock($fullcontent, $ajax = FALSE) {
+/**
+ * Insert db record.
+ */
+function quicktabs_createblock($fullcontent) {
   $qtid = db_last_insert_id('quicktabs', 'qtid');
-  $title = $fullcontent['blocktitle'];
-  $tabs = serialize($fullcontent['blockcontent']);
-  if (!$ajax) {
-    db_query('INSERT INTO {quicktabs} (qtid, title, tabs) VALUES(%d, "%s", "%s")', $qtid, $title, $tabs);
-  } else {
-    db_query('INSERT INTO {quicktabs} (qtid, ajax, title, tabs) VALUES(%d, 1, "%s", "%s")', $qtid, $title, $tabs);
-  }
-  return; 
+  $title = $fullcontent['title'];
+  $style = $fullcontent['style'];
+  $ajax = $fullcontent['ajax'];
+  $tabs = serialize($fullcontent['tabs']);
+
+  db_query("INSERT INTO {quicktabs} (qtid, ajax, title, tabs, style) VALUES (%d, %d, '%s', '%s', '%s')", $qtid, $ajax, $title, $tabs, $style);
 }
 
+/**
+ * Update db record.
+ */
 function quicktabs_updateblock($qtid, $fullcontent) {
-  $title = $fullcontent['blocktitle'];
-  $tabs = serialize($fullcontent['blockcontent']);
-  db_query("UPDATE {quicktabs} SET title='%s', tabs='%s' WHERE qtid=%d", $title, $tabs, $qtid);
-  return; 
-}
-
-function quicktabs_block_edit($qtid) {
-  if ($qtblock = db_fetch_object(db_query('SELECT title, tabs, ajax FROM {quicktabs} WHERE qtid = %d', $qtid))) {
-    $tabs = unserialize($qtblock->tabs);
-    $formtabs = array();
-    foreach ($tabs as $key => $tab) {
-      $weight[$key]  = $tab['weight'];
-      $formtabs[] = array(
-        'tabweight' => $tab['weight'],
-        'tabtext' => $tab['title'],
-        'tabtype' => $tab['type'],
-        'bid' => ($qtblock->ajax == 0 ? ($tab['type'] == 'block' ? $tab['bvid'] : NULL) : NULL),
-        'hide_title' => ($qtblock->ajax == 0 ? ($tab['type'] == 'block' ? $tab['hide_title'] : NULL) : NULL),
-        'nid' => ($qtblock->ajax == 1 ? ($tab['type'] == 'node' ? $tab['bnid'] : NULL) : NULL),
-        'vid' => $tab['type'] == 'view' ? ($qtblock->ajax == 0 ? $tab['bvid'] : $tab['bnid']) : NULL,
-        'args' => $tab['type'] == 'view' ? $tab['args'] : NULL,
-        'display' => $tab['type'] == 'view' ? $tab['display'] : NULL,
-      );
-    }
-    array_multisort($weight, SORT_ASC, $formtabs);
-
-    $quicktabs = array(
-      'qtid' => $qtid,
-      'title' => $qtblock->title,
-      'tabs' => $formtabs,
-      'formtype' => 'edit',
-    );
+  $title = $fullcontent['title'];
+  $style = $fullcontent['style'];
+  $ajax = $fullcontent['ajax'];
+  $tabs = serialize($fullcontent['tabs']);
 
-    drupal_add_js(drupal_get_path('module', 'quicktabs') .'/js/quicktabs_form.js');
-    drupal_add_css(drupal_get_path('module', 'quicktabs') .'/quicktabs.css');
-    if ($qtblock->ajax == 0) {
-      $output = drupal_get_form('quicktabs_form', $quicktabs);
-    } else {
-      $output = drupal_get_form('quicktabs_aj_form', $quicktabs);
-    }
-    return $output; 
-  }
-  else {
-    drupal_goto('admin/build/quicktabs');
-  }
+  db_query("UPDATE {quicktabs} SET ajax=%d, title='%s', tabs='%s', style='%s' WHERE qtid = %d", $ajax, $title, $tabs, $style, $qtid);
+  return;
 }
 
 /**
- * Deletion of Quick Tabs blocks.
+ * Create or edit Quick Tabs block.
  */
+function quicktabs_block_edit($quicktabs, $formtype) {
+  $quicktabs['formtype'] = $formtype; // formtype = add or edit
+  drupal_add_js(drupal_get_path('module', 'quicktabs') .'/js/quicktabs_form.js');
+  drupal_add_css(drupal_get_path('module', 'quicktabs') .'/quicktabs.css');
 
-
-function quicktabs_block_get_name($qtid) {
-  $result = db_result(db_query('SELECT title FROM {quicktabs} WHERE qtid=%d', $qtid));
-  return $result;
+  return drupal_get_form('quicktabs_form', $quicktabs);
 }
 
-function quicktabs_block_delete(&$form_state, $qtid = 0) {
-  $qt_name = quicktabs_block_get_name($qtid);
-  $form['qtid'] = array('#type' => 'hidden', '#value' => $qtid);
-  $form['qt_name'] = array('#type' => 'hidden', '#value' => $qt_name);
-  return confirm_form($form, t('Are you sure you want to delete the Quick Tabs block %name?', array('%name' => $qt_name)), 'admin/build/quicktabs', '', t('Delete'), t('Cancel'));
+/**
+ * Deletion of Quick Tabs blocks.
+ */
+function quicktabs_block_delete(&$form_state, $quicktabs) {
+  $form['qtid'] = array('#type' => 'hidden', '#value' => $quicktabs['qtid']);
+  $form['qt_name'] = array('#type' => 'hidden', '#value' => $quicktabs['title']);
+  return confirm_form($form, t('Are you sure you want to delete the Quick Tabs block %name?', array('%name' => $quicktabs['title'])), 'admin/build/quicktabs', '', t('Delete'), t('Cancel'));
 }
 
-function quicktabs_block_delete_submit($form, $form_state) {
+/**
+ * Submit handler for Quick Tabs blocks deletion.
+ */
+function quicktabs_block_delete_submit($form, &$form_state) {
   db_query('DELETE FROM {quicktabs} WHERE qtid = %d', $form_state['values']['qtid']);
   drupal_set_message(t('The Quick Tabs block %name has been removed.', array('%name' => $form_state['values']['qt_name'])));
   cache_clear_all();
-  drupal_goto('admin/build/quicktabs');
+  $form_state['redirect'] = 'admin/build/quicktabs';
 };
 
 /**
  * Callback function for admin/settings/quicktabs. Display the settings form.
  */
 function quicktabs_settings() {
-  $form = array();
+  $styles = module_invoke_all('quicktabs_tabstyles');
+  // The keys used for radios options must be valid html ids. Removing the path to css files.
+  foreach ($styles as $style) {
+    $options[drupal_strtolower($style)] = $style;
+  }
+
   $form['quicktabs_tabstyle'] = array(
     '#type' => 'radios',
     '#title' => t('Tab Style'),
-    '#options' => array('default' => t('Default (no style)')) + module_invoke_all('quicktabs_tabstyles'),
+    '#options' => array('default' => t('Default (no style)')) + $options,
     '#default_value' => variable_get('quicktabs_tabstyle', 'default'),
-    '#description' => t('Choose a tab style for your Quick Tabs blocks.'),
+    '#description' => t('Choose the default tab style for your Quick Tabs blocks.'),
     '#attributes' => array('class' => 'quicktabs-tabstyles clear-block'),
   );
   $form['submit'] = array(
-  '#type' => 'submit',
-  '#value' => t('Submit'),
-  ); 		
+   '#type' => 'submit',
+   '#value' => t('Save'),
+  );
   return $form;
 }
 
-function quicktabs_settings_submit($form, $form_state) {
+/**
+ * Submit handler for QuickTabs settings.
+ */
+function quicktabs_settings_submit($form, &$form_state) {
   variable_set('quicktabs_tabstyle', $form_state['values']['quicktabs_tabstyle']);
-  variable_set('quicktabs_blocktitles', $form_state['values']['quicktabs_blocktitles']);
-  //variable_set('quicktabs_viewbuild', $form_state['values']['quicktabs_viewbuild']);
 }
 
+/**
+ * Theme function for quicktabs settings page.
+ *
+ * @ingroup themeable
+ */
 function theme_quicktabs_settings($form) {
   quicktabs_add_css();
+  drupal_add_js(drupal_get_path('module', 'quicktabs') .'/js/quicktabs.js');
   drupal_set_title(t('Quick Tabs Settings'));
 
-  // Default preview.
-  $form['quicktabs_tabstyle']['default']['#description'] = 'Default '. t('Preview') .':<br /><iframe class="quicktabs-preview" scrolling="no" src="'. url('quicktabs/preview') .'"></iframe>';
-
   // Preview for each style.
-  $tabstyle_number = 0;
-  foreach (element_children($form['quicktabs_tabstyle']) as $tabstyle_key) {
-    if ($tabstyle_key != 'default') {
-      $form['quicktabs_tabstyle'][$tabstyle_key]['#description'] = $form['quicktabs_tabstyle'][$tabstyle_key]['#title'] .' '. t('Preview') .':<br /><iframe class="quicktabs-preview" scrolling="no" src="'. url('quicktabs/preview/'. $tabstyle_number) .'"></iframe>';
-      $tabstyle_number++;
-    }
-    
+  foreach (element_children($form['quicktabs_tabstyle']) as $style) {
+    $style_title = $form['quicktabs_tabstyle'][$style]['#title'];
+    $preview = '<iframe class="quicktabs-preview" scrolling="no" src="'. url('quicktabs/preview/'. $style) .'"></iframe>';
+    $form['quicktabs_tabstyle'][$style]['#description'] = $style_title .' '. t('Preview') .':<br />'. $preview;
   }
   return drupal_render($form);
 }
@@ -675,21 +607,33 @@ function theme_quicktabs_settings($form)
 /**
  * Callback function for quicktabs/preview.
  */
-function quicktabs_preview_page($tabstyle_number = NULL) {
-  $tabstyles = module_invoke_all('quicktabs_tabstyles');
-  $css_files = array_keys($tabstyles);
-  if (isset($css_files[$tabstyle_number])) {
-    quicktabs_add_css($css_files[$tabstyle_number]);
-  }
-  else {
-    quicktabs_add_css('default');
-  }
-  drupal_add_js(drupal_get_path('module', 'quicktabs') .'/js/quicktabs.js');
-  print theme('quicktabs_preview_page');
+function quicktabs_preview_page($style) {
+  print theme('quicktabs_preview_page', $style);
   exit;
 }
 
-function theme_quicktabs_preview_page() {
+/**
+ * Theme function for quicktabs preview page.
+ *
+ * @ingroup themeable
+ */
+function theme_quicktabs_preview_page($style) {
+  $tabs['one'] = array(
+    'title' => t('One'),
+    'type' => 'freetext',
+    'freetext' => array(
+      'text' => t('First tabpage'),
+    ),
+  );
+  $tabs['two'] = array(
+    'title' => t('Two'),
+    'type' => 'freetext',
+    'freetext' => array(
+      'text' => t('Second tabpage'),
+    ),
+  );;
+
+  $rendered_tabs = quicktabs_render($tabs, $style);
 
   $output = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n";
   $output .= '<html xmlns="http://www.w3.org/1999/xhtml">';
@@ -698,104 +642,35 @@ function theme_quicktabs_preview_page() 
   $output .= drupal_get_html_head();
   $output .= drupal_get_css();
   $output .= drupal_get_js();
-  $output .= ' </head>';
-  $output .= ' <body style="background: none; background-color: #fff; color: #000;" class="quicktabs_iframe">';
-  $output .= '<div class="quicktabs_wrapper">';
-  $output .= '<ul class="quicktabs_tabs"><li><a href="#">One</a></li><li><a href="#">Two</a></li></ul>';
-  $output .= '<div class="quicktabs_main"><div class="quicktabs"></div><div class="quicktabs"></div></div></div>';
-        
+  $output .= '</head>';
+  $output .= '<body style="background: none; background-color: #fff; color: #000;" class="quicktabs_iframe">';
+  $output .= $rendered_tabs;
   $output .= '</body></html>';
 
   return $output;
 }
 
-
-
-/**
- * Implementation of hook_quicktabs_widgets.
- * 
- * This hook allows other modules to create additional tab styles for
- * the quicktabs module.
- * 
- * @return array
- *   An array of key => value pairs suitable for inclusion as the #options in a
- *   select or radios form element. Each key must be the location of a css
- *   file for a quick tabs style. Each value should be the name of the style.
- */
-function quicktabs_quicktabs_tabstyles() {
-  $tabstyles_directory = drupal_get_path('module', 'quicktabs') .'/tabstyles';
-  $files = file_scan_directory($tabstyles_directory, '\.css$');
-
-  $tabstyles = array();
-  foreach ($files as $file) {
-    $tabstyles[$file->filename] = drupal_ucfirst($file->name);
-  }
-  return $tabstyles;
-}
-
-
-
 /**
- * Helper Functions
+ * Helper function to get all views.
  */
-
 function quicktabs_get_views() {
-  $result = db_query("SELECT v.name, v.description FROM {views_view} v");
-  $views = array();
-  while ($view = db_fetch_object($result)) {
-    $views[$view->name] = $view->name;
-  }
-  $status = variable_get('views_defaults', array());
-  foreach (_quicktabs_get_default_views_names() as $view) {
-    // Determine if default view is enabled or disabled.
-    if (isset($status[$view['name']])) {
-      $view['disabled'] = $status[$view['name']];
-    }
-    if (empty($views[$view['name']]) && $view['disabled'] != 1) {
-      $views[$view['name']] = $view['name'];
-    }
-  }
-  return $views;
-}
-
-function _quicktabs_get_default_views() {
-  views_include('view');
-  views_include_default_views();
-  $defaults = module_invoke_all('views_default_views');
-  $views = array();
-  foreach ($defaults as $name => $view) {
-    // Only views with a sufficiently high api version are eligible.
-    if (isset($view->api_version) && $view->api_version >= 2) {
-      $views[$name] = $view;
-    }
-  }
-  return $views;
-}
-
-function _quicktabs_get_default_views_names() {
-  $views = array();
-  foreach (_quicktabs_get_default_views() as $name => $view) {
-    $views[] = array(
-      'name' => $name,
-    );
-  }
-  return $views;
-}
+  $enabled_views = array();
+  $views = views_get_all_views();
 
-function _quicktabs_get_default_view_displays($selected_view) {
-  $displays = array();
-  foreach (_quicktabs_get_default_views() as $name => $view) {
-    if ($name == $selected_view) {
-      $display_array = $view->display;
-      foreach ($display_array as $key => $display) {
-        $displays[$key] = $key;
-      }
-      break;
+  foreach ($views as $view) {
+    // Skip disabled views.
+    if (!empty($views[$view->name]->disabled)) {
+      continue;
     }
+    $enabled_views[$view->name] = $view->name;
   }
-  return $displays;
+  ksort($enabled_views);
+  return $enabled_views;
 }
 
+/**
+ * Helper function to get all blocks.
+ */
 function quicktabs_get_blocks() {
   static $blocksarray;
   if (empty($blocksarray)) {
@@ -837,25 +712,27 @@ function quicktabs_get_blocks() {
   return $blocksarray;
 }
 
-function _quicktabs_get_views_displays($view) {
+/**
+ * Helper function to get all view displays.
+ */
+function _quicktabs_get_views_displays($view_name) {
   $displays = array();
-  $result = db_query("SELECT d.id FROM {views_view} v INNER JOIN {views_display} d ON v.vid = d.vid WHERE v.name = '%s' ORDER BY position ASC", $view);
-  while ($row = db_fetch_object($result)) {
-    $displays[$row->id] = $row->id;
+  if (empty($view_name)) {
+    // No view.
+    return $displays;
   }
-  if (empty($displays)) {
-    $displays = _quicktabs_get_default_view_displays($view);
+
+  $views = views_get_all_views();
+  $view = $views[$view_name];
+
+  if (empty($view->display)) {
+    // This view is broken.
+    return $displays;
+  }
+
+  foreach ($view->display as $id => $display) {
+    $displays[$id] = $id .': '. $display->display_title;
   }
   return $displays;
 }
 
-function quicktabs_get_nodes() {
-  $nodes = array();
-  // TODO: make the allowed node types an admin setting
-  $result = db_query('SELECT nid, title FROM {node} WHERE type in ("page", "story")');
-  while ($row = db_fetch_object($result)) {
-    $key = $row->nid;
-    $nodes[$key] = $row->title;
-  }
-  return $nodes;
-}
\ No newline at end of file
Index: js/quicktabs.js
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/quicktabs/js/quicktabs.js,v
retrieving revision 1.3.2.1
diff -u -p -r1.3.2.1 quicktabs.js
--- js/quicktabs.js	26 Nov 2008 06:12:25 -0000	1.3.2.1
+++ js/quicktabs.js	26 Nov 2008 17:43:03 -0000
@@ -1,3 +1,5 @@
+// $Id$
+
 Drupal.settings.views = Drupal.settings.views || {'ajax_path': 'views/ajax'};
 
 Drupal.behaviors.quicktabs = function (context) {
@@ -19,14 +21,24 @@ var quicktabsClick = function() {
   $(this).parents('li').siblings().removeClass('active');
   $(this).parents('li').addClass('active');
   if ( $(this).hasClass('qt_ajax_tabs') ) {
-    var viewDetails = this.id.split('-');
+    var viewDetails = this.id.split('--');
     var $container = $('div#quicktabs_ajax_container_' + viewDetails[1]);
-    if (viewDetails[0] == 'node') {
-      $.get(Drupal.settings.basePath + 'quicktabs/ajax/node/' + viewDetails[3], null, function(data){
+    switch (viewDetails[0]) {
+    case 'node':
+      $.get(Drupal.settings.basePath + 'quicktabs/ajax/node/' + viewDetails[3] + '/' + viewDetails[4] + '/' + viewDetails[5], null, function(data){
+        var result = Drupal.parseJson(data);
+        $container.html(result['data']);
+      });
+      break;
+
+    case 'block':
+      $.get(Drupal.settings.basePath + 'quicktabs/ajax/block/' + viewDetails[3] + '/' + viewDetails[4], null, function(data){
         var result = Drupal.parseJson(data);
         $container.html(result['data']);
       });
-    } else {
+      break;
+
+    case 'view':
       var target;
       target = $('div#quicktabs_ajax_container_' + viewDetails[1] + ' > div');
       var ajax_path = Drupal.settings.views.ajax_path;
Index: js/quicktabs_form.js
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/quicktabs/js/quicktabs_form.js,v
retrieving revision 1.5.2.1
diff -u -p -r1.5.2.1 quicktabs_form.js
--- js/quicktabs_form.js	26 Nov 2008 06:12:25 -0000	1.5.2.1
+++ js/quicktabs_form.js	26 Nov 2008 15:01:03 -0000
@@ -1,48 +1,41 @@
+// $Id$
+
 Drupal.quicktabsShowHide = function() {
-  if (this.value == 'block' || this.value == 'node') {
-    $(this).parents('tr')
-    .find('div.form-item :input[name*="vid"]').parent().hide();
-    $(this).parents('tr')
-    .find('div.form-item :input[name*="args"]').parent().hide();
-    $(this).parents('tr')
-    .find('div.form-item :input[name*="display"]').parent().hide();  
-    $(this).parents('tr')
-    .find('div.form-item :input[name*="bid"]').parent().show();    
-    $(this).parents('tr')
-    .find('div.form-item :input[name*="hide_title"]').parent().show();
-    $(this).parents('tr')
-    .find('div.form-item :input[name*="nid"]').parent().show(); 
- } else {
-    $(this).parents('tr')
-    .find('div.form-item :input[name*="nid"]').parent().hide(); 
-    $(this).parents('tr')
-    .find('div.form-item :input[name*="bid"]').parent().hide();
-    $(this).parents('tr')
-    .find('div.form-item :input[name*="hide_title"]').parent().hide(); 
-    $(this).parents('tr')
-    .find('div.form-item :input[name*="vid"]').parent().show();
-    $(this).parents('tr')
-    .find('div.form-item :input[name*="args"]').parent().show(); 
-    $(this).parents('tr')
-    .find('div.form-item :input[name*="display"]').parent().show();  
+  switch (this.value) {
+    case 'block':
+      $(this).parents('tr')
+      .find('td.qt-tab-block-content').show();
+      $(this).parents('tr')
+      .find('td.qt-tab-node-content').hide();
+      $(this).parents('tr')
+      .find('td.qt-tab-view-content').hide();
+      break;
+
+    case 'node':
+      $(this).parents('tr')
+      .find('td.qt-tab-block-content').hide();
+      $(this).parents('tr')
+      .find('td.qt-tab-node-content').show();
+      $(this).parents('tr')
+      .find('td.qt-tab-view-content').hide();
+      break;
 
- }
+    case 'view':
+      $(this).parents('tr')
+      .find('td.qt-tab-block-content').hide();
+      $(this).parents('tr')
+      .find('td.qt-tab-node-content').hide();
+      $(this).parents('tr')
+      .find('td.qt-tab-view-content').show();
+      break;
+  }
 };
 
 Drupal.behaviors.quicktabsform = function(context) {
-  $('#quicktabs-form tr, #quicktabs-aj-form tr').not('.quicktabs-form-processed').addClass('quicktabs-form-processed').each(function(){
+  $('#quicktabs-form tr, #quicktabs-aj-form tr').not('.quicktabs-form-processed').addClass('quicktabs-form-processed').each(function() {
     var currentRow = $(this);
-    $(':input[name*="tabtype"]:checked', this).each(function(){
-      if(this.value == 'block' || this.value == 'node') {
-        currentRow.find('div.form-item :input[name*="vid"]').parent().hide();
-        currentRow.find('div.form-item :input[name*="args"]').parent().hide();
-        currentRow.find('div.form-item :input[name*="display"]').parent().hide(); 
-      } else {
-        currentRow.find('div.form-item :input[name*="bid"]').parent().hide();
-        currentRow.find('div.form-item :input[name*="hide_title"]').parent().hide();
-        currentRow.find('div.form-item :input[name*="nid"]').parent().hide();
-      }
-    });
-    currentRow.find('div.form-item :input[name*="tabtype"]').bind('click', Drupal.quicktabsShowHide);
+    currentRow.find('div.form-item :input[name*="type"]').bind('click', Drupal.quicktabsShowHide);
+
+    $(':input[name*="type"]:checked', this).trigger('click');
   })
-};
\ No newline at end of file
+};
