function showError(message) {
  alert(message); // TODO
}

function formatSeconds(duration) {
  var hours = Math.floor(duration / 3600);
  var minutes = Math.floor(duration / 60) - (hours * 60);
  var seconds = Math.round(duration - (hours * 3600) - (minutes * 60));
  if(hours < 10) {
    hours = '0' + hours;
  }
  if(minutes < 10) {
    minutes = '0' + minutes;
  }
  if(seconds < 10) {
    seconds = '0' + seconds;
  }
  return hours + ':' + minutes + ':' + seconds;
}

function formatBytes(bytes)
{
  if(bytes) {
    var s = new Array('Bytes', 'KB', 'MB', 'GB', 'TB', 'PB');
    var e = Math.floor(Math.log(bytes) / Math.log(1024));
    var p = bytes / Math.pow(1024, Math.floor(e));
    //var r = Math.round(p * 100) / 100;
    return p.toFixed(2) + ' ' + s[e];
  } else {
    return '0 Bytes';
  }
}

(function($) {
  $.widget('ui.animatedProgressBar', $.ui.progressbar, {
    _refreshValue: function() {
      var self = this;
      self.valueDiv.animate({width: [self.value() + '%', 'swing']}, 'slow', function() {
        $.ui.progressbar.prototype._refreshValue.call(self);
      });
    }
  });
})(jQuery);

$(function() {
  $('body').ajaxError(function(e, xhr, settings, exception){
    var data = $.parseJSON(xhr.responseText);
    if(data && data.error) {
      alert(data.error.message);
    }
  });
});
