//>>built
define("dojox/mobile/app/ImageThumbView",["dojo","dijit","dojox","dojo/require!dijit/_WidgetBase,dojo/string"],function(b,k,l){b.provide("dojox.mobile.app.ImageThumbView");b.experimental("dojox.mobile.app.ImageThumbView");b.require("dijit._WidgetBase");b.require("dojo.string");b.declare("dojox.mobile.app.ImageThumbView",k._WidgetBase,{items:[],urlParam:"url",labelParam:null,itemTemplate:'\x3cdiv class\x3d"mblThumbInner"\x3e\x3cdiv class\x3d"mblThumbOverlay"\x3e\x3c/div\x3e\x3cdiv class\x3d"mblThumbMask"\x3e\x3cdiv class\x3d"mblThumbSrc" style\x3d"background-image:url(${url})"\x3e\x3c/div\x3e\x3c/div\x3e\x3c/div\x3e',
minPadding:4,maxPerRow:3,maxRows:-1,baseClass:"mblImageThumbView",thumbSize:"medium",animationEnabled:!0,selectedIndex:-1,cache:null,cacheMustMatch:!1,clickEvent:"onclick",cacheBust:!1,disableHide:!1,constructor:function(a,c){},postCreate:function(){this.inherited(arguments);var a=this;this.addThumb=b.hitch(this,this.addThumb);this.handleImgLoad=b.hitch(this,this.handleImgLoad);this.hideCached=b.hitch(this,this.hideCached);this._onLoadImages={};this.cache=[];this.visibleImages=[];this._cacheCounter=
0;this.connect(this.domNode,this.clickEvent,function(c){(c=a._getItemNodeFromEvent(c))&&!c._cached&&(a.onSelect(c._item,c._index,a.items),b.query(".selected",this.domNode).removeClass("selected"),b.addClass(c,"selected"))});b.addClass(this.domNode,this.thumbSize);this.resize();this.render()},onSelect:function(a,c,b){},_setAnimationEnabledAttr:function(a){this.animationEnabled=a;b[a?"addClass":"removeClass"](this.domNode,"animated")},_setItemsAttr:function(a){this.items=a||[];a={};var c;for(c=0;c<
this.items.length;c++)a[this.items[c][this.urlParam]]=1;var e=[],d;for(d in this._onLoadImages)!a[d]&&this._onLoadImages[d]._conn&&(b.disconnect(this._onLoadImages[d]._conn),this._onLoadImages[d].src=null,e.push(d));for(c=0;c<e.length;c++)delete this._onLoadImages[d];this.render()},_getItemNode:function(a){for(;a&&!b.hasClass(a,"mblThumb")&&a!=this.domNode;)a=a.parentNode;return a==this.domNode?null:a},_getItemNodeFromEvent:function(a){a.touches&&0<a.touches.length&&(a=a.touches[0]);return this._getItemNode(a.target)},
resize:function(){this._thumbSize=null;this._size=b.contentBox(this.domNode);this.disableHide=!0;this.render();this.disableHide=!1},hideCached:function(){for(var a=0;a<this.cache.length;a++)this.cache[a]&&b.style(this.cache[a],"display","none")},render:function(){for(var a,c,e;this.visibleImages&&0<this.visibleImages.length;)a=this.visibleImages.pop(),this.cache.push(a),this.disableHide||b.addClass(a,"hidden"),a._cached=!0;this.cache&&0<this.cache.length&&setTimeout(this.hideCached,1E3);if(this.items&&
0!=this.items.length){for(a=0;a<this.items.length&&!(e=this.items[a],c=b.isString(e)?e:e[this.urlParam],this.addThumb(e,c,a),0<this.maxRows&&(a+1)/this.maxPerRow>=this.maxRows);a++);if(this._thumbSize){c=0;e=-1;var d=this._thumbSize.w+2*this.padding,g=this._thumbSize.h+2*this.padding,f=this.thumbNodes=b.query(".mblThumb",this.domNode),h=0,f=this.visibleImages;for(a=0;a<f.length;a++)if(!f[a]._cached){0==h%this.maxPerRow&&e++;c=h%this.maxPerRow;this.place(f[a],c*d+this.padding,e*g+this.padding);f[a]._loading||
b.removeClass(f[a],"hidden");if(h==this.selectedIndex)b[h==this.selectedIndex?"addClass":"removeClass"](f[a],"selected");h++}this._numRows=a=Math.ceil(h/this.maxPerRow);this.setContainerHeight(a*(this._thumbSize.h+2*this.padding))}}},setContainerHeight:function(a){b.style(this.domNode,"height",a+"px")},addThumb:function(a,c,e){var d,g=!1;if(0<this.cache.length){for(var f=0;f<this.cache.length;f++)if(this.cache[f]._url==c){d=this.cache.splice(f,1)[0];break}d||this.cacheMustMatch?g=!0:(d=this.cache.pop(),
b.removeClass(d,"selected"))}d||(d=b.create("div",{"class":"mblThumb hidden",innerHTML:b.string.substitute(this.itemTemplate,{url:c},null,this)},this.domNode));this.labelParam&&((f=b.query(".mblThumbLabel",d)[0])||(f=b.create("div",{"class":"mblThumbLabel"},d)),f.innerHTML=a[this.labelParam]||"");b.style(d,"display","");this.disableHide||b.addClass(d,"hidden");!g&&(g=b.create("img",{}),g._thumbDiv=d,g._conn=b.connect(g,"onload",this.handleImgLoad),g._url=c,d._loading=!0,this._onLoadImages[c]=g)&&
(g.src=c);this.visibleImages.push(d);d._index=e;d._item=a;d._url=c;d._cached=!1;this._thumbSize||(this._thumbSize=b.marginBox(d),0==this._thumbSize.h&&(this._thumbSize.h=100,this._thumbSize.w=100),this.labelParam&&(this._thumbSize.h+=8),this.calcPadding())},handleImgLoad:function(a){a=a.target;b.disconnect(a._conn);b.removeClass(a._thumbDiv,"hidden");a._thumbDiv._loading=!1;a._conn=null;var c=a._url;this.cacheBust&&(c+=(-1<c.indexOf("?")?"\x26":"?")+"cacheBust\x3d"+(new Date).getTime()+"_"+this._cacheCounter++);
b.query(".mblThumbSrc",a._thumbDiv).style("backgroundImage","url("+c+")");delete this._onLoadImages[a._url]},calcPadding:function(){var a=this._size.w,c=this._thumbSize.w;this.maxPerRow=Math.floor(a/(c+this.minPadding));this.padding=Math.floor((a-c*this.maxPerRow)/(2*this.maxPerRow))},place:function(a,c,e){b.style(a,{"-webkit-transform":"translate("+c+"px,"+e+"px)"})},destroy:function(){var a,c=0,b;for(b in this._onLoadImages)if(a=this._onLoadImages[b])a.src=null,c++;this.inherited(arguments)}})});