define([
  'app'
  ], function (App) {
    "use strict";
    // this module provides generic methods usable across all gadgets/modules
    var that = {};

    // Javascript closest()
    that.closest = function (elem, selector) {
      var matchesSelector = elem.matches ||
          elem.webkitMatchesSelector ||
          elem.mozMatchesSelector ||
          elem.msMatchesSelector,
        fallback;

      if (matchesSelector) {
        while (elem) {
          if (matchesSelector.bind(elem)(selector)) {
              return elem;
          } else {
              elem = elem.parentNode;
          }
        }
        return false;
      } else {
        // opera...
        fallback = $( elem ).closest(selector);
        if (fallback.length > 0) {
          return fallback;
        }
        return false;
      }
    };
    // object size
    that.objectSize = function (obj) {
      var size = 0, key;

      for (key in obj) {
        if (obj.hasOwnProperty(key)) {
          size++;
        }
      }
      return size;
    };

    App.util = that;

    return undefined;
  }
);