//
// A XG_Button is a GControl.
//
function XG_Button(buttonOpts, callbackFuncs) {
  this.globals = {};
  this.globals.options={
    buttonHTML: 'button',
    buttonStartingStyle: 
      {width: '52px', border: '1px solid black', padding: '2px'},
    buttonStyle: {background: '#FFF'},
    buttonZoomingHTML: 'Drag a region on the map',
    buttonZoomingStyle: {background: '#FF0'},
    overlayRemoveTime: 1000,
    stickyZoomEnabled: false,
	 buttonID: 'xg-button'
  };
	
  for (var s in buttonOpts) {
    this.globals.options[s] = buttonOpts[s]
  }

  // callbacks: buttonclick, dragstart, dragging, dragend, backbuttonclick 
  if (callbackFuncs == null) {
     callbackFuncs = {}
  }
  this.globals.callbacks = callbackFuncs;
}
XG_Button.prototype = new GControl();
//==================================================================================
// Name:    initButton_
// Purpose: Create a div of a button
// Usage:   var buttonDiv = this.initButton_(buttonContainerDiv);
// Arguments: 
//   buttonContainerDiv -- A 'DIV' container.
//   buttonDiv          -- a div for button, which is contained in 'buttonContainerDiv'
//===================================================================================
XG_Button.prototype.initButton_ = function(buttonContainerDiv) {
  var G = this.globals;
  var buttonDiv = document.createElement('div');
  buttonDiv.innerHTML = G.options.buttonHTML;
  buttonDiv.id = G.options.buttonID;
  UtilFuncs.style([buttonDiv], {cursor: 'pointer', zIndex:200});
  UtilFuncs.style([buttonDiv], G.options.buttonStartingStyle);
  UtilFuncs.style([buttonDiv], G.options.buttonStyle);
  buttonContainerDiv.appendChild(buttonDiv);
  return buttonDiv;
};
//
//---------Create button
//
XG_Button.prototype.initialize = function(map) {
   var buttonContainerDiv = document.createElement("div");
	//
	//-----------Create a button
	//
   var buttonDiv = this.initButton_(buttonContainerDiv);
	//
	//-----------Set 'callback' functions
	//
   if (this.globals.callbacks.click != null) {
      GEvent.addDomListener(buttonDiv, "click", this.globals.callbacks.click);
	}
   map.getContainer().appendChild(buttonContainerDiv);
   return buttonContainerDiv;
}
//
//-----------Set default position
//
XG_Button.prototype.getDefaultPosition = function() {
   return new GControlPosition(G_ANCHOR_BOTTOM_LEFT, new GSize(7, 30));
}
//
