//>>built
define("dojox/data/FlickrRestStore","dojo/_base/lang dojo/_base/declare dojo/_base/array dojo/io/script dojox/data/FlickrStore dojo/_base/connect".split(" "),function(v,A,w,B,y,C){var z=A("dojox.data.FlickrRestStore",y,{constructor:function(a){a&&(a.label&&(this.label=a.label),a.apikey&&(this._apikey=a.apikey));this._cache=[];this._prevRequests={};this._handlers={};this._prevRequestRanges=[];this._maxPhotosPerUser={};this._id=z.prototype._id++},_id:0,_requestCount:0,_flickrRestUrl:"https://www.flickr.com/services/rest/",
_apikey:null,_storeRef:"_S",_cache:null,_prevRequests:null,_handlers:null,_sortAttributes:{"date-posted":!0,"date-taken":!0,interestingness:!0},_fetchItems:function(a,f,q){var b={};a.query?v.mixin(b,a.query):a.query=b={};var d=[],e=[],c={format:"json",method:"flickr.photos.search",api_key:this._apikey,extras:"owner_name,date_upload,date_taken"};b.userid&&(c.user_id=a.query.userid,d.push("userid"+a.query.userid));b.groupid&&(c.group_id=b.groupid,d.push("groupid"+b.groupid));if(b.apikey)c.api_key=a.query.apikey,
e.push("api"+a.query.apikey);else if(c.api_key)a.query.apikey=c.api_key,e.push("api"+c.api_key);else throw Error("dojox.data.FlickrRestStore: An API key must be specified.");a._curCount=a.count;if(b.page)c.page=a.query.page,e.push("page"+c.page);else if("start"in a&&null!==a.start){a.count||(a.count=20);var h=a.start,p=a.count;if(0!==a.start%a.count){if(h<p/2)p=h+p,h=0;else{for(var r=2,t=20;0<t;t--)if(0===h%t&&h/t>=p){r=t;break}p=h/r}a._realStart=a.start;a._realCount=a.count;a._curStart=h;a._curCount=
p}else a._realStart=a._realCount=null,a._curStart=a.start,a._curCount=a.count;c.page=h/p+1;e.push("page"+c.page)}a._curCount&&(c.per_page=a._curCount,e.push("count"+a._curCount));b.lang&&(c.lang=a.query.lang,d.push("lang"+a.lang));b.setid&&(c.method="flickr.photosets.getPhotos",c.photoset_id=a.query.setid,d.push("set"+a.query.setid));b.tags&&(c.tags=b.tags instanceof Array?b.tags.join(","):b.tags,d.push("tags"+c.tags),!b.tag_mode||"any"!==b.tag_mode.toLowerCase()&&"all"!==b.tag_mode.toLowerCase()||
(c.tag_mode=b.tag_mode));b.text&&(c.text=b.text,d.push("text:"+b.text));b.sort&&0<b.sort.length?(b.sort[0].attribute||(b.sort[0].attribute="date-posted"),this._sortAttributes[b.sort[0].attribute]&&(c.sort=b.sort[0].descending?b.sort[0].attribute+"-desc":b.sort[0].attribute+"-asc")):c.sort="date-posted-asc";d.push("sort:"+c.sort);d=d.join(".");e=0<e.length?"."+e.join("."):"";var l=d+e;a={query:b,count:a._curCount,start:a._curStart,_realCount:a._realCount,_realStart:a._realStart,onBegin:a.onBegin,onComplete:a.onComplete,
onItem:a.onItem};f={request:a,fetchHandler:f,errorHandler:q};if(this._handlers[l])this._handlers[l].push(f);else{this._handlers[l]=[f];b={url:this._flickrRestUrl,preventCache:this.urlPreventCache,content:c,callbackParamName:"jsoncallback"};var x=v.hitch(this,function(m,n,k){var u=k.request.onBegin;k.request.onBegin=null;var g=k.request;"_realStart"in g&&null!=g._realStart&&(g.start=g._realStart,g.count=g._realCount,g._realStart=g._realCount=null);u&&(g=null,n&&(g=n.photoset?n.photoset:n.photos),g&&
"perpage"in g&&"pages"in g?(n=g.perpage*g.pages<=k.request.start+k.request.count?k.request.start+g.photo.length:g.perpage*g.pages,this._maxPhotosPerUser[d]=n,u(n,k.request)):this._maxPhotosPerUser[d]&&u(this._maxPhotosPerUser[d],k.request));k.fetchHandler(m,k.request);u&&(k.request.onBegin=u)});c=v.hitch(this,function(m){if("ok"!=m.stat)q(null,a);else{var n=this._handlers[l];if(n){this._handlers[l]=null;this._prevRequests[l]=m;var k=this._processFlickrData(m,a,d);this._prevRequestRanges[d]||(this._prevRequestRanges[d]=
[]);this._prevRequestRanges[d].push({start:a.start,end:a.start+(m.photoset?m.photoset.photo.length:m.photos.photo.length)});w.forEach(n,function(u){x(k,m,u)})}}});(e=this._prevRequests[l])?(this._handlers[l]=null,x(this._cache[d],e,f)):this._checkPrevRanges(d,a.start,a.count)?(this._handlers[l]=null,x(this._cache[d],null,f)):(f=B.get(b),f.addCallback(c),f.addErrback(function(m){C.disconnect(null);q(m,a)}))}},getAttributes:function(a){return"title author imageUrl imageUrlSmall imageUrlMedium imageUrlThumb imageUrlLarge imageUrlOriginal link dateTaken datePublished".split(" ")},
getValues:function(a,f){this._assertIsItem(a);this._assertIsAttribute(f);switch(f){case "title":return[this._unescapeHtml(a.title)];case "author":return[a.ownername];case "imageUrlSmall":return[a.media.s];case "imageUrl":return[a.media.l];case "imageUrlOriginal":return[a.media.o];case "imageUrlLarge":return[a.media.l];case "imageUrlMedium":return[a.media.m];case "imageUrlThumb":return[a.media.t];case "link":return["https://www.flickr.com/photos/"+a.owner+"/"+a.id];case "dateTaken":return[a.datetaken];
case "datePublished":return[a.datepublished]}},_processFlickrData:function(a,f,q){if(a.items)return y.prototype._processFlickrData.apply(this,arguments);var b=["http://farm",null,".static.flickr.com/",null,"/",null,"_",null],d=[],e=a.photoset?a.photoset:a.photos;if("ok"==a.stat&&e&&e.photo)for(d=e.photo,e=0;e<d.length;e++){var c=d[e];c[this._storeRef]=this;b[1]=c.farm;b[3]=c.server;b[5]=c.id;b[7]=c.secret;var h=b.join("");c.media={s:h+"_s.jpg",m:h+"_m.jpg",l:h+".jpg",t:h+"_t.jpg",o:h+"_o.jpg"};!c.owner&&
a.photoset&&(c.owner=a.photoset.owner)}var p=f.start?f.start:0,r=this._cache[q];r||(this._cache[q]=r=[]);w.forEach(d,function(t,l){r[l+p]=t});return r},_checkPrevRanges:function(a,f,q){var b=f+q;a=this._prevRequestRanges[a];return!!a&&w.some(a,function(d){return f>=d.start&&b<=d.end})}});return z});