function AdfResizeTrackManager(element) {
  this.Init(element);
}
AdfObject.createSubclass(AdfResizeTrackManager);
AdfResizeTrackManager.prototype.Init = function(element) {
  AdfResizeTrackManager.superclass.Init.call(this);
  this._listeners = [];
  this._element = element;
  this._RETRY_MAX_COUNT = 2;
  this._retrySetScroll = 0;
  this._invokeId = null;
  this._oldWidth = null;
  this._oldHeight = null;
  this._detectExpansion = null;
  this._detectContraction = null;
  this._resizeListener = null;
  this._scrollListener = null;
  this._onResizeTimeout = null;
};
AdfResizeTrackManager.prototype.addListener = function(listener) {
  this._listeners.push(listener);
};
AdfResizeTrackManager.prototype.removeListener = function(listener) {
  for (var i = this._listeners.length - 1;i >= 0;i--) {
    if (this._listeners[i] === listener) {
      this._listeners.splice(i, 1);
      return;
    }
  }
};
AdfResizeTrackManager.prototype.isEmpty = function() {
  return this._listeners.length == 0;
};
AdfResizeTrackManager.prototype.start = function() {
  this._scrollListener = this.createCallback(AdfResizeTrackManager._handleScroll);
  if (this._element.attachEvent) {
    this._resizeListener = this.createCallback(AdfResizeTrackManager._handleResize);
    this._element.attachEvent("onresize", this._resizeListener);
  } else {
    var firstChild = this._element.childNodes[0];
    this._detectExpansion = document.createElement("div");
    var cssText = "position:absolute; overflow:hidden; visibility:hidden; top:0; left:0; right:0; bottom:0; direction:ltr;";
    AdfDomUtils.addInlineStyle(this._detectExpansion, cssText);
    this._detectExpansion.className = "AFDetectExpansion";
    var expansionChild = document.createElement("div");
    this._detectExpansion.appendChild(expansionChild);
    if (firstChild != null) {
      this._element.insertBefore(this._detectExpansion, firstChild);
    } else {
      this._element.appendChild(this._detectExpansion);
    }
    this._detectExpansion.addEventListener("scroll", this._scrollListener, false);
    this._detectContraction = document.createElement("div");
    this._detectContraction.className = "AFDetectContraction";
    AdfDomUtils.addInlineStyle(this._detectContraction, cssText);
    var contractionChild = document.createElement("div");
    contractionChild.style.width = "200%";
    contractionChild.style.height = "200%";
    this._detectContraction.appendChild(contractionChild);
    this._element.insertBefore(this._detectContraction, this._detectExpansion);
    this._detectContraction.addEventListener("scroll", this._scrollListener, false);
    this.initializeElements(false);
  }
};
AdfResizeTrackManager.prototype.stop = function() {
  if (this._invokeId != null) {
    AdfResizeTrackManager._cancelInvokeAfterPaint(this._invokeId);
    this._invokeId = null;
  }
  if (this._detectExpansion != null) {
    this._detectExpansion.removeEventListener("scroll", this._scrollListener, false);
    this._detectContraction.removeEventListener("scroll", this._scrollListener, false);
    this._element.removeChild(this._detectExpansion);
    this._element.removeChild(this._detectContraction);
  } else {
    this._element.detachEvent("onresize", this._resizeListener);
  }
};
AdfResizeTrackManager.prototype.initializeElements = function(isFixup) {
  var adjusted = this._checkSize(isFixup);
  if (isFixup && !adjusted && this._detectExpansion.offsetParent != null) {
    this._adjust(this._oldWidth, this._oldHeight);
  }
};
AdfResizeTrackManager.prototype._checkSize = function(fireEvent) {
  var adjusted = false;
  if (this._detectExpansion.offsetParent != null) {
    var newWidth = this._detectExpansion.offsetWidth;
    var newHeight = this._detectExpansion.offsetHeight;
    var innerWindowHeight = AdfAgent.AGENT.getDomWindow().innerHeight;
    if (this._oldWidth !== newWidth || this._oldHeight !== newHeight && newHeight < innerWindowHeight) {
      this._retrySetScroll = this._RETRY_MAX_COUNT;
      this._adjust(newWidth, newHeight);
      adjusted = true;
      if (fireEvent) {
        this._notifyListeners(true);
      }
    }
  }
  return adjusted;
};
AdfResizeTrackManager.prototype._notifyListeners = function(useAfterPaint) {
  if (this._listeners.length > 0) {
    if (!useAfterPaint) {
      for (var i = 0;i < this._listeners.length;i++) {
        this._listeners[i]();
      }
    } else {
      if (this._invokeId !== null) {
        AdfResizeTrackManager._cancelInvokeAfterPaint(this._invokeId);
      }
      var myself = this;
      this._invokeId = AdfResizeTrackManager._invokeAfterPaint(function() {
        myself._invokeId = null;
        for (var j = 0;j < myself._listeners.length;j++) {
          myself._listeners[j]();
        }
      });
    }
  }
};
AdfResizeTrackManager._handleScroll = function(evt) {
  evt.stopPropagation();
  if (!this._onResizeTimeout) {
    var page = AdfPage.PAGE;
    this._onResizeTimeout = page.scheduleTimer(this, AdfResizeTrackManager._onResizeHandlerTimeout, {}, 100);
  }
};
AdfResizeTrackManager._onResizeHandlerTimeout = function() {
  if (!this._checkSize(true)) {
    if (this._retrySetScroll > 0 && this._detectExpansion.offsetParent != null && (this._detectExpansion.scrollLeft == 0 || this._detectExpansion.scrollTop == 0)) {
      this._retrySetScroll--;
      this._adjust(this._oldWidth, this._oldHeight);
    }
  }
  this._onResizeTimeout = null;
};
AdfResizeTrackManager._handleResize = function() {
  this._notifyListeners(false);
};
AdfResizeTrackManager.prototype._adjust = function(width, height) {
  this._oldWidth = width;
  this._oldHeight = height;
  var expansionChildStyle = this._detectExpansion.firstChild.style;
  var delta = 1;
  do {
    expansionChildStyle.width = width + delta + "px";
    expansionChildStyle.height = height + delta + "px";
    this._detectExpansion.scrollLeft = this._detectExpansion.scrollTop = delta;
    delta++;
  } while ((this._detectExpansion.scrollTop == 0 || this._detectExpansion.scrollLeft == 0) && delta <= 5);
  this._detectContraction.scrollLeft = width;
  this._detectContraction.scrollTop = height;
};
AdfResizeTrackManager._invokeAfterPaint = function(callback) {
  var agent = AdfAgent.AGENT;
  if (agent.getDomWindow()["requestAnimationFrame"]) {
    return agent.getDomWindow()["requestAnimationFrame"](callback);
  } else {
    if (agent.getDomWindow()["mozRequestAnimationFrame"]) {
      return agent.getDomWindow()["mozRequestAnimationFrame"](callback);
    } else {
      if (agent.getDomWindow()["webkitRequestAnimationFrame"]) {
        return agent.getDomWindow()["webkitRequestAnimationFrame"](callback);
      } else {
        return agent.getDomWindow().setTimeout(callback, 0);
      }
    }
  }
};
AdfResizeTrackManager._cancelInvokeAfterPaint = function(id) {
  var agent = AdfAgent.AGENT;
  if (agent.getDomWindow()["cancelAnimationFrame"]) {
    return agent.getDomWindow()["cancelAnimationFrame"](id);
  } else {
    if (agent.getDomWindow()["mozCancelAnimationFrame"]) {
      return agent.getDomWindow()["mozCancelAnimationFrame"](id);
    } else {
      if (agent.getDomWindow()["webkitCancelAnimationFrame"]) {
        return agent.getDomWindow()["webkitCancelAnimationFrame"](id);
      } else {
        return agent.getDomWindow().clearTimeout(id);
      }
    }
  }
};
