qx.Mixin.define("nx4.webwidgets.ui.core.MWidgetPosition",
{
  members :
  {
    _resyncDimensions : function()
    {
      var size = this.getContainerSize();
      if(!size)
        throw "could not sync element dimensions";

      if(!this.getWidth())
        this.setWidth(size.width);
      if(!this.getHeight())
        this.setHeight(size.height);
    },

    center : function()
    {
      if(!this.getWidth() || !this.getHeight())
        this._resyncDimensions();

      var vp = qx.bom.Viewport;
      var v = { w:vp.getWidth(), h:vp.getHeight() };

      //Wenn das Element groesser als das Fenster ist, dieses auf (0,0) bringen
      var x = (this.getWidth()  >= v.w) ? 0 : Math.round((v.w - this.getWidth())/2);
      var y = (this.getHeight() >= v.h) ? 0 : Math.round((v.h - this.getHeight())/2);

      //noch die Scroll-Position anfuegen, damit es wirklich immer zentriert wird
      x+= vp.getScrollLeft();
      y+= vp.getScrollTop();

      this.setLeft(x);
      this.setTop(y);
    }
  }
});

