/***************************************************************\
| |\  /|                                                We Put  |
| | >< Hypercosm            zoom_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 zoomButton(element, buttonGroup, parent) {
	
  // call superclass constructor
  //
  toolbarRadioButton.call(this, element, buttonGroup, parent);
  
  // set attributes
  //
  this.status = "Zoom";
  this.helpMessage = "This button sets the mouse mode to zoom mode.";
  
  return this;
}    // zoomButton


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


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


zoomButton.prototype.onActivate = function() {
  
  // create new cursor
  //
  this.cursor = new HCIcon("zoom_cursor.png", "center", "middle");
}	// onActivate
  
  
//
// selection event handling methods
//


zoomButton.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
  //
  if (this.parent.parent.applet.camera.perspective) {
    this.parent.parent.applet.setMouseMode("left", "zoom", this.cursor);
    this.parent.parent.applet.setMouseMode("right", "zoom_fov", this.cursor);
  } else {
    this.parent.parent.applet.setMouseMode("left", "zoom_fov", 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


zoomButton.prototype.onDeselect = function() {

  // 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); 
		
  // call superclass method
  //
  toolbarRadioButton.prototype.onDeselect.call(this);
}    // onDeselect


//
// query string methods
//


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


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

