function hReviewAggregate(node) {
  if (node) {
    Microformats.parser.newMicroformat(this, node, "hReviewAggregate");
  }
}
hReviewAggregate.prototype.toString = function() {
  var fn;
  if (this.item) {
    if (this.item.summary) {
      fn = this.item.summary
    } else if (this.item.fn) {
      fn = this.item.fn;
    }
    return fn;
  }
}

var hReviewAggregate_definition = {
  mfVersion: 0.8,
  description: "Review Aggregate",
  mfObject: hReviewAggregate,
  className: "hreview-aggregate",
  required: ["item"],
  properties: {
    "item" : {
      datatype: "custom",
      customGetter: function(propnode) {
        var item;
        if (propnode.className.match("(^|\\s)" + "vcard" + "(\\s|$)")) {
          item = new hCard(propnode);
        } else if (propnode.className.match("(^|\\s)" + "vevent" + "(\\s|$)")) {
          item = new hCalendar(propnode);
        } else {
          item = {};
          var fns = Microformats.getElementsByClassName(propnode, "fn");
          if (fns.length > 0) {
            item.fn = Microformats.parser.defaultGetter(fns[0]);
          }
        }
		var urls = Microformats.getElementsByClassName(propnode, "url");
          if (urls.length > 0) {
            item.url = Microformats.parser.uriGetter(urls[0]);
          }
        /* Only return item if it has stuff in it */
        for (var i in item) {
          return item;
        }
        return;
      }
    },
	"rating" : {
      datatype: "float"
    },
	"average" : {
      datatype: "float"
    },
    "count" : {
      datatype: "float"
    },
    "summary" : {
    }
  },
  validate: function(node, error) {
    var errormsg;
    var item = Microformats.parser.getMicroformatProperty(node, "hReviewAggregate", "item");
    if (item) {
      if (item instanceof hCard) {
        if (!item.fn) {
          errormsg =  "No fn specified on the hCard for the item";
        }
      } else if (!(item instanceof hCalendar)) {
        if (!item.fn) {
          /* This is a common error case, so I'd like to report it */
          var items = Microformats.getElementsByClassName(node, "item");
          if (items[0].className.match("fn")) {
            errormsg = "fn should be a child of item";
          }
          errormsg = "No fn specified on the item";
        }
      }
    } else {
      var items = Microformats.getElementsByClassName(node, "item");
      if (items.length > 0) {
        if (items[0].className.match("fn")) {
          errormsg = "fn should be a child of item";
        } else {
          errormsg = "No fn specified on the item";
        }
      } else {
        errormsg = "No item specified";
      }
    }
    if (errormsg) {
      if (error) {
        error.message = errormsg;
      }
      return false;
    } else {
      return true;
    }
  }
};

Microformats.add("hReviewAggregate", hReviewAggregate_definition);

var hreviewaggregate_firefox_bookmark = {
  scope: {
    semantic: {
      "hReviewAggregate" : "hReviewAggregate",
    }
  }
};

var hreviewaggregate_google_search = {
  scope: {
    semantic: {
      "hReviewAggregate" : "item.fn"
    }
  }
};

var hreviewaggregate_yahoo_search = {
  scope: {
    semantic: {
      "hReviewAggregate" : "item.fn"
    }
  }
};

SemanticActions.add("firefox_bookmark", hreviewaggregate_firefox_bookmark);
SemanticActions.add("google_search", hreviewaggregate_google_search);
SemanticActions.add("yahoo_search", hreviewaggregate_yahoo_search);

