//VmapPanel.js

VmapPanel = function (newId, newParent, newXPosition, newYPosition, newZIndex, newWidth, newHeight, newVisibility, newMapObject, newMapControlId)
{
  if (arguments.length > 0)
    this.init(newId, newParent, newXPosition, newYPosition, newZIndex, newWidth, newHeight, newVisibility, newMapObject, newMapControlId);
};

VmapPanel.prototype = new GuiWidget();
VmapPanel.constructor = VmapPanel;
VmapPanel.superclass = GuiWidget.prototype;

VmapPanel.prototype.init = function (newId, newParent, newXPosition, newYPosition, newZIndex, newWidth, newHeight, newVisibility, newMapObject, newMapControlId)
{
  VmapPanel.superclass.init.call(this, newId, newParent, newXPosition, newYPosition, newZIndex, newWidth, newHeight, newVisibility, "vmapPanel");
  if (newMapObject)
    this.map = newMapObject;
  else
    this.map = OBJECT_MANAGER.getControl(newMapControlId);
  this.clickMode = '';
  this.totalHeight = newHeight;
  this.hiddenHeight = 10;
  this.totalWidth = newWidth;
  this.expandedYPosition = newYPosition;
  this.hiddenYPosition = newYPosition + newHeight - 10;
  
  
  this.setClass('vmapPanel');
  this.buttonElement = new ToggleButton(this.id+"ToggleButton", this.element, (this.width() / 2) - 50, 0, 1, 100, 10, true, "vmapToggle", "Hide Vicinity Map", "Show Vicinity Map", true);
  this.buttonElement.vmapPanel = this;
  this.buttonElement.clickOn = function (e)
  {
    this.vmapPanel.expand();
  };
  this.buttonElement.clickOff = function (e)
  {
    this.vmapPanel.collapse();
  };
    
  //Map frame objects
  this.mapImage = new ImagePanel(this.id+"MapImage", this.element, 5, 10, 0, this.width() - 10, this.height() - 10, true, "", true, this.width() - 10, this.height() - 10);
  this.mapImage.element.cbe.moveTo('S');
  this.mapImage.vmapPanel = this;
  this.mapImage.setClass("vmap");
  this.mapImage.clickEvent = function(e)
  {
    this.map.clickVmap(e);
  };
  this.loadImageGraphic = new ImagePanel(this.id+"LoadImage", this.element, 5, 10, 1, this.width() - 10, this.height() - 10, false, './'+GuiWidget.THEME_PATH+GuiWidget.THEME+'/images/mapLoad.gif', false, null, null);
  this.setMapObject(this.map); 
};

/*******************************************/

VmapPanel.prototype.setMapObject = function(newMapObject)
{
  this.map = newMapObject;
  this.mapImage.map = this.map;
  if (this.map)
  {
    this.map.setVmapImage(this.mapImage);
    this.map.setVmapLoadImage(this.loadImageGraphic);
  }  
};

VmapPanel.prototype.expand = function()
{
  this.element.cbe.resizeTo(this.totalWidth, this.totalHeight); 
  this.element.cbe.moveTo(this.element.cbe.left(), this.yPosition - this.totalHeight + 10);
  this.yPosition = this.yPosition - this.totalHeight + 10;
  if (this.expandEvent)
    this.expandEvent();
};

/*******************************************/

VmapPanel.prototype.collapse = function()
{
  this.element.cbe.resizeTo(this.totalWidth, this.hiddenHeight); 
  this.element.cbe.moveTo(this.element.cbe.left(), this.yPosition + this.totalHeight - 10);
  this.yPosition = this.yPosition + this.totalHeight - 10;
  if (this.collapseEvent)
    this.collapseEvent();
};

/************************************************/

GuiWidget.prototype.setPosition = function(newXPosition, newYPosition)
{
  this.xPosition = newXPosition;
  this.yPosition = newYPosition;
  this.element.cbe.moveTo(this.xPosition, this.yPosition);
};


