var EXPORTED_SYMBOLS = ["Tracker"];

const Cu = Components.utils;
const Cc = Components.classes;
const Ci = Components.interfaces;

Cu.import("resource://gre/modules/XPCOMUtils.jsm");

XPCOMUtils.defineLazyGetter(this, "utils", function() {
  let obj = { };
  Cu["import"]("resource://livemargins/utils.jsm", obj);
  return obj.utils;
});

XPCOMUtils.defineLazyGetter(this, "window", function() {
  return Cc["@mozilla.org/appshell/appShellService;1"]
       .getService(Ci.nsIAppShellService)
       .hiddenDOMWindow;
});

var _trackurl = 'http://addons.g-fox.cn/appcenter.gif';
Tracker = {
  view: {
    type: 0,
    actions: {
      SWITCH_VIEW:   "001",
      OPEN_APPCENTER:  "002",
    }
  },

  app: {
    type: 1,
    actions: {
      OPEN_APP:    101,
      CHANGE_NAME:   102,
      SEARCH_APP:    103,
      DRAG_APP:    104,
      REMOVE_APP:    105,
      COMMENT_APP:   106,
      BOOKMARK_APP:  107,
      CLEAR_HISTORY:   108,
      REMOVE_HISTORY:  109
    }
  },

  click: {
    type: 2,
    actions: {
      CLICK_APP_WIN_BTN: 201,
      CLICK_XUL_BTN:   202,
    }
  },

  intent: {
     type: 3,
     actions: {
       OPEN_INENT:  301,
       HIDE_PIE_ICON: 302,
       SHOW_PIE_ICON: 303,
       CUSTOMIZE:   304
     }
  },

  snapshot: {
    type: 4,
    actions: {
      SNAP:   401,
      POST:   402,
      EDITOR: 403,
    }
  },

  track: function(type, action, tid, extra) {
    // ignore minimize and close button
    switch (tid) {
    case "favpart-minimize-button":
    case "favpart-close-button":
      return;
    }

    if (utils.getPref("feedback.enable")) {
      var img = new window.Image();
      img.src = _trackurl + "?t=" + type + "&a=" +
            action + "&d=" + encodeURIComponent(tid) +
            (typeof extra !== "undefined" ? ("&e=" + extra) : "") +
            "&r=" + Math.random() +
            "&cid=" + utils.getPrefFromRoot("app.chinaedition.channel", "www.firefox.com.cn");
    }
  }
};
