var current_cost_duration = null;

function change_cost(duration) {
  // update menu text
  var first = duration.charAt(0).toUpperCase();
  var text = first + duration.substr(1);
  $("#cost-dropdown .dropdown-toggle .text").text("Cost: "+text);

  // update selected menu option
  $('#cost-dropdown li a').each(function(i, e) {
    e = $(e);
    if (e.attr('duration') == duration) {
      e.parent().addClass('active');
    } else {
      e.parent().removeClass('active');
    }
  });

  var hour_multipliers = {
    "hourly": 1,
    "daily": 24,
    "weekly": (7*24),
    "monthly": (24*30),
    "yearly": (365*24)
  };
  var multiplier = hour_multipliers[duration];
  var per_time;
  $.each($("td.cost"), function(i, elem) {
    elem = $(elem);
    per_time = elem.attr("hour_cost");
    per_time = (per_time * multiplier).toFixed(2);
    elem.text("$" + per_time + " " + duration);
  });

  current_cost_duration = duration;
}

function column_toggle_setup() {
  // get column headings, add to filter button
  $.each($("#data thead tr th"), function(i, elem) {
    $("#filter-dropdown ul").append("<li class=\"active\"><a href=\"javascript:;\" onclick=\"fnShowHide("+i+");\">"+elem.innerText+"</a></li>");
  });

  // toggle column buttons
  $("#filter-dropdown ul.dropdown-menu li").bind("click", function(e) {
    $(this).toggleClass("active");
  });
}

$(function() {
  $(document).ready(function() {
    $('#data').dataTable({
      "bPaginate": false,
      "bInfo": false,
      "aoColumnDefs": [
        {
          "aTargets": ["memory", "computeunits", "storage", "ioperf"],
          "sType": "span-sort"
        }
      ],
      "fnDrawCallback": function() {
        // Whenever the table is drawn, update the costs. This is necessary
        // because the cost duration may have changed while a filter was being
        // used and so some rows will need updating.
        change_cost(current_cost_duration);
      }
    });
  });

  $.extend($.fn.dataTableExt.oStdClasses, {
    "sWrapper": "dataTables_wrapper form-inline"
  });

  change_cost('hourly');

  column_toggle_setup();
});

$("#cost-dropdown li").bind("click", function(e) {
  change_cost(e.target.getAttribute("duration"));
});

// sorting for colums with more complex data
// http://datatables.net/plug-ins/sorting#hidden_title
jQuery.extend(jQuery.fn.dataTableExt.oSort, {
  "span-sort-pre": function(elem) {
    var matches = elem.match(/sort="(.*?)"/);
    if (matches) {
      return parseInt(matches[1], 10);
    }
    return 0;
  },

  "span-sort-asc": function(a, b) {
    return ((a < b) ? -1 : ((a > b) ? 1 : 0));
  },

  "span-sort-desc": function(a, b) {
    return ((a < b) ? 1 : ((a > b) ? -1 : 0));
  }
});

// toggle columns
function fnShowHide(iCol) {
  var oTable = $('#data').dataTable();
  var bVis = oTable.fnSettings().aoColumns[iCol].bVisible;
  oTable.fnSetColumnVis( iCol, bVis ? false : true );
}
@@ -934,16 +934,22 @@
 unction 
+setup_
 column_t
@@ -953,22 +953,16 @@
 n_toggle
-_setup
 () %7B%0A  /
@@ -1098,39 +1098,76 @@
 end(
-%22%3Cli 
+%0A      $('%3Cli%3E', %7B
 class
-=%5C
+: 
 %22active
-%5C%22%3E%3Ca 
+%22%7D).append(%0A        $('%3Ca%3E', %7B
 href
-=%5C
+: 
 %22jav
@@ -1179,165 +1179,61 @@
 pt:;
-%5C%22 onclick=%5C%22fnShowHide(%22+i+%22);%5C%22%3E%22+elem.innerText+%22%3C/a%3E%3C/li%3E%22);%0A  %7D);%0A%0A  // toggle column buttons%0A  $(%22#filter-dropdown ul.dropdown-menu li%22).bind(%22
+%22%7D)%0A          .text($(elem).text())%0A          .
 click
-%22, 
+(
 func
@@ -1250,36 +1250,247 @@
     
-$(this).toggleClass(%22active%22
+        toggle_column(i);%0A            $(this).parent().toggleClass(%22active%22);%0A            $(this).blur(); // prevent focus style from sticking in Firefox%0A            e.stopPropagation(); // keep dropdown menu open%0A          %7D)%0A      )%0A    
 );%0A 
@@ -2215,16 +2215,22 @@
 y');%0A%0A  
+setup_
 column_t
@@ -2238,14 +2238,8 @@
 ggle
-_setup
 ();%0A
@@ -2874,23 +2874,31 @@
 ion 
-fnShowHide(iCol
+toggle_column(col_index
 ) %7B%0A
@@ -2903,18 +2903,17 @@
 %7B%0A  var 
-oT
+t
 able = $
@@ -2945,17 +2945,22 @@
 var 
-bV
 is
+_visible
  = 
-oT
+t
 able
@@ -2983,20 +2983,25 @@
 Columns%5B
-iCol
+col_index
 %5D.bVisib
@@ -3010,10 +3010,9 @@
 ;%0A  
-oT
+t
 able
@@ -3031,19 +3031,29 @@
 Vis(
- iCol, bVis
+col_index, is_visible
  ? f
@@ -3063,13 +3063,12 @@
 e : true
- 
 );%0A%7D

Clean column toggle and fix for Firefox