// (c) 2007 KystAtlas AS (Hans Martin Mohn)

gtToolZoom.prototype=new gtTool();gtToolZoom.prototype.constructor=gtTool;gtToolZoom.superclass=gtTool.prototype;function gtToolZoom()
{this.m_map=null;this.m_zoomin=true;this.m_startX=0;this.m_startY=0;this.m_button_down=false;this.m_rect=null;this.m_clickLimit=10;}
gtToolZoom.prototype.deselect=function()
{this.m_button_down=false;};gtToolZoom.prototype.select=function(map)
{this.m_map=map;this.m_map.setCursor("crosshair");}
gtToolZoom.prototype.buttonDown=function(evt)
{this.m_img=this.m_map.m_img;this.m_rect=this.m_map.m_rect;this.m_rect.m_tool=this;addGTHandlers(this.m_rect);if(this.m_img!=this.m_map)
{this.m_img.relEvt=function gtMapJS_relEvt(evt)
{return evt;};}
this.m_rect.m_img=this.m_img;this.m_rect.gtMouseDown=function(evt){this.m_img.relEvt(evt);this.m_tool.buttonDown(evt);};this.m_rect.gtMouseUp=function(evt){this.m_img.relEvt(evt);this.m_tool.buttonUp(evt);};this.m_rect.gtMouseMove=function(evt){this.m_img.relEvt(evt);this.m_tool.mouseMove(evt);};this.m_rect.style.padding=0;this.m_rect.style.margin=0;this.m_rect.style.cursor=this.m_img.style.cursor;this.m_button_down=true;gtSetVisibility(this.m_rect,"visible");gtSetLeft(this.m_rect,evt.gtX);gtSetTop(this.m_rect,evt.gtY);gtSetWidth(this.m_rect,0);gtSetHeight(this.m_rect,0);this.m_startX=evt.gtX;this.m_startY=evt.gtY;gtCancelBubble(evt);return gtPreventDefault(evt);};gtToolZoom.prototype.mouseMove=function(evt)
{if(this.m_button_down)
{var x=evt.gtX;var y=evt.gtY;gtSetWidth(this.m_rect,Math.abs(this.m_startX-x));gtSetHeight(this.m_rect,Math.abs(this.m_startY-y));gtSetLeft(this.m_rect,Math.min(x,this.m_startX));gtSetTop(this.m_rect,Math.min(y,this.m_startY));}
gtCancelBubble(evt);return gtPreventDefault(evt);};gtToolZoom.prototype.buttonUp=function(evt)
{this.m_button_down=false;gtSetVisibility(this.m_rect,"hidden");var x=evt.gtX;var y=evt.gtY;var w=Math.abs(this.m_startX-x);var h=Math.abs(this.m_startY-y);var zoomin=this.m_zoomin?(evt.gtButton<2):(evt.gtButton==2);if(w<this.m_clickLimit&&h<this.m_clickLimit)
{if(zoomin)
zf=0.5;else
zf=2;}
else
{var zf=(w+h)/(this.m_img.width+this.m_img.height);if(!zoomin)
zf=1/zf;}
var url=this.m_map.m_url;var old_scale=parseFloat(url.getParam("s"));var new_scale=old_scale*zf;zf=new_scale/old_scale;url.setParam("cmd","zoomin");url.setParam("map.x",(this.m_startX+x)/2);url.setParam("map.y",(this.m_startY+y)/2);url.setParam("zf",zf);this.m_map.showMap(url);gtCancelBubble(evt);return gtPreventDefault(evt);};gtToolZoom.prototype.click=function(evt)
{gtCancelBubble(evt);return gtPreventDefault(evt);}
gtToolZoom.prototype.canHandleSelection=function(selection){return true;};