/*   Copyright (c) 2010, Diaspora Inc.  This file is
*   licensed under the Affero General Public License version 3 or later.  See
*   the COPYRIGHT file.
*/

(function() {
  if(typeof window.Diaspora !== "undefined") {
    return;
  }

  var Diaspora = { };

  Diaspora.WidgetCollection = function() {
    this.initialized = false;
    this.collection = { };
    this.eventsContainer = $({});
  };

  Diaspora.WidgetCollection.prototype.add = function(widgetId, widget) {
    this[widgetId] = this.collection[widgetId] = new widget();
    if(this.initialized) {
      this.collection[widgetId].start();
    }
  };

  Diaspora.WidgetCollection.prototype.remove = function(widgetId) {
    delete this.collection[widgetId];
  };

  Diaspora.WidgetCollection.prototype.init = function() {
    this.initialized = true;

    for(var widgetId in this.collection) {
      if(this.collection[widgetId].hasOwnProperty("start")
          || this.collection[widgetId].__proto__.hasOwnProperty("start")) {
        this.collection[widgetId].start();
      }
    }
  };

  Diaspora.WidgetCollection.prototype.subscribe = function(id, callback) {
    this.eventsContainer.bind(id, callback);
  };

  Diaspora.WidgetCollection.prototype.publish = function(id) {
    this.eventsContainer.trigger(id);
  };

  Diaspora.widgets = new Diaspora.WidgetCollection();

  window.Diaspora = Diaspora;
})();


$(document).ready(function() { Diaspora.widgets.init(); });


@@ -857,24 +857,31 @@
  %7B%0A      if(
+typeof 
 this.collect
@@ -898,104 +898,29 @@
 Id%5D.
-hasOwnProperty(%22start%22)%0A          %7C%7C this.collection%5BwidgetId%5D.__proto__.hasOwnProperty(%22start%22)
+start !== %22undefined%22
 ) %7B%0A

use typeof operand instead of object#hasOwnProperty