if(typeof window.afkWindowObjectMap !== "undefined")
{
  throw "Variable: 'window.afkWindowObjectMap' has already been defined, but is needed by 'AfkWindowObjectMap'."
}

window.afkWindowObjectMap = new AfkWindowObjectMap();

function AfkWindowObjectMap()
{
  this._map = [];
  this._nextID = 0;
  
  //--------------------------------------------------------
  //
  //--------------------------------------------------------
  this.addObject = function(object)
  {
    var newID = this.getIdByObject(object);

    //if we didn't already find the object in the map, create a new id and add to map   
    if(newID == null)
    {
      newID = this.getNewID();
      this._map.push({"ID":newID, "objectRef":object}  );
    }
    return newID;
  }
  
  
  //--------------------------------------------------------
  //
  //--------------------------------------------------------
  this.getObjectByID = function(id)
  {
    var object = null;

    var i =0;
    while( i < this._map.length && object == null)
    {
      if(this._map[i].ID == id)
      {
        object = this._map[i].objectRef;
      }
      i++;
    }
    return object;
  };

  //--------------------------------------------------------
  //
  //--------------------------------------------------------
  this.getIdByObject = function(object)
  {
    var ID = null;

    var i =0;
    while( i < this._map.length && ID == null)
    {
      if(this._map[i].objectRef == object)
      {
        ID = this._map[i].ID;
      }
      i++;
    }
    return ID;
  };

  //--------------------------------------------------------
  //
  //--------------------------------------------------------  
  this.getNewID = function()
  {
    this._nextID++;
    return this._nextID;
  }
}

