// Generated by CoffeeScript 1.7.1
(function() {
  var AjentiNotification, Notificator,
    __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };

  AjentiNotification = (function() {
    function AjentiNotification(type, text, timeout, notificator, position) {
      this.type = type;
      this.text = text;
      this.timeout = timeout;
      this.notificator = notificator;
      this.position = position;
      this.moveUp = __bind(this.moveUp, this);
      this.remove = __bind(this.remove, this);
      this.dom = $("<div class=\"notification " + this.type + "\">\n    " + this.text + "\n</div>");
      this.active = true;
      this.position = 0;
      this.dom.css({
        top: this.position + 'px',
        left: '300px'
      });
      this.dom.animate({
        left: '0px'
      }, 500, 'swing');
      setTimeout(this.remove, this.timeout);
    }

    AjentiNotification.prototype.remove = function() {
      this.dom.animate({
        left: '300px'
      }, 500, 'swing');
      return setTimeout(function() {
        this.notificator.notifications.pop(this);
        return this.dom.remove();
      }, 500);
    };

    AjentiNotification.prototype.moveUp = function(dy) {
      this.position -= dy;
      return this.dom.animate({
        top: this.position + 'px'
      }, 500, 'swing');
    };

    return AjentiNotification;

  })();

  Notificator = (function() {
    function Notificator() {
      this.notifications = [];
      this.browserNotifications = false;
      if (window.Notification) {
        if (Notification.permission === 'granted') {
          this.browserNotifications = 'html5';
        } else {
          if (Notification.permission !== 'denied') {
            Notification.requestPermission((function(_this) {
              return function(permission) {
                if (!Notification.permission) {
                  Notification.permission = permission;
                }
                if (permission === "granted") {
                  return _this.browserNotifications = 'html5';
                }
              };
            })(this));
          }
        }
      }
    }

    Notificator.prototype.notify = function(type, text, timeout) {
      var notification, _fn, _i, _len, _ref;
      if (this.browserNotifications === 'html5') {
        new Notification(text);
        return;
      }
      if (timeout == null) {
        timeout = 7000;
      }
      _ref = this.notifications;
      _fn = (function(_this) {
        return function(notification) {
          return notification.moveUp(-50);
        };
      })(this);
      for (_i = 0, _len = _ref.length; _i < _len; _i++) {
        notification = _ref[_i];
        _fn(notification);
      }
      notification = new AjentiNotification(type, text, timeout, this, 0);
      this.notifications.push(notification);
      return $('#notifications').append(notification.dom);
    };

    return Notificator;

  })();

  window.Notificator = new Notificator();

}).call(this);
