/*

 regionSelect.js -- a DHTML library for drag/rubber-band selection in gbrowse
                      This class handles region-specific configuration.

 Sheldon McKay <mckays@cshl.edu>
 $Id: regionSelect.js,v 1.1.2.3 2008/02/04 21:51:05 sheldon_mckay Exp $

*/

var regionObject;

// Constructor
var Region = function () {
  this.imageName  = 'vview';
  this.marginTop  = '100px';
  this.background = 'skyblue';
  this.opacity    = 0.5;
  this.fontColor  = 'blue';
  this.border     = '1px solid black';
  this.menuWidth  = '160px';
  return this;
}

// Inherit from base class SelectArea
Region.prototype = new SelectArea();

// Region-specific config.
Region.prototype.initialize = function() {
  var self = new Region;

  var images = document.getElementById(self.imageName);
  var i = images;
  var p = i.parentNode;

  self.top     = self.elementLocation(i,'y1');
  self.bottom  = self.elementLocation(i,'y2');
  self.left    = self.elementLocation(i,'x1');
  self.right   = self.elementLocation(i,'x2');
  self.selectLayer = p.parentNode.parentNode;

  self.scalebar = i;
  self.getSegment();
//  self.addSelectMenu('region');
  self.addSelectBox();
  regionObject = self;
}

Region.prototype.startSelection = function(event) {
  var self = regionObject;
  var evt = event || window.event;
  SelectArea.prototype.startRubber(self,event);
}

Region.prototype.getSegment = function() {
  // get the segment info from gbrowse CGI parameters
  this.ref          = "test1";
  this.spid         = document.f1.spid.value;
  this.srh          = document.f1.srh.value;
  this.chrom_id     = parseInt(document.f1.chrom_id.value);
  this.segmentStart = parseInt(document.f1.s_start.value);
  this.segmentEnd   = parseInt(document.f1.s_end.value);
  this.segmentChromEnd = parseInt(document.f1.chro_lng.value);
  this.padChromLeft = parseInt(document.f1.x_indent.value);
  this.padLeft      = parseInt(document.f1.x_start.value);
  this.padRight     = parseInt(document.f1.x_start.value * 1 + document.f1.x_width.value * 1);
  this.padTop       = 72;
  this.pixelToDNA   = parseFloat((this.segmentEnd - this.segmentStart + 1) / (document.f1.x_width.value));
  this.pixelToChromDNA = parseFloat((this.segmentChromEnd)
  	/ (document.f1.x_width.value * 1 + this.padLeft * 1 - this.padChromLeft));
  this.pixelStart   = this.left + this.padLeft;
  this.pixelChromStart = this.left + this.padChromLeft;
}

Region.prototype.formatMenu = function() {
  this.menuHTML = this.selectMenu.innerHTML || '\
   <div style="padding:5px;text-align:center">\
     <b>SELECTION</b><hr>\
     <a href="javascript:SelectArea.prototype.clearAndSubmit()">Zoom</a>\
     &nbsp;&nbsp;|&nbsp;&nbsp;\
     <a href="javascript:SelectArea.prototype.cancelRubber()">Cancel</a>\
  </div>';
}

