/* Copyright (c) 2006 MetaCarta, Inc., published under a modified BSD license.
 * See http://svn.openlayers.org/trunk/openlayers/repository-license.txt 
 * for the full text of the license. */
OpenLayers.Control.PanZoomSlide=OpenLayers.Class.create();OpenLayers.Control.PanZoomSlide.X=4;OpenLayers.Control.PanZoomSlide.Y=4;OpenLayers.Control.PanZoomSlide.prototype=OpenLayers.Class.inherit(OpenLayers.Control,{slideFactor:180,slideSteps:18,slideWait:20,slideOn:null,slidePowr:0.5,buttons:null,position:null,initialize:function(){OpenLayers.Control.prototype.initialize.apply(this,arguments);this.position=new OpenLayers.Pixel(OpenLayers.Control.PanZoomSlide.X,OpenLayers.Control.PanZoomSlide.Y);},slideInit:function(x,y){this.slidePan([0,0],[x,y],this.slideSteps,this.slideWait,this.slidePowr);},slidePan:function(startPos,endPos,steps,intervals,powr){if(this.slideOn)window.clearInterval(this.slideOn);var actStep=0;var totX=totY=0;var o=this;this.slideOn=window.setInterval(function(){var dXdY=[o.easeInOut(startPos[0],endPos[0],steps,actStep,powr)-totX,o.easeInOut(startPos[1],endPos[1],steps,actStep,powr)-totY];totX+=dXdY[0];totY+=dXdY[1];o.map.pan(dXdY[0],dXdY[1]);actStep++;if(actStep>steps)window.clearInterval(o.slideOn);},intervals)},easeInOut:function(minValue,maxValue,totalSteps,actualStep,powr){var delta=maxValue-minValue;var stepp=minValue+(Math.pow(((1/totalSteps)*actualStep),powr)*delta);return Math.ceil(stepp)},draw:function(px){OpenLayers.Control.prototype.draw.apply(this,arguments);px=this.position;this.buttons=new Array();var sz=new OpenLayers.Size(18,18);var centered=new OpenLayers.Pixel(px.x+sz.w/2,px.y);this._addButton("panup","north-mini.png",centered,sz);px.y=centered.y+sz.h;this._addButton("panleft","west-mini.png",px,sz);this._addButton("panright","east-mini.png",px.add(sz.w,0),sz);this._addButton("pandown","south-mini.png",centered.add(0,sz.h*2),sz);this._addButton("zoomin","zoom-plus-mini.png",centered.add(0,sz.h*3+5),sz);this._addButton("zoomworld","zoom-world-mini.png",centered.add(0,sz.h*4+5),sz);this._addButton("zoomout","zoom-minus-mini.png",centered.add(0,sz.h*5+5),sz);return this.div;},_addButton:function(id,img,xy,sz){var imgLocation=OpenLayers.Util.getImagesLocation()+img;var btn=OpenLayers.Util.createAlphaImageDiv("OpenLayers_Control_PanZoom_"+id,xy,sz,imgLocation,"absolute");this.div.appendChild(btn);btn.onmousedown=this.buttonDown.bindAsEventListener(btn);btn.ondblclick=this.doubleClick.bindAsEventListener(btn);btn.onclick=this.doubleClick.bindAsEventListener(btn);btn.action=id;btn.map=this.map;btn.slideFactor=this.slideFactor;btn.control=this;this.buttons.push(btn);return btn;},doubleClick:function(evt){OpenLayers.Event.stop(evt);return false;},buttonDown:function(evt){var control=this.control;var slideFactor=control.slideFactor;if(!OpenLayers.Event.isLeftClick(evt))return;switch(this.action){case"panup":control.slideInit(0,-slideFactor);break;case"pandown":control.slideInit(0,slideFactor);break;case"panleft":control.slideInit(-slideFactor,0);break;case"panright":control.slideInit(slideFactor,0);break;case"zoomin":this.map.zoomIn();break;case"zoomout":this.map.zoomOut();break;case"zoomworld":this.map.zoomToMaxExtent();break;}
OpenLayers.Event.stop(evt);},destroy:function(){OpenLayers.Control.prototype.destroy.apply(this,arguments);for(i=0;i<this.buttons.length;i++){this.buttons[i].map=null;}},CLASS_NAME:"OpenLayers.Control.PanZoomSlide"});
