/***************************************************************\
| |\  /|                                                We Put  |
| | >< Hypercosm           orbit_button.js              3d      |
| |/  \|                                                To Work |
|***************************************************************|
|                                                               |
|        This file defines the Javascript behaviors of a        |
|        specific type of SketchUp user interface button.       |
|                                                               |
|***************************************************************|
|                Copyright (c) 2007 Hypercosm, LLC.             |
\***************************************************************/


//
// "class" constructor
//


function orbitButton(element, buttonGroup, parent) {
	
  // call superclass constructor
  //
  toolbarRadioButton.call(this, element, buttonGroup, parent);
  
  // set attributes
  //
  this.status = "Orbit";
  this.helpMessage = "This button sets the mouse mode to orbit mode.";
  
  return this;
}    // orbitButton


// inherit prototype from "superclass"
//
orbitButton.prototype = new toolbarRadioButton();

  
//
// "object" or "instance" methods
//


orbitButton.prototype.onActivate = function() {
  
  // create new cursor
  //
  this.cursor = new HCIcon("orbit_cursor.png", "center", "middle");
}	// onActivate


//
// selection event handling methods
//


orbitButton.prototype.onSelect = function() {
  this.parent.parent.applet.beginMessages();

  // call superclass method
  //
  toolbarRadioButton.prototype.onSelect.call(this);
  
  // set applet mouse mode for left and right buttons
  //
  this.parent.parent.applet.setMouseMode("left", "orbit", this.cursor);
  this.parent.parent.applet.setMouseMode("right", "none", null);

  // handle the previous button
  //
  if (this.parent.parent.cameraToolbar)
    if (this.parent.parent.cameraToolbar.previousButton) {
		  
      // disable the previous button
      //
      this.parent.parent.cameraToolbar.previousButton.setEnabled(false); 
		  
      // enable previous button on mouse down
      //
      var previousButton = this.parent.parent.cameraToolbar.previousButton;
      var mouseDownHandler = function(overlay, location, button) {
        previousButton.setEnabled(true);    
      }
      this.mouseDownListener = HCEvent.addListener(this.parent.parent.applet, "mousedown", mouseDownHandler);
	}
  
  // update applet
  //
  this.parent.parent.applet.endMessages();
}    // onSelect


orbitButton.prototype.onDeselect = function() {
  
  // call superclass method
  //
  toolbarRadioButton.prototype.onDeselect.call(this);
  
  // remove mouse up listener
  //
  HCEvent.removeListener(this.mouseDownListener);

  // enable the previous button
  //
  if (this.parent.parent.cameraToolbar)
    if (this.parent.parent.cameraToolbar.previousButton)
      this.parent.parent.cameraToolbar.previousButton.setEnabled(true); 
}    // onDeselect


//
// query string methods
//


orbitButton.prototype.parseQueryString = function(queryString) {
  var mouseMode = getQueryVariable(queryString, "mouse_mode");
  if (mouseMode == "orbit")
    this.setSelected(true);
}	// parseQueryString


orbitButton.prototype.getQueryString = function() {
  var queryString = null;
  if (this.selected && !this.initiallySelected)
    queryString = "mouse_mode=orbit";
  return queryString;
}	// getQueryString

