text: (function(){function t(t){function e(e,n,r,i,s,o){for(;s>=0&&s<o;s+=t){var a=i?i[s]:s;r=n(r,e[a],a,e)}return r}return function(n,r,i,s){r=_(r,s,4);var o=!E(n)&&m.keys(n),a=(o||n).length,c=t>0?0:a-1;return arguments.length<3&&(i=n[o?o[c]:c],c+=t),e(n,r,i,o,c,a)}}function e(t){return function(e,n,r){n=b(n,r);for(var i=k(e),s=t>0?0:i-1;s>=0&&s<i;s+=t)if(n(e[s],s,e))return s;return-1}}function n(t,e,n){return function(r,i,s){var o=0,a=k(r);if("number"==typeof s)t>0?o=s>=0?s:Math.max(s+a,o):a=s>=0?Math.min(s+1,a):s+a+1;else if(n&&s&&a)return s=n(r,i),r[s]===i?s:-1;if(i!==i)return s=e(l.call(r,o,a),m.isNaN),s>=0?s+o:-1;for(s=t>0?o:a-1;s>=0&&s<a;s+=t)if(r[s]===i)return s;return-1}}function r(t,e){var n=$.length,r=t.constructor,i=m.isFunction(r)&&r.prototype||a,s="constructor";for(m.has(t,s)&&!m.contains(e,s)&&e.push(s);n--;)s=$[n],s in t&&t[s]!==i[s]&&!m.contains(e,s)&&e.push(s)}var i=this,s=i._,o=Array.prototype,a=Object.prototype,c=Function.prototype,u=o.push,l=o.slice,h=a.toString,f=a.hasOwnProperty,d=Array.isArray,p=Object.keys,v=c.bind,g=Object.create,y=function(){},m=function(t){return t instanceof m?t:this instanceof m?void(this._wrapped=t):new m(t)};"undefined"!=typeof exports?("undefined"!=typeof module&&module.exports&&(exports=module.exports=m),exports._=m):i._=m,m.VERSION="1.8.3";var _=function(t,e,n){if(void 0===e)return t;switch(null==n?3:n){case 1:return function(n){return t.call(e,n)};case 2:return function(n,r){return t.call(e,n,r)};case 3:return function(n,r,i){return t.call(e,n,r,i)};case 4:return function(n,r,i,s){return t.call(e,n,r,i,s)}}return function(){return t.apply(e,arguments)}},b=function(t,e,n){return null==t?m.identity:m.isFunction(t)?_(t,e,n):m.isObject(t)?m.matcher(t):m.property(t)};m.iteratee=function(t,e){return b(t,e,1/0)};var x=function(t,e){return function(n){var r=arguments.length;if(r<2||null==n)return n;for(var i=1;i<r;i++)for(var s=arguments[i],o=t(s),a=o.length,c=0;c<a;c++){var u=o[c];e&&void 0!==n[u]||(n[u]=s[u])}return n}},w=function(t){if(!m.isObject(t))return{};if(g)return g(t);y.prototype=t;var e=new y;return y.prototype=null,e},C=function(t){return function(e){return null==e?void 0:e[t]}},S=Math.pow(2,53)-1,k=C("length"),E=function(t){var e=k(t);return"number"==typeof e&&e>=0&&e<=S};m.each=m.forEach=function(t,e,n){e=_(e,n);var r,i;if(E(t))for(r=0,i=t.length;r<i;r++)e(t[r],r,t);else{var s=m.keys(t);for(r=0,i=s.length;r<i;r++)e(t[s[r]],s[r],t)}return t},m.map=m.collect=function(t,e,n){e=b(e,n);for(var r=!E(t)&&m.keys(t),i=(r||t).length,s=Array(i),o=0;o<i;o++){var a=r?r[o]:o;s[o]=e(t[a],a,t)}return s},m.reduce=m.foldl=m.inject=t(1),m.reduceRight=m.foldr=t(-1),m.find=m.detect=function(t,e,n){var r;if(r=E(t)?m.findIndex(t,e,n):m.findKey(t,e,n),void 0!==r&&r!==-1)return t[r]},m.filter=m.select=function(t,e,n){var r=[];return e=b(e,n),m.each(t,function(t,n,i){e(t,n,i)&&r.push(t)}),r},m.reject=function(t,e,n){return m.filter(t,m.negate(b(e)),n)},m.every=m.all=function(t,e,n){e=b(e,n);for(var r=!E(t)&&m.keys(t),i=(r||t).length,s=0;s<i;s++){var o=r?r[s]:s;if(!e(t[o],o,t))return!1}return!0},m.some=m.any=function(t,e,n){e=b(e,n);for(var r=!E(t)&&m.keys(t),i=(r||t).length,s=0;s<i;s++){var o=r?r[s]:s;if(e(t[o],o,t))return!0}return!1},m.contains=m.includes=m.include=function(t,e,n,r){return E(t)||(t=m.values(t)),("number"!=typeof n||r)&&(n=0),m.indexOf(t,e,n)>=0},m.invoke=function(t,e){var n=l.call(arguments,2),r=m.isFunction(e);return m.map(t,function(t){var i=r?e:t[e];return null==i?i:i.apply(t,n)})},m.pluck=function(t,e){return m.map(t,m.property(e))},m.where=function(t,e){return m.filter(t,m.matcher(e))},m.findWhere=function(t,e){return m.find(t,m.matcher(e))},m.max=function(t,e,n){var r,i,s=-(1/0),o=-(1/0);if(null==e&&null!=t){t=E(t)?t:m.values(t);for(var a=0,c=t.length;a<c;a++)r=t[a],r>s&&(s=r)}else e=b(e,n),m.each(t,function(t,n,r){i=e(t,n,r),(i>o||i===-(1/0)&&s===-(1/0))&&(s=t,o=i)});return s},m.min=function(t,e,n){var r,i,s=1/0,o=1/0;if(null==e&&null!=t){t=E(t)?t:m.values(t);for(var a=0,c=t.length;a<c;a++)r=t[a],r<s&&(s=r)}else e=b(e,n),m.each(t,function(t,n,r){i=e(t,n,r),(i<o||i===1/0&&s===1/0)&&(s=t,o=i)});return s},m.shuffle=function(t){for(var e,n=E(t)?t:m.values(t),r=n.length,i=Array(r),s=0;s<r;s++)e=m.random(0,s),e!==s&&(i[s]=i[e]),i[e]=n[s];return i},m.sample=function(t,e,n){return null==e||n?(E(t)||(t=m.values(t)),t[m.random(t.length-1)]):m.shuffle(t).slice(0,Math.max(0,e))},m.sortBy=function(t,e,n){return e=b(e,n),m.pluck(m.map(t,function(t,n,r){return{value:t,index:n,criteria:e(t,n,r)}}).sort(function(t,e){var n=t.criteria,r=e.criteria;if(n!==r){if(n>r||void 0===n)return 1;if(n<r||void 0===r)return-1}return t.index-e.index}),"value")};var j=function(t){return function(e,n,r){var i={};return n=b(n,r),m.each(e,function(r,s){var o=n(r,s,e);t(i,r,o)}),i}};m.groupBy=j(function(t,e,n){m.has(t,n)?t[n].push(e):t[n]=[e]}),m.indexBy=j(function(t,e,n){t[n]=e}),m.countBy=j(function(t,e,n){m.has(t,n)?t[n]++:t[n]=1}),m.toArray=function(t){return t?m.isArray(t)?l.call(t):E(t)?m.map(t,m.identity):m.values(t):[]},m.size=function(t){return null==t?0:E(t)?t.length:m.keys(t).length},m.partition=function(t,e,n){e=b(e,n);var r=[],i=[];return m.each(t,function(t,n,s){(e(t,n,s)?r:i).push(t)}),[r,i]},m.first=m.head=m.take=function(t,e,n){if(null!=t)return null==e||n?t[0]:m.initial(t,t.length-e)},m.initial=function(t,e,n){return l.call(t,0,Math.max(0,t.length-(null==e||n?1:e)))},m.last=function(t,e,n){if(null!=t)return null==e||n?t[t.length-1]:m.rest(t,Math.max(0,t.length-e))},m.rest=m.tail=m.drop=function(t,e,n){return l.call(t,null==e||n?1:e)},m.compact=function(t){return m.filter(t,m.identity)};var A=function(t,e,n,r){for(var i=[],s=0,o=r||0,a=k(t);o<a;o++){var c=t[o];if(E(c)&&(m.isArray(c)||m.isArguments(c))){e||(c=A(c,e,n));var u=0,l=c.length;for(i.length+=l;u<l;)i[s++]=c[u++]}else n||(i[s++]=c)}return i};m.flatten=function(t,e){return A(t,e,!1)},m.without=function(t){return m.difference(t,l.call(arguments,1))},m.uniq=m.unique=function(t,e,n,r){m.isBoolean(e)||(r=n,n=e,e=!1),null!=n&&(n=b(n,r));for(var i=[],s=[],o=0,a=k(t);o<a;o++){var c=t[o],u=n?n(c,o,t):c;e?(o&&s===u||i.push(c),s=u):n?m.contains(s,u)||(s.push(u),i.push(c)):m.contains(i,c)||i.push(c)}return i},m.union=function(){return m.uniq(A(arguments,!0,!0))},m.intersection=function(t){for(var e=[],n=arguments.length,r=0,i=k(t);r<i;r++){var s=t[r];if(!m.contains(e,s)){for(var o=1;o<n&&m.contains(arguments[o],s);o++);o===n&&e.push(s)}}return e},m.difference=function(t){var e=A(arguments,!0,!0,1);return m.filter(t,function(t){return!m.contains(e,t)})},m.zip=function(){return m.unzip(arguments)},m.unzip=function(t){for(var e=t&&m.max(t,k).length||0,n=Array(e),r=0;r<e;r++)n[r]=m.pluck(t,r);return n},m.object=function(t,e){for(var n={},r=0,i=k(t);r<i;r++)e?n[t[r]]=e[r]:n[t[r][0]]=t[r][1];return n},m.findIndex=e(1),m.findLastIndex=e(-1),m.sortedIndex=function(t,e,n,r){n=b(n,r,1);for(var i=n(e),s=0,o=k(t);s<o;){var a=Math.floor((s+o)/2);n(t[a])<i?s=a+1:o=a}return s},m.indexOf=n(1,m.findIndex,m.sortedIndex),m.lastIndexOf=n(-1,m.findLastIndex),m.range=function(t,e,n){null==e&&(e=t||0,t=0),n=n||1;for(var r=Math.max(Math.ceil((e-t)/n),0),i=Array(r),s=0;s<r;s++,t+=n)i[s]=t;return i};var I=function(t,e,n,r,i){if(!(r instanceof e))return t.apply(n,i);var s=w(t.prototype),o=t.apply(s,i);return m.isObject(o)?o:s};m.bind=function(t,e){if(v&&t.bind===v)return v.apply(t,l.call(arguments,1));if(!m.isFunction(t))throw new TypeError("Bind must be called on a function");var n=l.call(arguments,2),r=function(){return I(t,r,e,this,n.concat(l.call(arguments)))};return r},m.partial=function(t){var e=l.call(arguments,1),n=function(){for(var r=0,i=e.length,s=Array(i),o=0;o<i;o++)s[o]=e[o]===m?arguments[r++]:e[o];for(;r<arguments.length;)s.push(arguments[r++]);return I(t,n,this,this,s)};return n},m.bindAll=function(t){var e,n,r=arguments.length;if(r<=1)throw new Error("bindAll must be passed function names");for(e=1;e<r;e++)n=arguments[e],t[n]=m.bind(t[n],t);return t},m.memoize=function(t,e){var n=function(r){var i=n.cache,s=""+(e?e.apply(this,arguments):r);return m.has(i,s)||(i[s]=t.apply(this,arguments)),i[s]};return n.cache={},n},m.delay=function(t,e){var n=l.call(arguments,2);return setTimeout(function(){return t.apply(null,n)},e)},m.defer=m.partial(m.delay,m,1),m.throttle=function(t,e,n){var r,i,s,o=null,a=0;n||(n={});var c=function(){a=n.leading===!1?0:m.now(),o=null,s=t.apply(r,i),o||(r=i=null)};return function(){var u=m.now();a||n.leading!==!1||(a=u);var l=e-(u-a);return r=this,i=arguments,l<=0||l>e?(o&&(clearTimeout(o),o=null),a=u,s=t.apply(r,i),o||(r=i=null)):o||n.trailing===!1||(o=setTimeout(c,l)),s}},m.debounce=function(t,e,n){var r,i,s,o,a,c=function(){var u=m.now()-o;u<e&&u>=0?r=setTimeout(c,e-u):(r=null,n||(a=t.apply(s,i),r||(s=i=null)))};return function(){s=this,i=arguments,o=m.now();var u=n&&!r;return r||(r=setTimeout(c,e)),u&&(a=t.apply(s,i),s=i=null),a}},m.wrap=function(t,e){return m.partial(e,t)},m.negate=function(t){return function(){return!t.apply(this,arguments)}},m.compose=function(){var t=arguments,e=t.length-1;return function(){for(var n=e,r=t[e].apply(this,arguments);n--;)r=t[n].call(this,r);return r}},m.after=function(t,e){return function(){if(--t<1)return e.apply(this,arguments)}},m.before=function(t,e){var n;return function(){return--t>0&&(n=e.apply(this,arguments)),t<=1&&(e=null),n}},m.once=m.partial(m.before,2);var F=!{toString:null}.propertyIsEnumerable("toString"),$=["valueOf","isPrototypeOf","toString","propertyIsEnumerable","hasOwnProperty","toLocaleString"];m.keys=function(t){if(!m.isObject(t))return[];if(p)return p(t);var e=[];for(var n in t)m.has(t,n)&&e.push(n);return F&&r(t,e),e},m.allKeys=function(t){if(!m.isObject(t))return[];var e=[];for(var n in t)e.push(n);return F&&r(t,e),e},m.values=function(t){for(var e=m.keys(t),n=e.length,r=Array(n),i=0;i<n;i++)r[i]=t[e[i]];return r},m.mapObject=function(t,e,n){e=b(e,n);for(var r,i=m.keys(t),s=i.length,o={},a=0;a<s;a++)r=i[a],o[r]=e(t[r],r,t);return o},m.pairs=function(t){for(var e=m.keys(t),n=e.length,r=Array(n),i=0;i<n;i++)r[i]=[e[i],t[e[i]]];return r},m.invert=function(t){for(var e={},n=m.keys(t),r=0,i=n.length;r<i;r++)e[t[n[r]]]=n[r];return e},m.functions=m.methods=function(t){var e=[];for(var n in t)m.isFunction(t[n])&&e.push(n);return e.sort()},m.extend=x(m.allKeys),m.extendOwn=m.assign=x(m.keys),m.findKey=function(t,e,n){e=b(e,n);for(var r,i=m.keys(t),s=0,o=i.length;s<o;s++)if(r=i[s],e(t[r],r,t))return r},m.pick=function(t,e,n){var r,i,s={},o=t;if(null==o)return s;m.isFunction(e)?(i=m.allKeys(o),r=_(e,n)):(i=A(arguments,!1,!1,1),r=function(t,e,n){return e in n},o=Object(o));for(var a=0,c=i.length;a<c;a++){var u=i[a],l=o[u];r(l,u,o)&&(s[u]=l)}return s},m.omit=function(t,e,n){if(m.isFunction(e))e=m.negate(e);else{var r=m.map(A(arguments,!1,!1,1),String);e=function(t,e){return!m.contains(r,e)}}return m.pick(t,e,n)},m.defaults=x(m.allKeys,!0),m.create=function(t,e){var n=w(t);return e&&m.extendOwn(n,e),n},m.clone=function(t){return m.isObject(t)?m.isArray(t)?t.slice():m.extend({},t):t},m.tap=function(t,e){return e(t),t},m.isMatch=function(t,e){var n=m.keys(e),r=n.length;if(null==t)return!r;for(var i=Object(t),s=0;s<r;s++){var o=n[s];if(e[o]!==i[o]||!(o in i))return!1}return!0};var O=function(t,e,n,r){if(t===e)return 0!==t||1/t===1/e;if(null==t||null==e)return t===e;t instanceof m&&(t=t._wrapped),e instanceof m&&(e=e._wrapped);var i=h.call(t);if(i!==h.call(e))return!1;switch(i){case"[object RegExp]":case"[object String]":return""+t==""+e;case"[object Number]":return+t!==+t?+e!==+e:0===+t?1/+t===1/e:+t===+e;case"[object Date]":case"[object Boolean]":return+t===+e}var s="[object Array]"===i;if(!s){if("object"!=typeof t||"object"!=typeof e)return!1;var o=t.constructor,a=e.constructor;if(o!==a&&!(m.isFunction(o)&&o instanceof o&&m.isFunction(a)&&a instanceof a)&&"constructor"in t&&"constructor"in e)return!1}n=n||[],r=r||[];for(var c=n.length;c--;)if(n[c]===t)return r[c]===e;if(n.push(t),r.push(e),s){if(c=t.length,c!==e.length)return!1;for(;c--;)if(!O(t[c],e[c],n,r))return!1}else{var u,l=m.keys(t);if(c=l.length,m.keys(e).length!==c)return!1;for(;c--;)if(u=l[c],!m.has(e,u)||!O(t[u],e[u],n,r))return!1}return n.pop(),r.pop(),!0};m.isEqual=function(t,e){return O(t,e)},m.isEmpty=function(t){return null==t||(E(t)&&(m.isArray(t)||m.isString(t)||m.isArguments(t))?0===t.length:0===m.keys(t).length)},m.isElement=function(t){return!(!t||1!==t.nodeType)},m.isArray=d||function(t){return"[object Array]"===h.call(t)},m.isObject=function(t){var e=typeof t;return"function"===e||"object"===e&&!!t},m.each(["Arguments","Function","String","Number","Date","RegExp","Error"],function(t){m["is"+t]=function(e){return h.call(e)==="[object "+t+"]"}}),m.isArguments(arguments)||(m.isArguments=function(t){return m.has(t,"callee")}),"function"!=typeof/./&&"object"!=typeof Int8Array&&(m.isFunction=function(t){return"function"==typeof t||!1}),m.isFinite=function(t){return isFinite(t)&&!isNaN(parseFloat(t))},m.isNaN=function(t){return m.isNumber(t)&&t!==+t},m.isBoolean=function(t){return t===!0||t===!1||"[object Boolean]"===h.call(t)},m.isNull=function(t){return null===t},m.isUndefined=function(t){return void 0===t},m.has=function(t,e){return null!=t&&f.call(t,e)},m.noConflict=function(){return i._=s,this},m.identity=function(t){return t},m.constant=function(t){return function(){return t}},m.noop=function(){},m.property=C,m.propertyOf=function(t){return null==t?function(){}:function(e){return t[e]}},m.matcher=m.matches=function(t){return t=m.extendOwn({},t),function(e){return m.isMatch(e,t)}},m.times=function(t,e,n){var r=Array(Math.max(0,t));e=_(e,n,1);for(var i=0;i<t;i++)r[i]=e(i);return r},m.random=function(t,e){return null==e&&(e=t,t=0),t+Math.floor(Math.random()*(e-t+1))},m.now=Date.now||function(){return(new Date).getTime()};var T={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#x27;","`":"&#x60;"},M=m.invert(T),R=function(t){var e=function(e){return t[e]},n="(?:"+m.keys(t).join("|")+")",r=RegExp(n),i=RegExp(n,"g");return function(t){return t=null==t?"":""+t,r.test(t)?t.replace(i,e):t}};m.escape=R(T),m.unescape=R(M),m.result=function(t,e,n){var r=null==t?void 0:t[e];return void 0===r&&(r=n),m.isFunction(r)?r.call(t):r};var P=0;m.uniqueId=function(t){var e=++P+"";return t?t+e:e},m.templateSettings={evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g};var N=/(.)^/,B={"'":"'","\\":"\\","\r":"r","\n":"n","\u2028":"u2028","\u2029":"u2029"},H=/\\|'|\r|\n|\u2028|\u2029/g,q=function(t){return"\\"+B[t]};m.template=function(t,e,n){!e&&n&&(e=n),e=m.defaults({},e,m.templateSettings);var r=RegExp([(e.escape||N).source,(e.interpolate||N).source,(e.evaluate||N).source].join("|")+"|$","g"),i=0,s="__p+='";t.replace(r,function(e,n,r,o,a){return s+=t.slice(i,a).replace(H,q),i=a+e.length,n?s+="'+\n((__t=("+n+"))==null?'':_.escape(__t))+\n'":r?s+="'+\n((__t=("+r+"))==null?'':__t)+\n'":o&&(s+="';\n"+o+"\n__p+='"),e}),s+="';\n",e.variable||(s="with(obj||{}){\n"+s+"}\n"),s="var __t,__p='',__j=Array.prototype.join,print=function(){__p+=__j.call(arguments,'');};\n"+s+"return __p;\n";try{var o=new Function(e.variable||"obj","_",s)}catch(a){throw a.source=s,a}var c=function(t){return o.call(this,t,m)},u=e.variable||"obj";return c.source="function("+u+"){\n"+s+"}",c},m.chain=function(t){var e=m(t);return e._chain=!0,e};var L=function(t,e){return t._chain?m(e).chain():e};m.mixin=function(t){m.each(m.functions(t),function(e){var n=m[e]=t[e];m.prototype[e]=function(){var t=[this._wrapped];return u.apply(t,arguments),L(this,n.apply(m,t))}})},m.mixin(m),m.each(["pop","push","reverse","shift","sort","splice","unshift"],function(t){var e=o[t];m.prototype[t]=function(){var n=this._wrapped;return e.apply(n,arguments),"shift"!==t&&"splice"!==t||0!==n.length||delete n[0],L(this,n)}}),m.each(["concat","join","slice"],function(t){var e=o[t];m.prototype[t]=function(){return L(this,e.apply(this._wrapped,arguments))}}),m.prototype.value=function(){return this._wrapped},m.prototype.valueOf=m.prototype.toJSON=m.prototype.value,m.prototype.toString=function(){return""+this._wrapped},"function"==typeof define&&define.amd&&define("underscore",[],function(){return m})}).call(this),function(t){var e="object"==typeof self&&self.self==self&&self||"object"==typeof global&&global.global==global&&global;if("function"==typeof define&&define.amd)define(["underscore","jquery","exports"],function(n,r,i){e.Backbone=t(e,i,n,r)});else if("undefined"!=typeof exports){var n,r=require("underscore");try{n=require("jquery")}catch(i){}t(e,exports,r,n)}else e.Backbone=t(e,{},e._,e.jQuery||e.Zepto||e.ender||e.$)}(function(t,e,n,r){var i=t.Backbone,s=[].slice;e.VERSION="1.2.1",e.$=r,e.noConflict=function(){return t.Backbone=i,this},e.emulateHTTP=!1,e.emulateJSON=!1;var o=function(t,e,r){switch(t){case 1:return function(){return n[e](this[r])};case 2:return function(t){return n[e](this[r],t)};case 3:return function(t,i){return n[e](this[r],t,i)};case 4:return function(t,i,s){return n[e](this[r],t,i,s)};default:return function(){var t=s.call(arguments);return t.unshift(this[r]),n[e].apply(n,t)}}},a=function(t,e,r){n.each(e,function(e,i){n[i]&&(t.prototype[i]=o(e,i,r))})},c=e.Events={},u=/\s+/,l=function(t,e,r,i,s){var o,a=0;if(r&&"object"==typeof r){void 0!==i&&"context"in s&&void 0===s.context&&(s.context=i);for(o=n.keys(r);a<o.length;a++)e=t(e,o[a],r[o[a]],s)}else if(r&&u.test(r))for(o=r.split(u);a<o.length;a++)e=t(e,o[a],i,s);else e=t(e,r,i,s);return e};c.on=function(t,e,n){return h(this,t,e,n)};var h=function(t,e,n,r,i){if(t._events=l(f,t._events||{},e,n,{context:r,ctx:t,listening:i}),i){var s=t._listeners||(t._listeners={});s[i.id]=i}return t};c.listenTo=function(t,e,r){if(!t)return this;var i=t._listenId||(t._listenId=n.uniqueId("l")),s=this._listeningTo||(this._listeningTo={}),o=s[i];if(!o){var a=this._listenId||(this._listenId=n.uniqueId("l"));o=s[i]={obj:t,objId:i,id:a,listeningTo:s,count:0}}return h(t,e,r,this,o),this};var f=function(t,e,n,r){if(n){var i=t[e]||(t[e]=[]),s=r.context,o=r.ctx,a=r.listening;a&&a.count++,i.push({callback:n,context:s,ctx:s||o,listening:a})}return t};c.off=function(t,e,n){return this._events?(this._events=l(d,this._events,t,e,{context:n,listeners:this._listeners}),this):this},c.stopListening=function(t,e,r){var i=this._listeningTo;if(!i)return this;for(var s=t?[t._listenId]:n.keys(i),o=0;o<s.length;o++){var a=i[s[o]];if(!a)break;a.obj.off(e,r,this)}return n.isEmpty(i)&&(this._listeningTo=void 0),this};var d=function(t,e,r,i){if(t){var s,o=0,a=i.context,c=i.listeners;if(e||r||a){for(var u=e?[e]:n.keys(t);o<u.length;o++){e=u[o];var l=t[e];if(!l)break;for(var h=[],f=0;f<l.length;f++){var d=l[f];r&&r!==d.callback&&r!==d.callback._callback||a&&a!==d.context?h.push(d):(s=d.listening,s&&0===--s.count&&(delete c[s.id],delete s.listeningTo[s.objId]))}h.length?t[e]=h:delete t[e]}return n.size(t)?t:void 0}for(var p=n.keys(c);o<p.length;o++)s=c[p[o]],delete c[s.id],delete s.listeningTo[s.objId]}};c.once=function(t,e,r){var i=l(p,{},t,e,n.bind(this.off,this));return this.on(i,void 0,r)},c.listenToOnce=function(t,e,r){var i=l(p,{},e,r,n.bind(this.stopListening,this,t));return this.listenTo(t,i)};var p=function(t,e,r,i){if(r){var s=t[e]=n.once(function(){i(e,s),r.apply(this,arguments)});s._callback=r}return t};c.trigger=function(t){if(!this._events)return this;for(var e=Math.max(0,arguments.length-1),n=Array(e),r=0;r<e;r++)n[r]=arguments[r+1];return l(v,this._events,t,void 0,n),this};var v=function(t,e,n,r){if(t){var i=t[e],s=t.all;i&&s&&(s=s.slice()),i&&g(i,r),s&&g(s,[e].concat(r))}return t},g=function(t,e){var n,r=-1,i=t.length,s=e[0],o=e[1],a=e[2];switch(e.length){case 0:for(;++r<i;)(n=t[r]).callback.call(n.ctx);return;case 1:for(;++r<i;)(n=t[r]).callback.call(n.ctx,s);return;case 2:for(;++r<i;)(n=t[r]).callback.call(n.ctx,s,o);return;case 3:for(;++r<i;)(n=t[r]).callback.call(n.ctx,s,o,a);return;default:for(;++r<i;)(n=t[r]).callback.apply(n.ctx,e);return}};c.bind=c.on,c.unbind=c.off,n.extend(e,c);var y=e.Model=function(t,e){var r=t||{};e||(e={}),this.cid=n.uniqueId(this.cidPrefix),this.attributes={},e.collection&&(this.collection=e.collection),e.parse&&(r=this.parse(r,e)||{}),r=n.defaults({},r,n.result(this,"defaults")),this.set(r,e),this.changed={},this.initialize.apply(this,arguments)};n.extend(y.prototype,c,{changed:null,validationError:null,idAttribute:"id",cidPrefix:"c",initialize:function(){},toJSON:function(t){return n.clone(this.attributes)},sync:function(){return e.sync.apply(this,arguments)},get:function(t){return this.attributes[t]},escape:function(t){return n.escape(this.get(t))},has:function(t){return null!=this.get(t)},matches:function(t){return!!n.iteratee(t,this)(this.attributes)},set:function(t,e,r){if(null==t)return this;var i;if("object"==typeof t?(i=t,r=e):(i={})[t]=e,r||(r={}),!this._validate(i,r))return!1;var s=r.unset,o=r.silent,a=[],c=this._changing;this._changing=!0,c||(this._previousAttributes=n.clone(this.attributes),this.changed={});var u=this.attributes,l=this.changed,h=this._previousAttributes;this.idAttribute in i&&(this.id=i[this.idAttribute]);for(var f in i)e=i[f],n.isEqual(u[f],e)||a.push(f),n.isEqual(h[f],e)?delete l[f]:l[f]=e,s?delete u[f]:u[f]=e;if(!o){a.length&&(this._pending=r);for(var d=0;d<a.length;d++)this.trigger("change:"+a[d],this,u[a[d]],r)}if(c)return this;if(!o)for(;this._pending;)r=this._pending,this._pending=!1,this.trigger("change",this,r);return this._pending=!1,this._changing=!1,this},unset:function(t,e){return this.set(t,void 0,n.extend({},e,{unset:!0}))},clear:function(t){var e={};for(var r in this.attributes)e[r]=void 0;return this.set(e,n.extend({},t,{unset:!0}))},hasChanged:function(t){return null==t?!n.isEmpty(this.changed):n.has(this.changed,t)},changedAttributes:function(t){if(!t)return!!this.hasChanged()&&n.clone(this.changed);var e=this._changing?this._previousAttributes:this.attributes,r={};for(var i in t){var s=t[i];n.isEqual(e[i],s)||(r[i]=s)}return!!n.size(r)&&r},previous:function(t){return null!=t&&this._previousAttributes?this._previousAttributes[t]:null},previousAttributes:function(){return n.clone(this._previousAttributes)},fetch:function(t){t=n.extend({parse:!0},t);var e=this,r=t.success;return t.success=function(n){var i=t.parse?e.parse(n,t):n;return!!e.set(i,t)&&(r&&r.call(t.context,e,n,t),void e.trigger("sync",e,n,t))},H(this,t),this.sync("read",this,t)},save:function(t,e,r){var i;null==t||"object"==typeof t?(i=t,r=e):(i={})[t]=e,r=n.extend({validate:!0,parse:!0},r);var s=r.wait;if(i&&!s){if(!this.set(i,r))return!1}else if(!this._validate(i,r))return!1;var o=this,a=r.success,c=this.attributes;r.success=function(t){o.attributes=c;var e=r.parse?o.parse(t,r):t;return s&&(e=n.extend({},i,e)),!(e&&!o.set(e,r))&&(a&&a.call(r.context,o,t,r),void o.trigger("sync",o,t,r))},H(this,r),i&&s&&(this.attributes=n.extend({},c,i));var u=this.isNew()?"create":r.patch?"patch":"update";"patch"!==u||r.attrs||(r.attrs=i);var l=this.sync(u,this,r);return this.attributes=c,l},destroy:function(t){t=t?n.clone(t):{};var e=this,r=t.success,i=t.wait,s=function(){e.stopListening(),e.trigger("destroy",e,e.collection,t)};t.success=function(n){i&&s(),r&&r.call(t.context,e,n,t),e.isNew()||e.trigger("sync",e,n,t)};var o=!1;return this.isNew()?n.defer(t.success):(H(this,t),o=this.sync("delete",this,t)),i||s(),o},url:function(){var t=n.result(this,"urlRoot")||n.result(this.collection,"url")||B();if(this.isNew())return t;var e=this.get(this.idAttribute);return t.replace(/[^\/]$/,"$&/")+encodeURIComponent(e)},parse:function(t,e){return t},clone:function(){return new this.constructor(this.attributes)},isNew:function(){return!this.has(this.idAttribute)},isValid:function(t){return this._validate({},n.defaults({validate:!0},t))},_validate:function(t,e){if(!e.validate||!this.validate)return!0;t=n.extend({},this.attributes,t);var r=this.validationError=this.validate(t,e)||null;return!r||(this.trigger("invalid",this,r,n.extend(e,{validationError:r})),!1)}});var m={keys:1,values:1,pairs:1,invert:1,pick:0,omit:0,chain:1,isEmpty:1};a(y,m,"attributes");var _=e.Collection=function(t,e){e||(e={}),e.model&&(this.model=e.model),void 0!==e.comparator&&(this.comparator=e.comparator),this._reset(),this.initialize.apply(this,arguments),t&&this.reset(t,n.extend({silent:!0},e))},b={add:!0,remove:!0,merge:!0},x={add:!0,remove:!1};n.extend(_.prototype,c,{model:y,initialize:function(){},toJSON:function(t){return this.map(function(e){return e.toJSON(t)})},sync:function(){return e.sync.apply(this,arguments)},add:function(t,e){return this.set(t,n.extend({merge:!1},e,x))},remove:function(t,e){e=n.extend({},e);var r=!n.isArray(t);t=r?[t]:n.clone(t);var i=this._removeModels(t,e);return!e.silent&&i&&this.trigger("update",this,e),r?i[0]:i},set:function(t,e){e=n.defaults({},e,b),e.parse&&!this._isModel(t)&&(t=this.parse(t,e));var r=!n.isArray(t);t=r?t?[t]:[]:t.slice();var i,s,o,a,c,u=e.at;null!=u&&(u=+u),u<0&&(u+=this.length+1);for(var l=this.comparator&&null==u&&e.sort!==!1,h=n.isString(this.comparator)?this.comparator:null,f=[],d=[],p={},v=e.add,g=e.merge,y=e.remove,m=!(l||!v||!y)&&[],_=!1,x=0;x<t.length;x++){if(o=t[x],a=this.get(o))y&&(p[a.cid]=!0),g&&o!==a&&(o=this._isModel(o)?o.attributes:o,e.parse&&(o=a.parse(o,e)),a.set(o,e),l&&!c&&a.hasChanged(h)&&(c=!0)),t[x]=a;else if(v){if(s=t[x]=this._prepareModel(o,e),!s)continue;f.push(s),this._addReference(s,e)}s=a||s,s&&(i=this.modelId(s.attributes),!m||!s.isNew()&&p[i]||(m.push(s),_=_||!this.models[x]||s.cid!==this.models[x].cid),p[i]=!0)}if(y){for(var x=0;x<this.length;x++)p[(s=this.models[x]).cid]||d.push(s);d.length&&this._removeModels(d,e)}if(f.length||_)if(l&&(c=!0),this.length+=f.length,null!=u)for(var x=0;x<f.length;x++)this.models.splice(u+x,0,f[x]);else{m&&(this.models.length=0);for(var w=m||f,x=0;x<w.length;x++)this.models.push(w[x])}if(c&&this.sort({silent:!0}),!e.silent){for(var C=null!=u?n.clone(e):e,x=0;x<f.length;x++)null!=u&&(C.index=u+x),(s=f[x]).trigger("add",s,this,C);(c||_)&&this.trigger("sort",this,e),(f.length||d.length)&&this.trigger("update",this,e)}return r?t[0]:t},reset:function(t,e){e=e?n.clone(e):{};for(var r=0;r<this.models.length;r++)this._removeReference(this.models[r],e);return e.previousModels=this.models,this._reset(),t=this.add(t,n.extend({silent:!0},e)),e.silent||this.trigger("reset",this,e),t},push:function(t,e){return this.add(t,n.extend({at:this.length},e))},pop:function(t){var e=this.at(this.length-1);return this.remove(e,t)},unshift:function(t,e){return this.add(t,n.extend({at:0},e))},shift:function(t){var e=this.at(0);return this.remove(e,t)},slice:function(){return s.apply(this.models,arguments)},get:function(t){if(null!=t){var e=this.modelId(this._isModel(t)?t.attributes:t);return this._byId[t]||this._byId[e]||this._byId[t.cid]}},at:function(t){return t<0&&(t+=this.length),this.models[t]},where:function(t,e){var r=n.matches(t);return this[e?"find":"filter"](function(t){return r(t.attributes)})},findWhere:function(t){return this.where(t,!0)},sort:function(t){if(!this.comparator)throw new Error("Cannot sort a set without a comparator");return t||(t={}),n.isString(this.comparator)||1===this.comparator.length?this.models=this.sortBy(this.comparator,this):this.models.sort(n.bind(this.comparator,this)),t.silent||this.trigger("sort",this,t),this},pluck:function(t){return n.invoke(this.models,"get",t)},fetch:function(t){t=n.extend({parse:!0},t);var e=t.success,r=this;return t.success=function(n){var i=t.reset?"reset":"set";r[i](n,t),e&&e.call(t.context,r,n,t),r.trigger("sync",r,n,t)},H(this,t),this.sync("read",this,t)},create:function(t,e){e=e?n.clone(e):{};var r=e.wait;if(t=this._prepareModel(t,e),!t)return!1;r||this.add(t,e);var i=this,s=e.success;return e.success=function(t,e,n){r&&i.add(t,n),s&&s.call(n.context,t,e,n)},t.save(null,e),t},parse:function(t,e){return t},clone:function(){return new this.constructor(this.models,{model:this.model,comparator:this.comparator})},modelId:function(t){return t[this.model.prototype.idAttribute||"id"]},_reset:function(){this.length=0,this.models=[],this._byId={}},_prepareModel:function(t,e){if(this._isModel(t))return t.collection||(t.collection=this),t;e=e?n.clone(e):{},e.collection=this;var r=new this.model(t,e);return r.validationError?(this.trigger("invalid",this,r.validationError,e),!1):r},_removeModels:function(t,e){for(var n=[],r=0;r<t.length;r++){var i=this.get(t[r]);if(i){var s=this.indexOf(i);this.models.splice(s,1),this.length--,e.silent||(e.index=s,i.trigger("remove",i,this,e)),n.push(i),this._removeReference(i,e)}}return!!n.length&&n},_isModel:function(t){return t instanceof y},_addReference:function(t,e){this._byId[t.cid]=t;var n=this.modelId(t.attributes);null!=n&&(this._byId[n]=t),t.on("all",this._onModelEvent,this)},_removeReference:function(t,e){delete this._byId[t.cid];var n=this.modelId(t.attributes);null!=n&&delete this._byId[n],this===t.collection&&delete t.collection,t.off("all",this._onModelEvent,this)},_onModelEvent:function(t,e,n,r){if("add"!==t&&"remove"!==t||n===this){if("destroy"===t&&this.remove(e,r),"change"===t){var i=this.modelId(e.previousAttributes()),s=this.modelId(e.attributes);i!==s&&(null!=i&&delete this._byId[i],null!=s&&(this._byId[s]=e))}this.trigger.apply(this,arguments)}}});var w={forEach:3,each:3,map:3,collect:3,reduce:4,foldl:4,inject:4,reduceRight:4,foldr:4,find:3,detect:3,filter:3,select:3,reject:3,every:3,all:3,some:3,any:3,include:2,contains:2,invoke:0,max:3,min:3,toArray:1,size:1,first:3,head:3,take:3,initial:3,rest:3,tail:3,drop:3,last:3,without:0,difference:0,indexOf:3,shuffle:1,lastIndexOf:3,isEmpty:1,chain:1,sample:3,partition:3};a(_,w,"models");var C=["groupBy","countBy","sortBy","indexBy"];n.each(C,function(t){n[t]&&(_.prototype[t]=function(e,r){var i=n.isFunction(e)?e:function(t){return t.get(e)};return n[t](this.models,i,r)})});var S=e.View=function(t){this.cid=n.uniqueId("view"),n.extend(this,n.pick(t,E)),this._ensureElement(),this.initialize.apply(this,arguments)},k=/^(\S+)\s*(.*)$/,E=["model","collection","el","id","attributes","className","tagName","events"];n.extend(S.prototype,c,{tagName:"div",$:function(t){return this.$el.find(t)},initialize:function(){},render:function(){return this},remove:function(){return this._removeElement(),this.stopListening(),this},_removeElement:function(){this.$el.remove()},setElement:function(t){return this.undelegateEvents(),this._setElement(t),this.delegateEvents(),this},_setElement:function(t){this.$el=t instanceof e.$?t:e.$(t),this.el=this.$el[0]},delegateEvents:function(t){if(t||(t=n.result(this,"events")),!t)return this;this.undelegateEvents();for(var e in t){var r=t[e];if(n.isFunction(r)||(r=this[r]),r){var i=e.match(k);this.delegate(i[1],i[2],n.bind(r,this))}}return this},delegate:function(t,e,n){return this.$el.on(t+".delegateEvents"+this.cid,e,n),this},undelegateEvents:function(){return this.$el&&this.$el.off(".delegateEvents"+this.cid),this},undelegate:function(t,e,n){return this.$el.off(t+".delegateEvents"+this.cid,e,n),this},_createElement:function(t){return document.createElement(t)},_ensureElement:function(){if(this.el)this.setElement(n.result(this,"el"));else{var t=n.extend({},n.result(this,"attributes"));this.id&&(t.id=n.result(this,"id")),this.className&&(t["class"]=n.result(this,"className")),this.setElement(this._createElement(n.result(this,"tagName"))),this._setAttributes(t)}},_setAttributes:function(t){this.$el.attr(t)}}),e.sync=function(t,r,i){var s=j[t];n.defaults(i||(i={}),{emulateHTTP:e.emulateHTTP,emulateJSON:e.emulateJSON});var o={type:s,dataType:"json"};if(i.url||(o.url=n.result(r,"url")||B()),null!=i.data||!r||"create"!==t&&"update"!==t&&"patch"!==t||(o.contentType="application/json",o.data=JSON.stringify(i.attrs||r.toJSON(i))),i.emulateJSON&&(o.contentType="application/x-www-form-urlencoded",o.data=o.data?{model:o.data}:{}),i.emulateHTTP&&("PUT"===s||"DELETE"===s||"PATCH"===s)){o.type="POST",i.emulateJSON&&(o.data._method=s);var a=i.beforeSend;i.beforeSend=function(t){if(t.setRequestHeader("X-HTTP-Method-Override",s),a)return a.apply(this,arguments);
  }}"GET"===o.type||i.emulateJSON||(o.processData=!1);var c=i.error;i.error=function(t,e,n){i.textStatus=e,i.errorThrown=n,c&&c.call(i.context,t,e,n)};var u=i.xhr=e.ajax(n.extend(o,i));return r.trigger("request",r,u,i),u};var j={create:"POST",update:"PUT",patch:"PATCH","delete":"DELETE",read:"GET"};e.ajax=function(){return e.$.ajax.apply(e.$,arguments)};var A=e.Router=function(t){t||(t={}),t.routes&&(this.routes=t.routes),this._bindRoutes(),this.initialize.apply(this,arguments)},I=/\((.*?)\)/g,F=/(\(\?)?:\w+/g,$=/\*\w+/g,O=/[\-{}\[\]+?.,\\\^$|#\s]/g;n.extend(A.prototype,c,{initialize:function(){},route:function(t,r,i){n.isRegExp(t)||(t=this._routeToRegExp(t)),n.isFunction(r)&&(i=r,r=""),i||(i=this[r]);var s=this;return e.history.route(t,function(n){var o=s._extractParameters(t,n);s.execute(i,o,r)!==!1&&(s.trigger.apply(s,["route:"+r].concat(o)),s.trigger("route",r,o),e.history.trigger("route",s,r,o))}),this},execute:function(t,e,n){t&&t.apply(this,e)},navigate:function(t,n){return e.history.navigate(t,n),this},_bindRoutes:function(){if(this.routes){this.routes=n.result(this,"routes");for(var t,e=n.keys(this.routes);null!=(t=e.pop());)this.route(t,this.routes[t])}},_routeToRegExp:function(t){return t=t.replace(O,"\\$&").replace(I,"(?:$1)?").replace(F,function(t,e){return e?t:"([^/?]+)"}).replace($,"([^?]*?)"),new RegExp("^"+t+"(?:\\?([\\s\\S]*))?$")},_extractParameters:function(t,e){var r=t.exec(e).slice(1);return n.map(r,function(t,e){return e===r.length-1?t||null:t?decodeURIComponent(t):null})}});var T=e.History=function(){this.handlers=[],n.bindAll(this,"checkUrl"),"undefined"!=typeof window&&(this.location=window.location,this.history=window.history)},M=/^[#\/]|\s+$/g,R=/^\/+|\/+$/g,P=/#.*$/;T.started=!1,n.extend(T.prototype,c,{interval:50,atRoot:function(){var t=this.location.pathname.replace(/[^\/]$/,"$&/");return t===this.root&&!this.getSearch()},matchRoot:function(){var t=this.decodeFragment(this.location.pathname),e=t.slice(0,this.root.length-1)+"/";return e===this.root},decodeFragment:function(t){return decodeURI(t.replace(/%25/g,"%2525"))},getSearch:function(){var t=this.location.href.replace(/#.*/,"").match(/\?.+/);return t?t[0]:""},getHash:function(t){var e=(t||this).location.href.match(/#(.*)$/);return e?e[1]:""},getPath:function(){var t=this.decodeFragment(this.location.pathname+this.getSearch()).slice(this.root.length-1);return"/"===t.charAt(0)?t.slice(1):t},getFragment:function(t){return null==t&&(t=this._usePushState||!this._wantsHashChange?this.getPath():this.getHash()),t.replace(M,"")},start:function(t){if(T.started)throw new Error("Backbone.history has already been started");if(T.started=!0,this.options=n.extend({root:"/"},this.options,t),this.root=this.options.root,this._wantsHashChange=this.options.hashChange!==!1,this._hasHashChange="onhashchange"in window,this._useHashChange=this._wantsHashChange&&this._hasHashChange,this._wantsPushState=!!this.options.pushState,this._hasPushState=!(!this.history||!this.history.pushState),this._usePushState=this._wantsPushState&&this._hasPushState,this.fragment=this.getFragment(),this.root=("/"+this.root+"/").replace(R,"/"),this._wantsHashChange&&this._wantsPushState){if(!this._hasPushState&&!this.atRoot()){var e=this.root.slice(0,-1)||"/";return this.location.replace(e+"#"+this.getPath()),!0}this._hasPushState&&this.atRoot()&&this.navigate(this.getHash(),{replace:!0})}if(!this._hasHashChange&&this._wantsHashChange&&!this._usePushState){this.iframe=document.createElement("iframe"),this.iframe.src="javascript:0",this.iframe.style.display="none",this.iframe.tabIndex=-1;var r=document.body,i=r.insertBefore(this.iframe,r.firstChild).contentWindow;i.document.open(),i.document.close(),i.location.hash="#"+this.fragment}var s=window.addEventListener||function(t,e){return attachEvent("on"+t,e)};if(this._usePushState?s("popstate",this.checkUrl,!1):this._useHashChange&&!this.iframe?s("hashchange",this.checkUrl,!1):this._wantsHashChange&&(this._checkUrlInterval=setInterval(this.checkUrl,this.interval)),!this.options.silent)return this.loadUrl()},stop:function(){var t=window.removeEventListener||function(t,e){return detachEvent("on"+t,e)};this._usePushState?t("popstate",this.checkUrl,!1):this._useHashChange&&!this.iframe&&t("hashchange",this.checkUrl,!1),this.iframe&&(document.body.removeChild(this.iframe),this.iframe=null),this._checkUrlInterval&&clearInterval(this._checkUrlInterval),T.started=!1},route:function(t,e){this.handlers.unshift({route:t,callback:e})},checkUrl:function(t){var e=this.getFragment();return e===this.fragment&&this.iframe&&(e=this.getHash(this.iframe.contentWindow)),e!==this.fragment&&(this.iframe&&this.navigate(e),void this.loadUrl())},loadUrl:function(t){return!!this.matchRoot()&&(t=this.fragment=this.getFragment(t),n.any(this.handlers,function(e){if(e.route.test(t))return e.callback(t),!0}))},navigate:function(t,e){if(!T.started)return!1;e&&e!==!0||(e={trigger:!!e}),t=this.getFragment(t||"");var n=this.root;""!==t&&"?"!==t.charAt(0)||(n=n.slice(0,-1)||"/");var r=n+t;if(t=this.decodeFragment(t.replace(P,"")),this.fragment!==t){if(this.fragment=t,this._usePushState)this.history[e.replace?"replaceState":"pushState"]({},document.title,r);else{if(!this._wantsHashChange)return this.location.assign(r);if(this._updateHash(this.location,t,e.replace),this.iframe&&t!==this.getHash(this.iframe.contentWindow)){var i=this.iframe.contentWindow;e.replace||(i.document.open(),i.document.close()),this._updateHash(i.location,t,e.replace)}}return e.trigger?this.loadUrl(t):void 0}},_updateHash:function(t,e,n){if(n){var r=t.href.replace(/(javascript:|#).*$/,"");t.replace(r+"#"+e)}else t.hash="#"+e}}),e.history=new T;var N=function(t,e){var r,i=this;r=t&&n.has(t,"constructor")?t.constructor:function(){return i.apply(this,arguments)},n.extend(r,i,e);var s=function(){this.constructor=r};return s.prototype=i.prototype,r.prototype=new s,t&&n.extend(r.prototype,t),r.__super__=i.prototype,r};y.extend=_.extend=A.extend=S.extend=T.extend=N;var B=function(){throw new Error('A "url" property or function must be specified')},H=function(t,e){var n=e.error;e.error=function(r){n&&n.call(e.context,t,r,e),t.trigger("error",t,r,e)}};return e}),!function(t,e){"function"==typeof define&&define.amd?define(["underscore","backbone","../../../../public/js/lib/jquery"],function(n,r,i){return t.Backbone=e(n,r,i)}):"undefined"!=typeof exports&&"undefined"!=typeof require?module.exports=e(require("underscore"),require("backbone"),require("jquery")):t.Backbone=e(t._,t.Backbone,t.jQuery)}(this,function(t,e,n){function r(e,r){if(e&&t.isObject(e)){if(t.isFunction(e.getCacheKey))return e.getCacheKey(r);e=r&&r.url?r.url:t.isFunction(e.url)?e.url():e.url}else if(t.isFunction(e))return e(r);return r&&r.data?"string"==typeof r.data?e+"?"+r.data:e+"?"+n.param(r.data):e}function i(t,n,r){n=n||{};var i=e.fetchCache.getCacheKey(t,n),s=!1,o=n.lastSync||(new Date).getTime(),a=!1;i&&n.cache!==!1&&(n.cache||n.prefill)&&(n.expires!==!1&&(s=(new Date).getTime()+1e3*(n.expires||300)),n.prefillExpires!==!1&&(a=(new Date).getTime()+1e3*(n.prefillExpires||300)),e.fetchCache._cache[i]={expires:s,lastSync:o,prefillExpires:a,value:r},e.fetchCache.setLocalStorage())}function s(n,i){return t.isFunction(n)?n=n():n&&t.isObject(n)&&(n=r(n,i)),e.fetchCache._cache[n]}function o(t){return s(t).lastSync}function a(n,i){t.isFunction(n)?n=n():n&&t.isObject(n)&&(n=r(n,i)),delete e.fetchCache._cache[n],e.fetchCache.setLocalStorage()}function c(){if(f&&e.fetchCache.localStorage)try{localStorage.setItem(e.fetchCache.getLocalStorageKey(),JSON.stringify(e.fetchCache._cache))}catch(t){var n=t.code||t.number||t.message;if(22!==n&&1014!==n)throw t;this._deleteCacheWithPriority()}}function u(){if(f&&e.fetchCache.localStorage){var t=localStorage.getItem(e.fetchCache.getLocalStorageKey())||"{}";e.fetchCache._cache=JSON.parse(t)}}function l(t){return window.setTimeout(t,0)}var h={modelFetch:e.Model.prototype.fetch,modelSync:e.Model.prototype.sync,collectionFetch:e.Collection.prototype.fetch},f=function(){var t="undefined"!=typeof window.localStorage;if(t)try{localStorage.setItem("test_support","test_support"),localStorage.removeItem("test_support")}catch(e){t=!1}return t}();return e.fetchCache=e.fetchCache||{},e.fetchCache._cache=e.fetchCache._cache||{},e.fetchCache.enabled=!0,e.fetchCache.priorityFn=function(t,e){return t&&t.expires&&e&&e.expires?t.expires-e.expires:t},e.fetchCache._prioritize=function(){var e=t.values(this._cache).sort(this.priorityFn),n=t.indexOf(t.values(this._cache),e[0]);return t.keys(this._cache)[n]},e.fetchCache._deleteCacheWithPriority=function(){e.fetchCache._cache[this._prioritize()]=null,delete e.fetchCache._cache[this._prioritize()],e.fetchCache.setLocalStorage()},e.fetchCache.getLocalStorageKey=function(){return"backboneCache"},"undefined"==typeof e.fetchCache.localStorage&&(e.fetchCache.localStorage=!0),e.Model.prototype.fetch=function(r){function i(){return r.prefill&&(!r.prefillExpires||f)}function o(){r.parse&&(d=v.parse(d,r)),v.set(d,r),t.isFunction(r.prefillSuccess)&&r.prefillSuccess(v,d,r),v.trigger("cachesync",v,d,r),v.trigger("sync",v,d,r),i()?p.notify(v):(t.isFunction(r.success)&&r.success(v,d,r),p.resolve(v))}if(!e.fetchCache.enabled)return h.modelFetch.apply(this,arguments);r=t.defaults(r||{},{parse:!0});var a=e.fetchCache.getCacheKey(this,r),c=s(a),u=!1,f=!1,d=!1,p=new n.Deferred,v=this;if(c&&(u=c.expires,u=u&&c.expires<(new Date).getTime(),f=c.prefillExpires,f=f&&c.prefillExpires<(new Date).getTime(),d=c.value),!u&&(r.cache||r.prefill)&&d&&(null==r.async&&(r.async=!0),r.async?l(o):o(),!i()))return p;var g=h.modelFetch.apply(this,arguments);return g.done(t.bind(p.resolve,this,this)).done(t.bind(e.fetchCache.setCache,null,this,r)).fail(t.bind(p.reject,this,this)),p.abort=g.abort,p},e.Model.prototype.sync=function(t,n,r){if("read"===t||!e.fetchCache.enabled)return h.modelSync.apply(this,arguments);var i,s,o=n.collection,c=[];for(c.push(e.fetchCache.getCacheKey(n,r)),o&&c.push(e.fetchCache.getCacheKey(o)),i=0,s=c.length;s>i;i++)a(c[i]);return h.modelSync.apply(this,arguments)},e.Collection.prototype.fetch=function(r){function i(){return r.prefill&&(!r.prefillExpires||f)}function o(){v[r.reset?"reset":"set"](d,r),t.isFunction(r.prefillSuccess)&&r.prefillSuccess(v),v.trigger("cachesync",v,d,r),v.trigger("sync",v,d,r),i()?p.notify(v):(t.isFunction(r.success)&&r.success(v,d,r),p.resolve(v))}if(!e.fetchCache.enabled)return h.collectionFetch.apply(this,arguments);r=t.defaults(r||{},{parse:!0});var a=e.fetchCache.getCacheKey(this,r),c=s(a),u=!1,f=!1,d=!1,p=new n.Deferred,v=this;if(c&&(u=c.expires,u=u&&c.expires<(new Date).getTime(),f=c.prefillExpires,f=f&&c.prefillExpires<(new Date).getTime(),d=c.value),!u&&(r.cache||r.prefill)&&d&&(null==r.async&&(r.async=!0),r.async?l(o):o(),!i()))return p;var g=h.collectionFetch.apply(this,arguments);return g.done(t.bind(p.resolve,this,this)).done(t.bind(e.fetchCache.setCache,null,this,r)).fail(t.bind(p.reject,this,this)),p.abort=g.abort,p},u(),e.fetchCache._superMethods=h,e.fetchCache.setCache=i,e.fetchCache.getCache=s,e.fetchCache.getCacheKey=r,e.fetchCache.getLastSync=o,e.fetchCache.clearItem=a,e.fetchCache.setLocalStorage=c,e.fetchCache.getLocalStorage=u,e}),$.ajaxSetup({cache:!0});var CountryModel=Backbone.Model.extend(),FilterCountryCollection=Backbone.Collection.extend({model:CountryModel,initialize:function(){this.sortField="name",this.sortDirection="ASC"},setSortField:function(t,e){this.sortField=t,this.sortDirection=e},comparator:function(t){return t.get(this.sortField)},sortBy:function(t,e){var n=this.models,r=this.sortDirection;return _.pluck(_.map(n,function(n,r,i){return{value:n,index:r,criteria:t.call(e,n,r,i)}}).sort(function(t,e){var n="ASC"===r?t.criteria:e.criteria,i="ASC"===r?e.criteria:t.criteria;if(n!==i){if(n>i||void 0===n)return 1;if(n<i||void 0===i)return-1}return t.index<e.index?-1:1}),"value")}}),CountryCollection=Backbone.Collection.extend({initialize:function(t){this.url=t},model:CountryModel,url:this.url,search:function(t){var e="name",n="code";if("undefined"==typeof t||""==t)return this;var r=new RegExp(t,"gi");return _(this.filter(function(t){return r.test(t.get(e))||r.test(t.get(n))}))},countries:function(t,e){var n;n=this.search(t),n=new FilterCountryCollection(n.toArray()),"undefined"!=typeof e&&(n.setSortField("name",e.toUpperCase()),n.sort());var r=[];return _.each(n.models,function(t){r.push({code:t.get("code"),name:t.get("name"),contract:t.get("contract")})}),r}}),CountryView=Backbone.View.extend({initialize:function(){this.template=_.template($("#country-template").html())},render:function(){return this.el=this.template(this.model),this}}),CountryList=Backbone.View.extend({initialize:function(t){this.query=t.query,this.sort_type=t.sort_type,this.collection.on("sort",this.sort,this),this.collection.on("search",this.search,this),this.collection.on("reset",this.render,this)},search:function(t){this.query=t,this.render()},sort:function(t){this.sort_type=t,this.render()},render:function(){var t=this,e=this.collection.countries(this.query,this.sort_type,this.resources);return $(t.el).html(""),_.each(e,function(e){$(t.el).append(new CountryView({model:e}).render().el)}),this}}),ResourceModel=Backbone.Model.extend(),ResourceController=Backbone.Collection.extend({initialize:function(t){this.url=t},model:ResourceModel,url:this.url,resources:function(){var t=this;t=new FilterCountryCollection(t.toArray()),t.setSortField("resource","ASC"),t.sort();var e=[];return t.each(function(t){e.push({name:t.get("resource"),value:t.get("resource"),contract:t.get("contract")})}),e}}),ResourceView=Backbone.View.extend({initialize:function(){this.template=_.template($("#resource-template").html())},render:function(){return this.el=this.template(this.model),this}}),ResourceList=Backbone.View.extend({initialize:function(){this.collection.on("reset",this.render,this)},render:function(){var t=this,e=this.collection.resources();return $(t.el).html(""),_.each(e,function(e){$(t.el).append(new ResourceView({model:e}).render().el)}),this}}),collection=new CountryCollection(APP_URL+"/contract/countries");collection.fetch({reset:!0,cache:!0,expires:6e4});var countryList=new CountryList({el:"#countries",sort_type:"asc",collection:collection}).el,rCollection=new ResourceController(APP_URL+"/contract/resources");rCollection.fetch({reset:!0,cache:!0,expires:6e4});var resourceList=new ResourceList({el:"#resources",collection:rCollection});$(function(){$(document).on("click",".resource",function(){var t=[];$(".resource:checked").each(function(){t.push($(this).val())}),collection.url=APP_URL+"/contract/countries?resource="+t.join(),collection.fetch({reset:!0,cache:!0,expires:6e4,success:function(){$("#countries").find(".col-lg-2").removeClass("col-lg-2").addClass("col-lg-3"),$(".side-collapse").css("height",$("#countries").height()+150+"px"),$(window).width()<1200&&$("#countries").find(".col-md-3,.col-md-6").toggleClass("col-md-3").toggleClass("col-md-6"),$(window).width()<992&&$("#countries").find(".col-sm-4,.col-sm-6").toggleClass("col-sm-4").toggleClass("col-sm-6"),$(window).width()<768&&$("#countries").find(".col-xs-6,.col-xs-12").toggleClass("col-xs-6").toggleClass("col-xs-12")}})}),$(document).on("change",".sort",function(t){t.preventDefault(),collection.trigger("sort",$(this).val())}),$(document).on("input",".search",function(t){t.preventDefault(),collection.trigger("search",$(this).val())})});