var myList;
var myOrder;

settings.prototype.filters = function () {

$('#main-container-left-header').html('&nbsp;');
$('#main-container-left-footer').html('&nbsp;');

var aheader = ajax_loader({filter: this.filter, tab: this.tab}, "app/settings/settings-filter-right-header.php", "main-container-right-header");
var abody = ajax_loader({filter: this.filter, tab: this.tab}, "app/settings/settings-filter-right-body.php", "main-container-right-body");

  $.when(abody).then(function () {
    /* Has plugin loaded yet */
    if(jQuery().sortable) {
      if (typeof myList == 'object') {
        myList.sortable("destroy");
      }
      do_sort(); 
    } else {
      $.getScript('assets/js/jquery-sortable-min.js')
        .done(function (script, textStatus) {
            do_sort();          
        });
    }
  });  
};

function do_sort() {
  myList = $("#statusFilter-list").sortable({
      handle : '.handle',
      onDrop: function ($item, container, _super) {
        var data = myList.sortable("serialize").get();
        var order = '';
        var a = data[0];
        for (i = 0; i < a.length; i++) {
          var item = a[i];
          var number = item.listitem;
          order += 'listItem[]=' + number + '&';
         }
         myOrder = order; 
        _super($item, container);
      }
    });                  
}

function save_order() {
  if (myOrder != null) {
    $.get("/dev/app/settings/settings-filter-order.php?"+myOrder, function(data, status) {
      alert(data);
    });
  }
}