var wave = wave || {};
wave.Callback = function(a, b) {
  this.callback_ = a;
  this.context_ = b || null
};
wave.Callback.prototype.invoke = function() {
  this.callback_ && this.callback_.apply(this.context_, arguments)
};
wave.Mode = {UNKNOWN:0, VIEW:1, EDIT:2, DIFF_ON_OPEN:3, PLAYBACK:4};
wave.API_PARAM_ = "wave";
wave.ID_PARAM_ = "waveId";
wave.id_ = null;
wave.viewer_ = null;
wave.host_ = null;
wave.participants_ = [];
wave.participantMap_ = {};
wave.participantCallback_ = new wave.Callback(null);
wave.state_ = null;
wave.stateCallback_ = new wave.Callback(null);
wave.privateState_ = null;
wave.privateStateCallback_ = new wave.Callback(null);
wave.mode_ = null;
wave.modeCallback_ = new wave.Callback(null);
wave.inWaveContainer_ = !1;
gadgets.window = gadgets.window || {};
(function() {
  function a(a, b) {
    var e = window.getComputedStyle(a, ""), e = e.getPropertyValue(b);
    e.match(/^([0-9]+)/);
    return parseInt(RegExp.$1, 10)
  }
  var b;
  gadgets.window.adjustWidth = function(d) {
    var c = parseInt(d, 10), d = !1;
    if(isNaN(c)) {
      var d = !0, e = gadgets.window.getViewportDimensions().width, f = document.body, g = document.documentElement;
      if(document.compatMode === "CSS1Compat" && g.scrollWidth) {
        c = g.scrollWidth !== e ? g.scrollWidth : g.offsetWidth
      }else {
        if(navigator.userAgent.indexOf("AppleWebKit") >= 0) {
          e = 0;
          for(f = [document.body];f.length > 0;) {
            g = f.shift();
            g = g.childNodes;
            for(c = 0;c < g.length;c++) {
              var h = g[c];
              if(typeof h.offsetLeft !== "undefined" && typeof h.scrollWidth !== "undefined") {
                var i = h.offsetLeft + h.scrollWidth + a(h, "margin-right"), e = Math.max(e, i)
              }
              f.push(h)
            }
          }
          c = e + a(document.body, "border-right") + a(document.body, "margin-right") + a(document.body, "padding-right")
        }else {
          if(f && g) {
            c = g.scrollWidth;
            h = g.offsetWidth;
            if(g.clientWidth !== h) {
              c = f.scrollWidth, h = f.offsetWidth
            }
            c = c > e ? c > h ? c : h : c < h ? c : h
          }
        }
      }
    }
    c !== b && !isNaN(c) && !(d && c === 0) && (b = c, gadgets.rpc.call(null, "setIframeWidth", null, c))
  }
})();
wave.Participant = function(a, b, d) {
  this.id_ = a || "";
  this.displayName_ = b || "";
  this.thumbnailUrl_ = d || ""
};
wave.Participant.prototype.getId = function() {
  return this.id_
};
wave.Participant.prototype.getDisplayName = function() {
  return this.displayName_
};
wave.Participant.prototype.getThumbnailUrl = function() {
  return this.thumbnailUrl_
};
wave.Participant.fromJson_ = function(a) {
  var b = new wave.Participant;
  b.id_ = a.id;
  b.displayName_ = a.displayName;
  b.thumbnailUrl_ = a.thumbnailUrl;
  return b
};
wave.State = function(a) {
  this.setState_({});
  this.rpc_ = a === void 0 ? "wave_gadget_state" : a
};
wave.State.prototype.get = function(a, b) {
  if(a in this.state_) {
    return this.state_[a]
  }
  return b === void 0 ? null : b
};
wave.State.prototype.getKeys = function() {
  var a = [], b;
  for(var d in this.state_) {
    d.match(/___$/) || (b = d, a.push(b))
  }
  return a
};
wave.State.prototype.getMeta = function(a, b, d) {
  if(a in this.meta_) {
    a = this.meta_[a];
    if(b != void 0) {
      return a[b]
    }
    return a
  }
  return d === void 0 ? null : d
};
wave.State.prototype.submitDelta = function(a) {
  gadgets.rpc.call(null, this.rpc_, null, a)
};
wave.State.prototype.submitValue = function(a, b) {
  var d = {};
  d[a] = b;
  this.submitDelta(d)
};
wave.State.prototype.reset = function() {
  var a = {}, b;
  for(var d in this.state_) {
    d.match(/___$/) || (b = d, a[b] = null)
  }
  this.submitDelta(a)
};
wave.State.prototype.toString = function() {
  return wave.util.printJson(this.state_, !0)
};
wave.State.prototype.setState_ = function(a) {
  this.state_ = {};
  this.meta_ = {};
  this.applyDelta_(a)
};
wave.State.prototype.calculateDelta_ = function(a) {
  var b = {}, d;
  for(var c in a) {
    if(!c.match(/___$/)) {
      d = c;
      var e = this.state_.hasOwnProperty(d);
      if(!e || this.state_[d] != a[d]) {
        b[d] = a[d]
      }
    }
  }
  for(var f in this.state_) {
    f.match(/___$/) || (d = f, a.hasOwnProperty(d) || (b[d] = null))
  }
  return b
};
wave.State.prototype.applyDelta_ = function(a) {
  this.state_ = this.state_ || {};
  var b;
  for(var d in a) {
    if(!d.match(/___$/)) {
      b = d;
      var c = a[b];
      c != null && c.value !== null ? typeof c == "string" || typeof c == "number" ? this.state_[b] = c : typeof c.charAt == "function" ? this.state_[b] = c.valueOf() : (this.meta_[b] = c, this.state_[b] = c.value) : (delete this.state_[b], delete this.meta_[b])
    }
  }
};
var tamings___ = tamings___ || [], caja___, ___;
tamings___.push(function(a) {
  function b(a, b) {
    var e = {apply:___.markFuncFreeze(function(f, e) {
      return ___.callPub(a, "apply", [b, e])
    })};
    return new wave.Callback(e, ___.USELESS)
  }
  ___.grantRead(wave, "Mode");
  b.prototype = wave.Callback.prototype;
  wave.Callback.prototype.constructor = b;
  ___.markCtor(b, Object, "Callback");
  ___.primFreeze(b);
  ___.tamesTo(wave.Callback, b);
  ___.handleGenericMethod(b.prototype, "invoke", function() {
    return ___.callPub(this.callback_, "apply", [___.tame(this.context_), Array.slice(arguments, 0)])
  });
  caja___.whitelistCtors([[wave, "Participant", Object], [wave, "State", Object]]);
  caja___.whitelistMeths([[wave.Participant, "getDisplayName"], [wave.Participant, "getId"], [wave.Participant, "getThumbnailUrl"], [wave.State, "get"], [wave.State, "getKeys"], [wave.State, "reset"], [wave.State, "submitDelta"], [wave.State, "submitValue"], [wave.State, "toString"]]);
  caja___.whitelistFuncs([[wave, "getHost"], [wave, "getMode"], [wave, "getParticipantById"], [wave, "getParticipants"], [wave, "getState"], [wave, "getTime"], [wave, "getViewer"], [wave, "isInWaveContainer"], [wave, "log"], [wave, "setModeCallback"], [wave, "setParticipantCallback"], [wave, "setStateCallback"], [wave.util, "printJson"]]);
  a.outers.wave = ___.tame(wave);
  ___.grantRead(a.outers, "wave")
});
wave.util = wave.util || {};
wave.util.SPACES_ = "                                                 ";
wave.util.toSpaces_ = function(a) {
  return wave.util.SPACES_.substring(0, a * 2)
};
wave.util.isArray_ = function(a) {
  try {
    return a && typeof a.length == "number"
  }catch(b) {
    return!1
  }
};
wave.util.printJson = function(a, b, d) {
  if(!a || typeof a.valueOf() != "object") {
    if(typeof a == "string") {
      return"'" + a + "'"
    }else {
      if(a instanceof Function) {
        return"[function]"
      }
    }
    return"" + a
  }
  var c = [], e = wave.util.isArray_(a), f = e ? "[]" : "{}", g = b ? "\n" : "", h = b ? " " : "", i = 0, d = d || 1;
  b || (d = 0);
  c.push(f.charAt(0));
  var j;
  for(var k in a) {
    if(!k.match(/___$/)) {
      j = k;
      var l = a[j];
      i++ > 0 && c.push(", ");
      e || (c.push(g), c.push(wave.util.toSpaces_(d)), c.push(j + ": "), c.push(h));
      c.push(wave.util.printJson(l, b, d + 1))
    }
  }
  e || (c.push(g), c.push(wave.util.toSpaces_(d - 1)));
  c.push(f.charAt(1));
  return c.join("")
};
wave.checkWaveContainer_ = function() {
  var a = gadgets.util.getUrlParameters();
  wave.inWaveContainer_ = a.hasOwnProperty(wave.API_PARAM_) && a[wave.API_PARAM_];
  wave.id_ = a.hasOwnProperty(wave.ID_PARAM_) && a[wave.ID_PARAM_]
};
wave.isInWaveContainer = function() {
  return wave.inWaveContainer_
};
wave.receiveWaveParticipants_ = function(a) {
  wave.viewer_ = null;
  wave.host_ = null;
  wave.participants_ = [];
  wave.participantMap_ = {};
  var b = a.myId, d = a.authorId, a = a.participants, c;
  for(var e in a) {
    if(!e.match(/___$/)) {
      c = e;
      var f = wave.Participant.fromJson_(a[c]);
      if(c == b) {
        wave.viewer_ = f
      }
      if(c == d) {
        wave.host_ = f
      }
      wave.participants_.push(f);
      wave.participantMap_[c] = f
    }
  }
  if(!wave.viewer_ && b) {
    f = new wave.Participant(b, b), wave.viewer_ = f, wave.participants_.push(f), wave.participantMap_[b] = f
  }
  wave.participantCallback_.invoke(wave.participants_)
};
wave.receiveState_ = function(a) {
  wave.state_ = wave.state_ || new wave.State("wave_gadget_state");
  var b = wave.state_.calculateDelta_(a);
  wave.state_.setState_(a);
  wave.stateCallback_.invoke(wave.state_, b)
};
wave.receiveServerTime_ = function(a) {
  wave._serverDelta = a - (new Date).getTime()
};
wave.receivePrivateState_ = function(a) {
  wave.privateState_ = wave.privateState_ || new wave.State("wave_private_gadget_state");
  var b = wave.privateState_.calculateDelta_(a);
  wave.privateState_.setState_(a);
  wave.privateStateCallback_.invoke(wave.privateState_, b)
};
wave.receiveStateDelta_ = function(a) {
  wave.state_ = wave.state_ || new wave.State("wave_gadget_state");
  wave.state_.applyDelta_(a);
  wave.stateCallback_.invoke(wave.state_, a)
};
wave.receivePrivateStateDelta_ = function(a) {
  wave.privateState_ = wave.privateState_ || new wave.State("wave_private_gadget_state");
  wave.privateState_.applyDelta_(a);
  wave.privateStateCallback_.invoke(wave.privateState_, a)
};
wave.receiveMode_ = function(a) {
  wave.mode_ = a || {};
  wave.modeCallback_.invoke(wave.getMode())
};
wave.getViewer = function() {
  return wave.viewer_
};
wave.getHost = function() {
  return wave.host_
};
wave.getParticipants = function() {
  return wave.participants_
};
wave.getParticipantById = function(a) {
  return wave.participantMap_[a]
};
wave.getState = function() {
  return wave.state_
};
wave.getPrivateState = function() {
  return wave.privateState_
};
wave.getMode = function() {
  if(wave.mode_) {
    var a = wave.mode_["${playback}"], b = wave.mode_["${edit}"];
    if(a != null && b != null) {
      return a == "1" ? wave.Mode.PLAYBACK : b == "1" ? wave.Mode.EDIT : wave.Mode.VIEW
    }
  }
  return wave.Mode.UNKNOWN
};
wave.isPlayback = function() {
  var a = wave.getMode();
  return a == wave.Mode.PLAYBACK || a == wave.Mode.UNKNOWN
};
wave.setStateCallback = function(a, b) {
  wave.stateCallback_ = new wave.Callback(a, b);
  wave.state_ && wave.stateCallback_.invoke(wave.state_, wave.state_.state_)
};
wave.setPrivateStateCallback = function(a, b) {
  wave.privateStateCallback_ = new wave.Callback(a, b);
  wave.privateState_ && wave.privateStateCallback_.invoke(wave.privateState_, wave.privateState_.state_)
};
wave.setParticipantCallback = function(a, b) {
  wave.participantCallback_ = new wave.Callback(a, b);
  wave.participants_ && wave.participantCallback_.invoke(wave.participants_)
};
wave.setModeCallback = function(a, b) {
  wave.modeCallback_ = new wave.Callback(a, b);
  wave.mode_ && wave.modeCallback_.invoke(wave.getMode())
};
wave.getTime = function() {
  return(new Date).getTime() + wave._serverDelta
};
wave.log = function(a) {
  gadgets.rpc.call(null, "wave_log", null, a || "")
};
wave.setSnippet = function(a) {
  gadgets.rpc.call(null, "set_snippet", null, a || "")
};
wave.getWaveId = function() {
  return wave.id_
};
wave.internalInit_ = function() {
  wave._serverDelta = 0;
  wave.checkWaveContainer_();
  wave.isInWaveContainer() && (gadgets.rpc.register("wave_gadget_mode", wave.receiveMode_), gadgets.rpc.register("wave_gadget_state", wave.receiveState_), gadgets.rpc.register("wave_private_gadget_state", wave.receivePrivateState_), gadgets.rpc.register("wave_private_state_delta", wave.receivePrivateStateDelta_), gadgets.rpc.register("wave_participants", wave.receiveWaveParticipants_), gadgets.rpc.register("wave_server_time", wave.receiveServerTime_), gadgets.rpc.register("wave_state_delta", wave.receiveStateDelta_), 
  gadgets.rpc.call(null, "wave_enable", null, "1.1"))
};
(wave.init_ = function() {
  window.gadgets && gadgets.util.registerOnLoadHandler(function() {
    wave.internalInit_()
  })
})();
typeof wave == "undefined" && (wave = {});
if(typeof wave.ui == "undefined") {
  wave.ui = {}
}
wave.ui.BASE = "http://wave-api.appspot.com/public/";
wave.ui.cssLoaded = !1;
wave.ui.loadCss = function() {
  if(!wave.ui.cssLoaded) {
    wave.ui.cssLoaded = !0;
    var a = document.createElement("link");
    a.setAttribute("rel", "stylesheet");
    a.setAttribute("type", "text/css");
    a.setAttribute("href", wave.ui.BASE + "wave.ui.css");
    document.getElementsByTagName("head")[0].appendChild(a)
  }
};
wave.ui.makeButton = function(a) {
  wave.ui.loadCss();
  a.innerHTML = "<span>" + a.innerHTML + "</span>";
  a.className += " wavebutton"
};
wave.ui.makeDialog = function(a, b, d) {
  function c() {
    a.style.display = "none"
  }
  wave.ui.loadCss();
  var e = a.innerHTML;
  a.innerHTML = "";
  var f = document.createElement("div");
  f.className = "wavedialoghead";
  var g = document.createElement("span"), h = document.createElement("div");
  h.className = "wavedialogclose";
  h.onclick = d || c;
  g.appendChild(h);
  g.appendChild(document.createTextNode(b));
  f.appendChild(g);
  a.appendChild(f);
  b = document.createElement("div");
  b.className = "wavedialogbody";
  b.innerHTML = e;
  a.appendChild(b);
  a.className += " wavedialog"
};
wave.ui.makeFrame = function(a) {
  wave.ui.loadCss();
  a.innerHTML = '<div class="waveboxhead"><span>&nbsp;</span></div><div class="waveboxbody">' + a.innerHTML + "</div>";
  a.className += " wavebox"
};
typeof wave == "undefined" && (wave = {});
if(typeof wave.client == "undefined") {
  wave.client = {}
}
wave.client.loadHashTags = function(a, b) {
  var d = "", c;
  for(var e in a) {
    e.match(/___$/) || (c = e, d != "" && (d += ","), d += c, a[c] && (d += ":" + a[c]))
  }
  b || (d += ",restored:wave:" + wave.getWaveId());
  alert(d);
  window.parent.location.hash = d
};
wave.client.openWave = function(a) {
  wave.client.loadHashTags({"restored:wave":a}, !0)
};
wave.client.openSearch = function(a) {
  wave.client.loadHashTags({"restored:search":a})
};
wave.client.maximizeWavePanel = function() {
  wave.client.loadHashTags({"minimized:nav":"", "minimized:contact":"", "minimized:search":""})
};


