/* ---- fashion index tablesorter widgets ---- */
/**
 * updates Num column
 */
$.tablesorter.addWidget({
    id: "updateNumField",
    format: function(table) {
      $(" .numField",table).each(function(index){
        $(this).html(index+1);
      });
    }
});

/**
 * retreive page name from <a> tag
 */
$.tablesorter.addParser({
    id: 'getPageNameFromTag',
    is: function(s) {
        return false;
    },
    format: function(s) {
      var rgx = /<a[^>]*>(.*?)<\/a>/;
      arr = s.match(rgx);
      return (arr)?arr[1]:s;
    },
    type: 'text'
});

/**
 * remove commas from number of fans before sorting
 */
$.tablesorter.addParser({
    id: 'formatNumFuns',
    is: function(s) {
        return false;
    },
    format: function(s) {
      var rgx = /,/g;
      return s.replace(rgx, '');
    },
    type: 'numeric'
});

/**
 * remove percentage from sort changes before sorting
 */
$.tablesorter.addParser({
    id: 'formatSortChanges',
    is: function(s) {
        return false;
    },
    format: function(s) {
      var rgx = /%/;
      return (s!="" && s.indexOf("New!") == -1)?s.replace(rgx, ''):-99; // "New!" label defined in chart controller.
                                                                        // 'sort change' can be negative, but "New!" brand 'sort change' should be less than other values,
                                                                        // that's why it's set to -99
    },
    type: 'numeric'
});