//>>built
define("dojox/mobile/app/ImageView",["dijit","dojo","dojox","dojo/require!dojox/mobile/app/_Widget,dojo/fx/easing"],function(t,e,p){e.provide("dojox.mobile.app.ImageView");e.experimental("dojox.mobile.app.ImageView");e.require("dojox.mobile.app._Widget");e.require("dojo.fx.easing");e.declare("dojox.mobile.app.ImageView",p.mobile.app._Widget,{zoom:1,zoomCenterX:0,zoomCenterY:0,maxZoom:5,autoZoomLevel:3,disableAutoZoom:!1,disableSwipe:!1,autoZoomEvent:null,_leftImg:null,_centerImg:null,_rightImg:null,
_leftSmallImg:null,_centerSmallImg:null,_rightSmallImg:null,constructor:function(){this.panY=this.panX=0;this.handleLoad=e.hitch(this,this.handleLoad);this._updateAnimatedZoom=e.hitch(this,this._updateAnimatedZoom);this._updateAnimatedPan=e.hitch(this,this._updateAnimatedPan);this._onAnimPanEnd=e.hitch(this,this._onAnimPanEnd)},buildRendering:function(){this.inherited(arguments);this.canvas=e.create("canvas",{},this.domNode);e.addClass(this.domNode,"mblImageView")},postCreate:function(){this.inherited(arguments);
this.size=e.marginBox(this.domNode);e.style(this.canvas,{width:this.size.w+"px",height:this.size.h+"px"});this.canvas.height=this.size.h;this.canvas.width=this.size.w;var a=this;this.connect(this.domNode,"onmousedown",function(b){a.isAnimating()||(a.panX&&a.handleDragEnd(),a.downX=b.targetTouches?b.targetTouches[0].clientX:b.clientX,a.downY=b.targetTouches?b.targetTouches[0].clientY:b.clientY)});this.connect(this.domNode,"onmousemove",function(b){if(!a.isAnimating()&&(a.downX||0===a.downX)&&(a.downY||
0===a.downY)&&(!a.disableSwipe&&1==a.zoom||!a.disableAutoZoom&&1!=a.zoom)){var c=b.targetTouches?b.targetTouches[0].clientY:b.pageY;a.panX=(b.targetTouches?b.targetTouches[0].clientX:b.pageX)-a.downX;a.panY=c-a.downY;1==a.zoom?10<Math.abs(a.panX)&&a.render():(10<Math.abs(a.panX)||10<Math.abs(a.panY))&&a.render()}});this.connect(this.domNode,"onmouseout",function(b){!a.isAnimating()&&a.panX&&a.handleDragEnd()});this.connect(this.domNode,"onmouseover",function(b){a.downX=a.downY=null});this.connect(this.domNode,
"onclick",function(b){if(!a.isAnimating()&&null!=a.downX&&null!=a.downY){var c=b.targetTouches?b.targetTouches[0].clientX:b.pageX;b=b.targetTouches?b.targetTouches[0].clientY:b.pageY;if(14<Math.abs(a.panX)||14<Math.abs(a.panY))a.downX=a.downY=null,a.handleDragEnd();else if(a.downX=a.downY=null,!a.disableAutoZoom&&a._centerImg&&a._centerImg._loaded)if(1!=a.zoom)a.set("animatedZoom",1);else{var d=e._abs(a.domNode);a.zoomTo((c-d.x)/(a.size.w/a._centerImg.width)-a.panX,(b-d.y)/(a.size.h/a._centerImg.height)-
a.panY,a.autoZoomLevel)}}});e.connect(this.domNode,"flick",this,"handleFlick")},isAnimating:function(){return this._anim&&"playing"==this._anim.status()},handleDragEnd:function(){this.downX=this.downY=null;if(1==this.zoom){if(this.panX){var a=this._leftImg&&this._leftImg._loaded||this._leftSmallImg&&this._leftSmallImg._loaded,b=this._rightImg&&this._rightImg._loaded||this._rightSmallImg&&this._rightSmallImg._loaded;Math.abs(this.panX)<this._centerImg._baseWidth/2||!(0<this.panX&&a||0>this.panX&&b)?
this._animPanTo(0,e.fx.easing.expoOut,700):this.moveTo(this.panX)}}else if(this.panX||this.panY)this.zoomCenterX-=this.panX/this.zoom,this.zoomCenterY-=this.panY/this.zoom,this.panX=this.panY=0},handleFlick:function(a){1==this.zoom&&500>a.duration&&("ltr"==a.direction?this.moveTo(1):"rtl"==a.direction&&this.moveTo(-1),this.downX=this.downY=null)},moveTo:function(a){a=0<a?1:-1;if(1>a)if(this._rightImg&&this._rightImg._loaded)var b=this._rightImg;else this._rightSmallImg&&this._rightSmallImg._loaded&&
(b=this._rightSmallImg);else this._leftImg&&this._leftImg._loaded?b=this._leftImg:this._leftSmallImg&&this._leftSmallImg._loaded&&(b=this._leftSmallImg);this._moveDir=a;var c=this;b&&b._loaded?this._animPanTo(this.size.w*a,null,500,function(){c.panX=0;c.panY=0;0>a?c._switchImage("left","right"):c._switchImage("right","left");c.render();c.onChange(-1*a)}):this._animPanTo(0,e.fx.easing.expoOut,700)},_switchImage:function(a,b){var c="_"+a+"SmallImg",d="_"+a+"Img",g="_"+b+"SmallImg",f="_"+b+"Img";this[d]=
this._centerImg;this[c]=this._centerSmallImg;this[d]._type=a;this[c]&&(this[c]._type=a);this._centerImg=this[f];this._centerSmallImg=this[g];this._centerImg._type="center";this._centerSmallImg&&(this._centerSmallImg._type="center");this[f]=this[g]=null},_animPanTo:function(a,b,c,d){this._animCallback=d;this._anim=new e.Animation({curve:[this.panX,a],onAnimate:this._updateAnimatedPan,duration:c||500,easing:b,onEnd:this._onAnimPanEnd});this._anim.play();return this._anim},onChange:function(a){},_updateAnimatedPan:function(a){this.panX=
a;this.render()},_onAnimPanEnd:function(){this.panX=this.panY=0;this._animCallback&&this._animCallback()},zoomTo:function(a,b,c){this.set("zoomCenterX",a);this.set("zoomCenterY",b);this.set("animatedZoom",c)},render:function(){this.canvas.getContext("2d").clearRect(0,0,this.canvas.width,this.canvas.height);this._renderImg(this._centerSmallImg,this._centerImg,1==this.zoom?0>this.panX?1:0<this.panX?-1:0:0);1==this.zoom&&0!=this.panX&&(0<this.panX?this._renderImg(this._leftSmallImg,this._leftImg,1):
this._renderImg(this._rightSmallImg,this._rightImg,-1))},_renderImg:function(a,b,c){if((a=b&&b._loaded?b:a)&&a._loaded){b=this.canvas.getContext("2d");var d=a._baseWidth*this.zoom,g=a._baseHeight*this.zoom,f=Math.min(this.size.w,d),l=Math.min(this.size.h,g);d=this.dispWidth=f/d*a.width;g=this.dispHeight=l/g*a.height;var h=Math.max(0,Math.round((a.width-d)/2+(Math.floor(Math.max(d/2,Math.min(a.width-d/2,this.zoomCenterX-this.panX/this.zoom)))-a._centerX))),q=Math.max(0,Math.round((a.height-g)/2+(Math.floor(Math.max(g/
2,Math.min(a.height-g/2,this.zoomCenterY-this.panY/this.zoom)))-a._centerY))),k=Math.round(Math.max(0,this.canvas.width-f)/2),r=Math.round(Math.max(0,this.canvas.height-l)/2),m=f,n=d;1==this.zoom&&c&&this.panX&&(0>this.panX?0<c?(f-=Math.abs(this.panX),k=0):0>c&&(f=Math.max(1,Math.abs(this.panX)-5),k=this.size.w-f):0<c?(f=Math.max(1,Math.abs(this.panX)-5),k=0):0>c&&(f-=Math.abs(this.panX),k=this.size.w-f),d=Math.max(1,Math.floor(f/m*d)),0<c&&(h=h+n-d),h=Math.floor(h));try{b.drawImage(a,Math.max(0,
h),q,Math.min(n,d),g,k,r,Math.min(m,f),l)}catch(u){}}},_setZoomAttr:function(a){this.zoom=Math.min(this.maxZoom,Math.max(1,a));1==this.zoom&&this._centerImg&&this._centerImg._loaded&&(this.isAnimating()||(this.zoomCenterX=this._centerImg.width/2,this.zoomCenterY=this._centerImg.height/2),this.panX=this.panY=0);this.render()},_setZoomCenterXAttr:function(a){a!=this.zoomCenterX&&(this._centerImg&&this._centerImg._loaded&&(a=Math.min(this._centerImg.width,a)),this.zoomCenterX=Math.max(0,Math.round(a)))},
_setZoomCenterYAttr:function(a){a!=this.zoomCenterY&&(this._centerImg&&this._centerImg._loaded&&(a=Math.min(this._centerImg.height,a)),this.zoomCenterY=Math.max(0,Math.round(a)))},_setZoomCenterAttr:function(a){if(a.x!=this.zoomCenterX||a.y!=this.zoomCenterY)this.set("zoomCenterX",a.x),this.set("zoomCenterY",a.y),this.render()},_setAnimatedZoomAttr:function(a){this._anim&&"playing"==this._anim.status()||(this._anim=new e.Animation({curve:[this.zoom,a],onAnimate:this._updateAnimatedZoom,onEnd:this._onAnimEnd}),
this._anim.play())},_updateAnimatedZoom:function(a){this._setZoomAttr(a)},_setCenterUrlAttr:function(a){this._setImage("center",a)},_setLeftUrlAttr:function(a){this._setImage("left",a)},_setRightUrlAttr:function(a){this._setImage("right",a)},_setImage:function(a,b){var c=null,d=null;e.isString(b)?d=b:(d=b.large,c=b.small);if(!this["_"+a+"Img"]||this["_"+a+"Img"]._src!=d){var g=this["_"+a+"Img"]=new Image;g._type=a;g._loaded=!1;g._src=d;g._conn=e.connect(g,"onload",this.handleLoad);if(c){var f=this["_"+
a+"SmallImg"]=new Image;f._type=a;f._loaded=!1;f._conn=e.connect(f,"onload",this.handleLoad);f._isSmall=!0;f._src=c;f.src=c}g.src=d}},handleLoad:function(a){a=a.target;a._loaded=!0;e.disconnect(a._conn);switch(a._type){case "center":this.zoomCenterX=a.width/2,this.zoomCenterY=a.height/2}var b=a.height,c=a.width;c/this.size.w<b/this.size.h?(a._baseHeight=this.canvas.height,a._baseWidth=c/(b/this.size.h)):(a._baseWidth=this.canvas.width,a._baseHeight=b/(c/this.size.w));a._centerX=c/2;a._centerY=b/2;
this.render();this.onLoad(a._type,a._src,a._isSmall)},onLoad:function(a,b,c){}})});