// generated by coffeescript 1.9.3 (function(){var e;e=function(){function e(e,t){var n,r;this.options={target:"instafeed",get:"popular",resolution:"thumbnail",sortby:"none",links:!0,mock:!1,usehttp:!1};if(typeof e=="object")for(n in e)r=e[n],this.options[n]=r;this.context=t!=null?t:this,this.unique=this._genkey()}return e.prototype.hasnext=function(){return typeof this.context.nexturl=="string"&&this.context.nexturl.length>0},e.prototype.next=function(){return this.hasnext()?this.run(this.context.nexturl):!1},e.prototype.run=function(t){var n,r,i;if(typeof this.options.clientid!="string"&&typeof this.options.accesstoken!="string")throw new error("missing clientid or accesstoken.");if(typeof this.options.accesstoken!="string"&&typeof this.options.clientid!="string")throw new error("missing clientid or accesstoken.");return this.options.before!=null&&typeof this.options.before=="function"&&this.options.before.call(this),typeof document!="undefined"&&document!==null&&(i=document.createelement("script"),i.id="instafeed-fetcher",i.src=t||this._buildurl(),n=document.getelementsbytagname("head"),n[0].appendchild(i),r="instafeedcache"+this.unique,window[r]=new e(this.options,this),window[r].unique=this.unique),!0},e.prototype.parse=function(e){var t,n,r,i,s,o,u,a,f,l,c,h,p,d,v,m,g,y,b,w,e,s,x,t,n,c,k,l,a,o,m,_,d;if(typeof e!="object"){if(this.options.error!=null&&typeof this.options.error=="function")return this.options.error.call(this,"invalid json data"),!1;throw new error("invalid json response")}if(e.meta.code!==200){if(this.options.error!=null&&typeof this.options.error=="function")return this.options.error.call(this,e.meta.error_message),!1;throw new error("error from instagram: "+e.meta.error_message)}if(e.data.length===0){if(this.options.error!=null&&typeof this.options.error=="function")return this.options.error.call(this,"no images were returned from instagram"),!1;throw new error("no images were returned from instagram")}this.options.success!=null&&typeof this.options.success=="function"&&this.options.success.call(this,e),this.context.nexturl="",e.pagination!=null&&(this.context.nexturl=e.pagination.next_url);if(this.options.sortby!=="none"){this.options.sortby==="random"?m=["","random"]:m=this.options.sortby.split("-"),o=m[0]==="least"?!0:!1;switch(m[1]){case"random":e.data.sort(function(){return.5-math.random()});break;case"recent":e.data=this._sortby(e.data,"created_time",o);break;case"liked":e.data=this._sortby(e.data,"likes.count",o);break;case"commented":e.data=this._sortby(e.data,"comments.count",o);break;default:throw new error("invalid option for sortby: '"+this.options.sortby+"'.")}}if(typeof document!="undefined"&&document!==null&&this.options.mock===!1){m=e.data,a=parseint(this.options.limit,10),this.options.limit!=null&&m.length>a&&(m=m.slice(0,a)),u=document.createdocumentfragment(),this.options.filter!=null&&typeof this.options.filter=="function"&&(m=this._filter(m,this.options.filter));if(this.options.template!=null&&typeof this.options.template=="string"){f="",d="",w="",d=document.createelement("div");for(c=0,n=m.length;cy&&(b="landscape"),e=0,l&&!this.options.usehttp&&(v=v.replace(/https?:\/\//,"//")),d=this._maketemplate(this.options.template,{model:h,id:h.id,link:h.link,type:h.type,image:v,width:e,height:y,orientation:b,caption:this._getobjectproperty(h,"caption.text"),likes:h.likes.count,comments:h.comments.count,location:this._getobjectproperty(h,"location.name")}),f+=d}d.innerhtml=f,i=[],r=0,n=d.childnodes.length;while(r=0,l&&!this.options.usehttp&&(v=v.replace(/https?:\/\//,"//")),g.src=v,this.options.links===!0?(t=document.createelement("a"),t.href=h.link,t.appendchild(g),u.appendchild(t)):u.appendchild(g)}_=this.options.target,typeof _=="string"&&(_=document.getelementbyid(_));if(_==null)throw o='no element with id="'+this.options.target+'" on page.',new error(o);_.appendchild(u),a=document.getelementsbytagname("head")[0],a.removechild(document.getelementbyid("instafeed-fetcher")),s="instafeedcache"+this.unique,window[s]=void 0;try{delete window[s]}catch(p){s=p}}return this.options.after!=null&&typeof this.options.after=="function"&&this.options.after.call(this),!0},e.prototype._buildurl=function(){var e,t,n;e="https://api.instagram.com/v1";switch(this.options.get){case"popular":t="media/popular";break;case"tagged":if(!this.options.tagname)throw new error("no tag name specified. use the 'tagname' option.");t="tags/"+this.options.tagname+"/media/recent";break;case"location":if(!this.options.locationid)throw new error("no location specified. use the 'locationid' option.");t="locations/"+this.options.locationid+"/media/recent";break;case"user":if(!this.options.userid)throw new error("no user specified. use the 'userid' option.");t="users/"+this.options.userid+"/media/recent";break;default:throw new error("invalid option for get: '"+this.options.get+"'.")}return n=e+"/"+t,this.options.accesstoken!=null?n+="?access_token="+this.options.accesstoken:n+="?client_id="+this.options.clientid,this.options.limit!=null&&(n+="&count="+this.options.limit),n+="&callback=instafeedcache"+this.unique+".parse",n},e.prototype._genkey=function(){var e;return e=function(){return((1+math.random())*65536|0).tostring(16).substring(1)},""+e()+e()+e()+e()},e.prototype._maketemplate=function(e,t){var n,r,i,s,o;r=/(?:\{{2})([\w\[\]\.]+)(?:\}{2})/,n=e;while(r.test(n))s=n.match(r)[1],o=(i=this._getobjectproperty(t,s))!=null?i:"",n=n.replace(r,function(){return""+o});return n},e.prototype._getobjectproperty=function(e,t){var n,r;t=t.replace(/\[(\w+)\]/g,".$1"),r=t.split(".");while(r.length){n=r.shift();if(!(e!=null&&n in e))return null;e=e[n]}return e},e.prototype._sortby=function(e,t,n){var r;return r=function(e,r){var i,s;return i=this._getobjectproperty(e,t),s=this._getobjectproperty(r,t),n?i>s?1:-1:i