(function(){var toPixels=function(widthValue){var px;switch(widthValue){case 'thin':px="2px";break;case 'medium':px="4px";break;case 'thick':px="6px";break;default:px=widthValue;}
return px;};/**/
var getBorderWidths=function(h){var computedStyle;var bw={};if(document.defaultView&&document.defaultView.getComputedStyle){computedStyle=h.ownerDocument.defaultView.getComputedStyle(h,"");if(computedStyle){bw.top=parseInt(computedStyle.borderTopWidth,10)||0;bw.bottom=parseInt(computedStyle.borderBottomWidth,10)||0;bw.left=parseInt(computedStyle.borderLeftWidth,10)||0;bw.right=parseInt(computedStyle.borderRightWidth,10)||0;return bw;}}else if(document.documentElement.currentStyle){if(h.currentStyle){bw.top=parseInt(toPixels(h.currentStyle.borderTopWidth),10)||0;bw.bottom=parseInt(toPixels(h.currentStyle.borderBottomWidth),10)||0;bw.left=parseInt(toPixels(h.currentStyle.borderLeftWidth),10)||0;bw.right=parseInt(toPixels(h.currentStyle.borderRightWidth),10)||0;return bw;}}
bw.top=parseInt(h.style["border-top-width"],10)||0;bw.bottom=parseInt(h.style["border-bottom-width"],10)||0;bw.left=parseInt(h.style["border-left-width"],10)||0;bw.right=parseInt(h.style["border-right-width"],10)||0;return bw;};var getMousePosition=function(e){var posX=0,posY=0;e=e||window.event;if(typeof e.pageX!=="undefined"){posX=e.pageX;posY=e.pageY;}else if(typeof e.clientX!=="undefined"){posX=e.clientX+
(typeof document.documentElement.scrollLeft!=="undefined"?document.documentElement.scrollLeft:document.body.scrollLeft);posY=e.clientY+(typeof document.documentElement.scrollTop!=="undefined"?document.documentElement.scrollTop:document.body.scrollTop);}
return{left:posX,top:posY};};var getElementPosition=function(h){var posX=h.offsetLeft;var posY=h.offsetTop;var parent=h.offsetParent;while(parent!==null){if(parent!==document.body&&parent!==document.documentElement){posX-=parent.scrollLeft;posY-=parent.scrollTop;}
posX+=parent.offsetLeft;posY+=parent.offsetTop;parent=parent.offsetParent;}
return{left:posX,top:posY};};var setVals=function(obj,vals){if(obj&&vals){for(var x in vals){if(vals.hasOwnProperty(x)){obj[x]=vals[x];}}}
return obj;};var setOpacity=function(div,op){if(typeof op!=='undefined'){div.style.opacity=op;}
if(typeof div.style.opacity!=='undefined'){div.style.filter="alpha(opacity="+(div.style.opacity*100)+")";}};function DragZoom(map,opt_zoomOpts){var ov=new google.maps.OverlayView();var me=this;ov.onAdd=function(){me.init_(map,opt_zoomOpts);};ov.draw=function(){};ov.onRemove=function(){};ov.setMap(map);this.prjov_=ov;}
DragZoom.prototype.init_=function(map,opt_zoomOpts){this.map_=map;opt_zoomOpts=opt_zoomOpts||{};this.key_=opt_zoomOpts.key||'shift';this.key_= this.key_.toLowerCase();this.borderWidths_=getBorderWidths(this.map_.getDiv());this.paneDiv_=document.createElement("div");this.paneDiv_.onselectstart=function(){return false;};setVals(this.paneDiv_.style,{backgroundColor:'white',opacity:0.0,cursor:'crosshair'});setVals(this.paneDiv_.style,opt_zoomOpts.paneStyle);setVals(this.paneDiv_.style,{position:'absolute',overflow:'hidden',zIndex:10001,display:'none'});if(this.key_==='shift'){this.paneDiv_.style.MozUserSelect="none";}
setOpacity(this.paneDiv_);if(this.paneDiv_.style.backgroundColor==='transparent'){this.paneDiv_.style.backgroundColor='white';setOpacity(this.paneDiv_,0);}
this.map_.getDiv().appendChild(this.paneDiv_);this.boxDiv_=document.createElement('div');setVals(this.boxDiv_.style,{border:'thin solid #FF0000'});setVals(this.boxDiv_.style,opt_zoomOpts.boxStyle);setVals(this.boxDiv_.style,{position:'absolute',display:'none'});setOpacity(this.boxDiv_);this.map_.getDiv().appendChild(this.boxDiv_);this.boxBorderWidths_=getBorderWidths(this.boxDiv_);var me=this;this.keyDownListener_=google.maps.event.addDomListener(document,'keydown',function(e){me.onKeyDown_(e);});this.keyUpListener_=google.maps.event.addDomListener(document,'keyup',function(e){me.onKeyUp_(e);});this.mouseDownListener_=google.maps.event.addDomListener(this.paneDiv_,'mousedown',function(e){me.onMouseDown_(e);});this.mouseDownListenerDocument_=google.maps.event.addDomListener(document,'mousedown',function(e){me.onMouseDownDocument_(e);});this.mouseMoveListener_=google.maps.event.addDomListener(document,'mousemove',function(e){me.onMouseMove_(e);});this.mouseUpListener_=google.maps.event.addDomListener(document,'mouseup',function(e){me.onMouseUp_(e);});this.hotKeyDown_=false;this.dragging_=false;this.startPt_=null;this.endPt_=null;this.boxMaxX_=null;this.boxMaxY_=null;this.mousePosn_=null;this.mapPosn_=getElementPosition(this.map_.getDiv());this.mouseDown_=false;};DragZoom.prototype.isHotKeyDown_=function(e){var isHot;e=e||window.event;isHot=(e.shiftKey&&this.key_==='shift')||(e.altKey&&this.key_==='alt')||(e.ctrlKey&&this.key_==='ctrl');if(!isHot){switch(e.keyCode){case 16:if(this.key_==='shift'){isHot=true;}
break;case 17:if(this.key_==='ctrl'){isHot=true;}
break;case 18:if(this.key_==='alt'){isHot=true;}
break;}}
return isHot;};DragZoom.prototype.isMouseOnMap_=function(){var mousePos=this.mousePosn_;if(mousePos){var mapPos=this.mapPosn_; var mapDiv=this.map_.getDiv();return mousePos.left>mapPos.left&&mousePos.left<mapPos.left+mapDiv.offsetWidth&&mousePos.top>mapPos.top&&mousePos.top<mapPos.top+mapDiv.offsetHeight;}else{return false;}};DragZoom.prototype.setPaneVisibility_=function(){if(this.map_&&this.hotKeyDown_&&this.isMouseOnMap_()){var mapDiv=this.map_.getDiv();this.paneDiv_.style.left=0+'px';this.paneDiv_.style.top=0+'px';this.paneDiv_.style.width=mapDiv.offsetWidth-(this.borderWidths_.left+this.borderWidths_.right)+'px';this.paneDiv_.style.height=mapDiv.offsetHeight-(this.borderWidths_.top+this.borderWidths_.bottom)+'px';this.paneDiv_.style.display='block';this.boxMaxX_=parseInt(this.paneDiv_.style.width,10)-(this.boxBorderWidths_.left+this.boxBorderWidths_.right);this.boxMaxY_=parseInt(this.paneDiv_.style.height,10)-(this.boxBorderWidths_.top+this.boxBorderWidths_.bottom);}else{this.paneDiv_.style.display='none';}};DragZoom.prototype.onKeyDown_=function(e){var me=this;if(this.map_&&!this.hotKeyDown_&&this.isHotKeyDown_(e)){me.hotKeyDown_=true;me.setPaneVisibility_();google.maps.event.trigger(me,'activate');}};DragZoom.prototype.getMousePoint_=function(e){var mousePosn=getMousePosition(e);var p=new google.maps.Point();p.x=mousePosn.left-this.mapPosn_.left-this.borderWidths_.left;p.y=mousePosn.top-this.mapPosn_.top-this.borderWidths_.top;p.x=Math.min(p.x,this.boxMaxX_);p.y=Math.min(p.y,this.boxMaxY_);p.x=Math.max(p.x,0);p.y=Math.max(p.y,0);return p;};DragZoom.prototype.onMouseDown_=function(e){if(this.map_&&this.hotKeyDown_){this.mapPosn_=getElementPosition(this.map_.getDiv());this.dragging_=true;this.startPt_=this.endPt_=this.getMousePoint_(e);var prj=this.prjov_.getProjection();var latlng=prj.fromDivPixelToLatLng(this.startPt_);google.maps.event.trigger(this,'dragstart',latlng);}};DragZoom.prototype.onMouseDownDocument_=function(e){this.mouseDown_=true;};DragZoom.prototype.onMouseMove_=function(e){this.mousePosn_=getMousePosition(e);if(this.dragging_){this.endPt_=this.getMousePoint_(e);var left=Math.min(this.startPt_.x,this.endPt_.x);var top=Math.min(this.startPt_.y,this.endPt_.y);var width=Math.abs(this.startPt_.x-this.endPt_.x);var height=Math.abs(this.startPt_.y-this.endPt_.y);this.boxDiv_.style.left=left+'px';this.boxDiv_.style.top=top+'px';this.boxDiv_.style.width=width+'px';this.boxDiv_.style.height=height+'px';this.boxDiv_.style.display='block';/**/
google.maps.event.trigger(this,'drag',new google.maps.Point(left,top+height),new google.maps.Point(left+width,top));}else if(!this.mouseDown_){this.setPaneVisibility_();}};DragZoom.prototype.onMouseUp_=function(e){this.mouseDown_=false;if(this.dragging_){var left=Math.min(this.startPt_.x,this.endPt_.x);var top=Math.min(this.startPt_.y,this.endPt_.y);var width=Math.abs(this.startPt_.x-this.endPt_.x);var height=Math.abs(this.startPt_.y-this.endPt_.y);var prj=this.prjov_.getProjection();var containerPos=getElementPosition(this.map_.getDiv());var mapPanePos=getElementPosition(this.prjov_.getPanes().mapPane);left=left+(containerPos.left-mapPanePos.left);top=top+(containerPos.top-mapPanePos.top);var sw=prj.fromDivPixelToLatLng(new google.maps.Point(left,top+height));var ne=prj.fromDivPixelToLatLng(new google.maps.Point(left+width,top));var bnds=new google.maps.LatLngBounds(sw,ne);this.map_.fitBounds(bnds);this.dragging_=false;this.boxDiv_.style.display='none';google.maps.event.trigger(this,'dragend',bnds);}};DragZoom.prototype.onKeyUp_=function(e){if(this.map_&&this.hotKeyDown_){this.hotKeyDown_=false;this.dragging_=false;this.boxDiv_.style.display='none';this.paneDiv_.style.display="none";google.maps.event.trigger(this,'deactivate');}};google.maps.Map.prototype.enableKeyDragZoom=function(opt_zoomOpts){this.dragZoom_=new DragZoom(this,opt_zoomOpts);};google.maps.Map.prototype.disableKeyDragZoom=function(){var d=this.dragZoom_;if(d){google.maps.event.removeListener(d.mouseDownListener_);google.maps.event.removeListener(d.mouseDownListenerDocument_);google.maps.event.removeListener(d.mouseMoveListener_);google.maps.event.removeListener(d.mouseUpListener_);google.maps.event.removeListener(d.keyUpListener_);google.maps.event.removeListener(d.keyDownListener_);this.getDiv().removeChild(d.boxDiv_);this.getDiv().removeChild(d.paneDiv_);this.dragZoom_=null;}};google.maps.Map.prototype.keyDragZoomEnabled=function(){return this.dragZoom_!==null;};/**/
google.maps.Map.prototype.getDragZoomObject=function(){return this.dragZoom_;};})();
