AppNotification = function(message) {
    var self = this;
    this.$appNotification = $("#appNotification");
    this.message = message;
    this.displayTime = 5000; // 5 seconds notification time
    
    this.findContent = function() {
      content = self.$appNotification.find(".center").text();
      if (content.trim().length > 1) {
          return content;
      } else {
          return false;
      }
    };
    
    this.show = function(message) {
        var notification = message || self.message;
        self.$appNotification.find(".center").html(notification);
        self.$appNotification.fadeIn();
    };
    
    this.setContent = function(message) {
        self.$appNotification.find(".center").text(message);
    };
    
    this.saving = function(message) {
        var notification = message || 'Saving...';
        self.show(notification);
    };
    
    this.startUploading = function(message) {
        var notification = message || 'Uploading';
        self.show(notification);
        var length = notification.length;
        self.interval = window.setInterval(function() {
           var text = self.findContent();
           if (text.length < (length + 3)) {
               self.setContent(text + '.');
           } else {
               self.setContent(notification);
           }
        }, 400);
    };
    
    this.stopUploading = function() {
        clearInterval(self.interval);
    };
    
    this.hide = function() {
      self.$appNotification.fadeOut();
    };
    
    this.success = function(message) {
        self.$appNotification.find(".center").html(message);
        self.$appNotification.show();
        var hide = function() { self.hide(); };
        setTimeout(hide, self.displayTime);
    };

    this.error = function(message) {
        self.$appNotification.find(".center").html(message);
        self.$appNotification.show();
        var hide = function() { self.hide(); };
        setTimeout(hide, self.displayTime);
    };
};




