/*
  Welcome to AssetHost
  */
window.console||(window.console=function(){function a(){}return a.log=function(){},a}());if(typeof AssetHost=="undefined"||AssetHost===null)AssetHost={};AssetHost.SERVER="a.scpr.org",function(a){a.extend(a.fn,{livequery:function(b,c,d){var e=this,f;return a.isFunction(b)&&(d=c,c=b,b=undefined),a.each(a.livequery.queries,function(a,g){if(e.selector==g.selector&&e.context==g.context&&b==g.type&&(!c||c.$lqguid==g.fn.$lqguid)&&(!d||d.$lqguid==g.fn2.$lqguid))return(f=g)&&!1}),f=f||new a.livequery(this.selector,this.context,b,c,d),f.stopped=!1,f.run(),this},expire:function(b,c,d){var e=this;return a.isFunction(b)&&(d=c,c=b,b=undefined),a.each(a.livequery.queries,function(f,g){e.selector==g.selector&&e.context==g.context&&(!b||b==g.type)&&(!c||c.$lqguid==g.fn.$lqguid)&&(!d||d.$lqguid==g.fn2.$lqguid)&&!this.stopped&&a.livequery.stop(g.id)}),this}}),a.livequery=function(b,c,d,e,f){return this.selector=b,this.context=c||document,this.type=d,this.fn=e,this.fn2=f,this.elements=[],this.stopped=!1,this.id=a.livequery.queries.push(this)-1,e.$lqguid=e.$lqguid||a.livequery.guid++,f&&(f.$lqguid=f.$lqguid||a.livequery.guid++),this},a.livequery.prototype={stop:function(){var a=this;this.type?this.elements.unbind(this.type,this.fn):this.fn2&&this.elements.each(function(b,c){a.fn2.apply(c)}),this.elements=[],this.stopped=!0},run:function(){if(this.stopped)return;var b=this,c=this.elements,d=a(this.selector,this.context),e=d.not(c);this.elements=d,this.type?(e.bind(this.type,this.fn),c.length>0&&a.each(c,function(c,e){a.inArray(e,d)<0&&a.event.remove(e,b.type,b.fn)})):(e.each(function(){b.fn.apply(this)}),this.fn2&&c.length>0&&a.each(c,function(c,e){a.inArray(e,d)<0&&b.fn2.apply(e)}))}},a.extend(a.livequery,{guid:0,queries:[],queue:[],running:!1,timeout:null,checkQueue:function(){if(a.livequery.running&&a.livequery.queue.length){var b=a.livequery.queue.length;while(b--)a.livequery.queries[a.livequery.queue.shift()].run()}},pause:function(){a.livequery.running=!1},play:function(){a.livequery.running=!0,a.livequery.run()},registerPlugin:function(){a.each(arguments,function(b,c){if(!a.fn[c])return;var d=a.fn[c];a.fn[c]=function(){var b=d.apply(this,arguments);return a.livequery.run(),b}})},run:function(b){b!=undefined?a.inArray(b,a.livequery.queue)<0&&a.livequery.queue.push(b):a.each(a.livequery.queries,function(b){a.inArray(b,a.livequery.queue)<0&&a.livequery.queue.push(b)}),a.livequery.timeout&&clearTimeout(a.livequery.timeout),a.livequery.timeout=setTimeout(a.livequery.checkQueue,20)},stop:function(b){b!=undefined?a.livequery.queries[b].stop():a.each(a.livequery.queries,function(b){a.livequery.queries[b].stop()})}}),a.livequery.registerPlugin("append","prepend","after","before","wrap","attr","removeAttr","addClass","removeClass","toggleClass","empty","remove"),a(function(){a.livequery.play()});var b=a.prototype.init;a.prototype.init=function(a,c){var d=b.apply(this,arguments);return a&&a.selector&&(d.context=a.context,d.selector=a.selector),typeof a=="string"&&(d.context=c||document,d.selector=a),d},a.prototype.init.prototype=a.prototype}(jQuery),function(){var a=this,b=a._,c={},d=Array.prototype,e=Object.prototype,f=Function.prototype,g=d.slice,h=d.unshift,i=e.toString,j=e.hasOwnProperty,k=d.forEach,l=d.map,m=d.reduce,n=d.reduceRight,o=d.filter,p=d.every,q=d.some,r=d.indexOf,s=d.lastIndexOf,t=Array.isArray,u=Object.keys,v=f.bind,w=function(a){return new B(a)};typeof module!="undefined"&&module.exports?(module.exports=w,w._=w):a._=w,w.VERSION="1.1.6";var x=w.each=w.forEach=function(a,b,d){if(a==null)return;if(k&&a.forEach===k)a.forEach(b,d);else if(w.isNumber(a.length)){for(var e=0,f=a.length;e<f;e++)if(b.call(d,a[e],e,a)===c)return}else for(var g in a)if(j.call(a,g)&&b.call(d,a[g],g,a)===c)return};w.map=function(a,b,c){var d=[];return a==null?d:l&&a.map===l?a.map(b,c):(x(a,function(a,e,f){d[d.length]=b.call(c,a,e,f)}),d)},w.reduce=w.foldl=w.inject=function(a,b,c,d){var e=c!==void 0;a==null&&(a=[]);if(m&&a.reduce===m)return d&&(b=w.bind(b,d)),e?a.reduce(b,c):a.reduce(b);x(a,function(a,f,g){!e&&f===0?(c=a,e=!0):c=b.call(d,c,a,f,g)});if(!e)throw new TypeError("Reduce of empty array with no initial value");return c},w.reduceRight=w.foldr=function(a,b,c,d){a==null&&(a=[]);if(n&&a.reduceRight===n)return d&&(b=w.bind(b,d)),c!==void 0?a.reduceRight(b,c):a.reduceRight(b);var e=(w.isArray(a)?a.slice():w.toArray(a)).reverse();return w.reduce(e,b,c,d)},w.find=w.detect=function(a,b,c){var d;return y(a,function(a,e,f){if(b.call(c,a,e,f))return d=a,!0}),d},w.filter=w.select=function(a,b,c){var d=[];return a==null?d:o&&a.filter===o?a.filter(b,c):(x(a,function(a,e,f){b.call(c,a,e,f)&&(d[d.length]=a)}),d)},w.reject=function(a,b,c){var d=[];return a==null?d:(x(a,function(a,e,f){b.call(c,a,e,f)||(d[d.length]=a)}),d)},w.every=w.all=function(a,b,d){var e=!0;return a==null?e:p&&a.every===p?a.every(b,d):(x(a,function(a,f,g){if(!(e=e&&b.call(d,a,f,g)))return c}),e)};var y=w.some=w.any=function(a,b,d){b||(b=w.identity);var e=!1;return a==null?e:q&&a.some===q?a.some(b,d):(x(a,function(a,f,g){if(e=b.call(d,a,f,g))return c}),e)};w.include=w.contains=function(a,b){var c=!1;return a==null?c:r&&a.indexOf===r?a.indexOf(b)!=-1:(y(a,function(a){if(c=a===b)return!0}),c)},w.invoke=function(a,b){var c=g.call(arguments,2);return w.map(a,function(a){return(b.call?b||a:a[b]).apply(a,c)})},w.pluck=function(a,b){return w.map(a,function(a){return a[b]})},w.max=function(a,b,c){if(!b&&w.isArray(a))return Math.max.apply(Math,a);var d={computed:-Infinity};return x(a,function(a,e,f){var g=b?b.call(c,a,e,f):a;g>=d.computed&&(d={value:a,computed:g})}),d.value},w.min=function(a,b,c){if(!b&&w.isArray(a))return Math.min.apply(Math,a);var d={computed:Infinity};return x(a,function(a,e,f){var g=b?b.call(c,a,e,f):a;g<d.computed&&(d={value:a,computed:g})}),d.value},w.sortBy=function(a,b,c){return w.pluck(w.map(a,function(a,d,e){return{value:a,criteria:b.call(c,a,d,e)}}).sort(function(a,b){var c=a.criteria,d=b.criteria;return c<d?-1:c>d?1:0}),"value")},w.sortedIndex=function(a,b,c){c||(c=w.identity);var d=0,e=a.length;while(d<e){var f=d+e>>1;c(a[f])<c(b)?d=f+1:e=f}return d},w.toArray=function(a){return a?a.toArray?a.toArray():w.isArray(a)?a:w.isArguments(a)?g.call(a):w.values(a):[]},w.size=function(a){return w.toArray(a).length},w.first=w.head=function(a,b,c){return b!=null&&!c?g.call(a,0,b):a[0]},w.rest=w.tail=function(a,b,c){return g.call(a,b==null||c?1:b)},w.last=function(a){return a[a.length-1]},w.compact=function(a){return w.filter(a,function(a){return!!a})},w.flatten=function(a){return w.reduce(a,function(a,b){return w.isArray(b)?a.concat(w.flatten(b)):(a[a.length]=b,a)},[])},w.without=function(a){var b=g.call(arguments,1);return w.filter(a,function(a){return!w.include(b,a)})},w.uniq=w.unique=function(a,b){return w.reduce(a,function(a,c,d){if(0==d||(b===!0?w.last(a)!=c:!w.include(a,c)))a[a.length]=c;return a},[])},w.intersect=function(a){var b=g.call(arguments,1);return w.filter(w.uniq(a),function(a){return w.every(b,function(b){return w.indexOf(b,a)>=0})})},w.zip=function(){var a=g.call(arguments),b=w.max(w.pluck(a,"length")),c=new Array(b);for(var d=0;d<b;d++)c[d]=w.pluck(a,""+d);return c},w.indexOf=function(a,b,c){if(a==null)return-1;var d,e;if(c)return d=w.sortedIndex(a,b),a[d]===b?d:-1;if(r&&a.indexOf===r)return a.indexOf(b);for(d=0,e=a.length;d<e;d++)if(a[d]===b)return d;return-1},w.lastIndexOf=function(a,b){if(a==null)return-1;if(s&&a.lastIndexOf===s)return a.lastIndexOf(b);var c=a.length;while(c--)if(a[c]===b)return c;return-1},w.range=function(a,b,c){arguments.length<=1&&(b=a||0,a=0),c=arguments[2]||1;var d=Math.max(Math.ceil((b-a)/c),0),e=0,f=new Array(d);while(e<d)f[e++]=a,a+=c;return f},w.bind=function(a,b){if(a.bind===v&&v)return v.apply(a,g.call(arguments,1));var c=g.call(arguments,2);return function(){return a.apply(b,c.concat(g.call(arguments)))}},w.bindAll=function(a){var b=g.call(arguments,1);return b.length==0&&(b=w.functions(a)),x(b,function(b){a[b]=w.bind(a[b],a)}),a},w.memoize=function(a,b){var c={};return b||(b=w.identity),function(){var d=b.apply(this,arguments);return j.call(c,d)?c[d]:c[d]=a.apply(this,arguments)}},w.delay=function(a,b){var c=g.call(arguments,2);return setTimeout(function(){return a.apply(a,c)},b)},w.defer=function(a){return w.delay.apply(w,[a,1].concat(g.call(arguments,1)))};var z=function(a,b,c){var d;return function(){var e=this,f=arguments,g=function(){d=null,a.apply(e,f)};c&&clearTimeout(d);if(c||!d)d=setTimeout(g,b)}};w.throttle=function(a,b){return z(a,b,!1)},w.debounce=function(a,b){return z(a,b,!0)},w.once=function(a){var b=!1,c;return function(){return b?c:(b=!0,c=a.apply(this,arguments))}},w.wrap=function(a,b){return function(){var c=[a].concat(g.call(arguments));return b.apply(this,c)}},w.compose=function(){var a=g.call(arguments);return function(){var b=g.call(arguments);for(var c=a.length-1;c>=0;c--)b=[a[c].apply(this,b)];return b[0]}},w.after=function(a,b){return function(){if(--a<1)return b.apply(this,arguments)}},w.keys=u||function(a){if(a!==Object(a))throw new TypeError("Invalid object");var b=[];for(var c in a)j.call(a,c)&&(b[b.length]=c);return b},w.values=function(a){return w.map(a,w.identity)},w.functions=w.methods=function(a){return w.filter(w.keys(a),function(b){return w.isFunction(a[b])}).sort()},w.extend=function(a){return x(g.call(arguments,1),function(b){for(var c in b)b[c]!==void 0&&(a[c]=b[c])}),a},w.defaults=function(a){return x(g.call(arguments,1),function(b){for(var c in b)a[c]==null&&(a[c]=b[c])}),a},w.clone=function(a){return w.isArray(a)?a.slice():w.extend({},a)},w.tap=function(a,b){return b(a),a},w.isEqual=function(a,b){if(a===b)return!0;var c=typeof a,d=typeof b;if(c!=d)return!1;if(a==b)return!0;if(!a&&b||a&&!b)return!1;a._chain&&(a=a._wrapped),b._chain&&(b=b._wrapped);if(a.isEqual)return a.isEqual(b);if(w.isDate(a)&&w.isDate(b))return a.getTime()===b.getTime();if(w.isNaN(a)&&w.isNaN(b))return!1;if(w.isRegExp(a)&&w.isRegExp(b))return a.source===b.source&&a.global===b.global&&a.ignoreCase===b.ignoreCase&&a.multiline===b.multiline;if(c!=="object")return!1;if(a.length&&a.length!==b.length)return!1;var e=w.keys(a),f=w.keys(b);if(e.length!=f.length)return!1;for(var g in a)if(!(g in b)||!w.isEqual(a[g],b[g]))return!1;return!0},w.isEmpty=function(a){if(w.isArray(a)||w.isString(a))return a.length===0;for(var b in a)if(j.call(a,b))return!1;return!0},w.isElement=function(a){return!!a&&a.nodeType==1},w.isArray=t||function(a){return i.call(a)==="[object Array]"},w.isArguments=function(a){return!!a&&!!j.call(a,"callee")},w.isFunction=function(a){return!!(a&&a.constructor&&a.call&&a.apply)},w.isString=function(a){return!!(a===""||a&&a.charCodeAt&&a.substr)},w.isNumber=function(a){return!!(a===0||a&&a.toExponential&&a.toFixed)},w.isNaN=function(a){return a!==a},w.isBoolean=function(a){return a===!0||a===!1},w.isDate=function(a){return!!(a&&a.getTimezoneOffset&&a.setUTCFullYear)},w.isRegExp=function(a){return!(!(a&&a.test&&a.exec)||!a.ignoreCase&&a.ignoreCase!==!1)},w.isNull=function(a){return a===null},w.isUndefined=function(a){return a===void 0},w.noConflict=function(){return a._=b,this},w.identity=function(a){return a},w.times=function(a,b,c){for(var d=0;d<a;d++)b.call(c,d)},w.mixin=function(a){x(w.functions(a),function(b){D(b,w[b]=a[b])})};var A=0;w.uniqueId=function(a){var b=A++;return a?a+b:b},w.templateSettings={evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g},w.template=function(a,b){var c=w.templateSettings,d="var __p=[],print=function(){__p.push.apply(__p,arguments);};with(obj||{}){__p.push('"+a.replace(/\\/g,"\\\\").replace(/'/g,"\\'").replace(c.interpolate,function(a,b){return"',"+b.replace(/\\'/g,"'")+",'"}).replace(c.evaluate||null,function(a,b){return"');"+b.replace(/\\'/g,"'").replace(/[\r\n\t]/g," ")+"__p.push('"}).replace(/\r/g,"\\r").replace(/\n/g,"\\n").replace(/\t/g,"\\t")+"');}return __p.join('');",e=new Function("obj",d);return b?e(b):e};var B=function(a){this._wrapped=a};w.prototype=B.prototype;var C=function(a,b){return b?w(a).chain():a},D=function(a,b){B.prototype[a]=function(){var a=g.call(arguments);return h.call(a,this._wrapped),C(b.apply(w,a),this._chain)}};w.mixin(w),x(["pop","push","reverse","shift","sort","splice","unshift"],function(a){var b=d[a];B.prototype[a]=function(){return b.apply(this._wrapped,arguments),C(this._wrapped,this._chain)}}),x(["concat","join","slice"],function(a){var b=d[a];B.prototype[a]=function(){return C(b.apply(this._wrapped,arguments),this._chain)}}),B.prototype.chain=function(){return this._chain=!0,this},B.prototype.value=function(){return this._wrapped}}(),function(){var a=this,b=a.Backbone,c;typeof exports!="undefined"?c=exports:c=a.Backbone={},c.VERSION="0.5.3";var d=a._;!d&&typeof require!="undefined"&&(d=require("underscore")._);var e=a.jQuery||a.Zepto||a.ender;c.noConflict=function(){return a.Backbone=b,this},c.emulateHTTP=!1,c.emulateJSON=!1,c.Events={bind:function(a,b,c){var d=this._callbacks||(this._callbacks={}),e=d[a]||(d[a]=[]);return e.push([b,c]),this},unbind:function(a,b){var c;if(!a)this._callbacks={};else if(c=this._callbacks)if(!b)c[a]=[];else{var d=c[a];if(!d)return this;for(var e=0,f=d.length;e<f;e++)if(d[e]&&b===d[e][0]){d[e]=null;break}}return this},trigger:function(a){var b,c,d,e,f,g=2;if(!(c=this._callbacks))return this;while(g--){d=g?a:"all";if(b=c[d])for(var h=0,i=b.length;h<i;h++)(e=b[h])?(f=g?Array.prototype.slice.call(arguments,1):arguments,e[0].apply(e[1]||this,f)):(b.splice(h,1),h--,i--)}return this}},c.Model=function(a,b){var c;a||(a={});if(c=this.defaults)d.isFunction(c)&&(c=c.call(this)),a=d.extend({},c,a);this.attributes={},this._escapedAttributes={},this.cid=d.uniqueId("c"),this.set(a,{silent:!0}),this._changed=!1,this._previousAttributes=d.clone(this.attributes),b&&b.collection&&(this.collection=b.collection),this.initialize(a,b)},d.extend(c.Model.prototype,c.Events,{_previousAttributes:null,_changed:!1,idAttribute:"id",initialize:function(){},toJSON:function(){return d.clone(this.attributes)},get:function(a){return this.attributes[a]},escape:function(a){var b;if(b=this._escapedAttributes[a])return b;var c=this.attributes[a];return this._escapedAttributes[a]=w(c==null?"":""+c)},has:function(a){return this.attributes[a]!=null},set:function(a,b){b||(b={});if(!a)return this;a.attributes&&(a=a.attributes);var c=this.attributes,e=this._escapedAttributes;if(!b.silent&&this.validate&&!this._performValidation(a,b))return!1;this.idAttribute in a&&(this.id=a[this.idAttribute]);var f=this._changing;this._changing=!0;for(var g in a){var h=a[g];d.isEqual(c[g],h)||(c[g]=h,delete e[g],this._changed=!0,b.silent||this.trigger("change:"+g,this,h,b))}return!f&&!b.silent&&this._changed&&this.change(b),this._changing=!1,this},unset:function(a,b){if(a in this.attributes){b||(b={});var c=this.attributes[a],d={};return d[a]=void 0,!b.silent&&this.validate&&!this._performValidation(d,b)?!1:(delete this.attributes[a],delete this._escapedAttributes[a],a==this.idAttribute&&delete this.id,this._changed=!0,b.silent||(this.trigger("change:"+a,this,void 0,b),this.change(b)),this)}return this},clear:function(a){a||(a={});var b,c=this.attributes,d={};for(b in c)d[b]=void 0;if(!a.silent&&this.validate&&!this._performValidation(d,a))return!1;this.attributes={},this._escapedAttributes={},this._changed=!0;if(!a.silent){for(b in c)this.trigger("change:"+b,this,void 0,a);this.change(a)}return this},fetch:function(a){a||(a={});var b=this,d=a.success;return a.success=function(c,e,f){if(!b.set(b.parse(c,f),a))return!1;d&&d(b,c)},a.error=v(a.error,b,a),(this.sync||c.sync).call(this,"read",this,a)},save:function(a,b){b||(b={});if(a&&!this.set(a,b))return!1;var d=this,e=b.success;b.success=function(a,c,f){if(!d.set(d.parse(a,f),b))return!1;e&&e(d,a,f)},b.error=v(b.error,d,b);var f=this.isNew()?"create":"update";return(this.sync||c.sync).call(this,f,this,b)},destroy:function(a){a||(a={});if(this.isNew())return this.trigger("destroy",this,this.collection,a);var b=this,d=a.success;return a.success=function(c){b.trigger("destroy",b,b.collection,a),d&&d(b,c)},a.error=v(a.error,b,a),(this.sync||c.sync).call(this,"delete",this,a)},url:function(){var a=t(this.collection)||this.urlRoot||u();return this.isNew()?a:a+(a.charAt(a.length-1)=="/"?"":"/")+encodeURIComponent(this.id)},parse:function(a,b){return a},clone:function(){return new this.constructor(this)},isNew:function(){return this.id==null},change:function(a){this.trigger("change",this,a),this._previousAttributes=d.clone(this.attributes),this._changed=!1},hasChanged:function(a){return a?this._previousAttributes[a]!=this.attributes[a]:this._changed},changedAttributes:function(a){a||(a=this.attributes);var b=this._previousAttributes,c=!1;for(var e in a)d.isEqual(b[e],a[e])||(c=c||{},c[e]=a[e]);return c},previous:function(a){return!a||!this._previousAttributes?null:this._previousAttributes[a]},previousAttributes:function(){return d.clone(this._previousAttributes)},_performValidation:function(a,b){var c=this.validate(a);return c?(b.error?b.error(this,c,b):this.trigger("error",this,c,b),!1):!0}}),c.Collection=function(a,b){b||(b={}),b.comparator&&(this.comparator=b.comparator),d.bindAll(this,"_onModelEvent","_removeReference"),this._reset(),a&&this.reset(a,{silent:!0}),this.initialize.apply(this,arguments)},d.extend(c.Collection.prototype,c.Events,{model:c.Model,initialize:function(){},toJSON:function(){return this.map(function(a){return a.toJSON()})},add:function(a,b){if(d.isArray(a))for(var c=0,e=a.length;c<e;c++)this._add(a[c],b);else this._add(a,b);return this},remove:function(a,b){if(d.isArray(a))for(var c=0,e=a.length;c<e;c++)this._remove(a[c],b);else this._remove(a,b);return this},get:function(a){return a==null?null:this._byId[a.id!=null?a.id:a]},getByCid:function(a){return a&&this._byCid[a.cid||a]},at:function(a){return this.models[a]},sort:function(a){a||(a={});if(!this.comparator)throw new Error("Cannot sort a set without a comparator");return this.models=this.sortBy(this.comparator),a.silent||this.trigger("reset",this,a),this},pluck:function(a){return d.map(this.models,function(b){return b.get(a)})},reset:function(a,b){return a||(a=[]),b||(b={}),this.each(this._removeReference),this._reset(),this.add(a,{silent:!0}),b.silent||this.trigger("reset",this,b),this},fetch:function(a){a||(a={});var b=this,d=a.success;return a.success=function(c,e,f){b[a.add?"add":"reset"](b.parse(c,f),a),d&&d(b,c)},a.error=v(a.error,b,a),(this.sync||c.sync).call(this,"read",this,a)},create:function(a,b){var c=this;b||(b={}),a=this._prepareModel(a,b);if(!a)return!1;var d=b.success;return b.success=function(a,e,f){c.add(a,b),d&&d(a,e,f)},a.save(null,b),a},parse:function(a,b){return a},chain:function(){return d(this.models).chain()},_reset:function(a){this.length=0,this.models=[],this._byId={},this._byCid={}},_prepareModel:function(a,b){if(a instanceof c.Model)a.collection||(a.collection=this);else{var d=a;a=new this.model(d,{collection:this}),a.validate&&!a._performValidation(d,b)&&(a=!1)}return a},_add:function(a,b){b||(b={}),a=this._prepareModel(a,b);if(!a)return!1;var c=this.getByCid(a);if(c)throw new Error(["Can't add the same model to a set twice",c.id]);this._byId[a.id]=a,this._byCid[a.cid]=a;var d=b.at!=null?b.at:this.comparator?this.sortedIndex(a,this.comparator):this.length;return this.models.splice(d,0,a),a.bind("all",this._onModelEvent),this.length++,b.silent||a.trigger("add",a,this,b),a},_remove:function(a,b){return b||(b={}),a=this.getByCid(a)||this.get(a),a?(delete this._byId[a.id],delete this._byCid[a.cid],this.models.splice(this.indexOf(a),1),this.length--,b.silent||a.trigger("remove",a,this,b),this._removeReference(a),a):null},_removeReference:function(a){this==a.collection&&delete a.collection,a.unbind("all",this._onModelEvent)},_onModelEvent:function(a,b,c,d){if(a!="add"&&a!="remove"||c==this)a=="destroy"&&this._remove(b,d),b&&a==="change:"+b.idAttribute&&(delete this._byId[b.previous(b.idAttribute)],this._byId[b.id]=b),this.trigger.apply(this,arguments);else return}});var f=["forEach","each","map","reduce","reduceRight","find","detect","filter","select","reject","every","all","some","any","include","contains","invoke","max","min","sortBy","sortedIndex","toArray","size","first","rest","last","without","indexOf","lastIndexOf","isEmpty","groupBy"];d.each(f,function(a){c.Collection.prototype[a]=function(){return d[a].apply(d,[this.models].concat(d.toArray(arguments)))}}),c.Router=function(a){a||(a={}),a.routes&&(this.routes=a.routes),this._bindRoutes(),this.initialize.apply(this,arguments)};var g=/:([\w\d]+)/g,h=/\*([\w\d]+)/g,i=/[-[\]{}()+?.,\\^$|#\s]/g;d.extend(c.Router.prototype,c.Events,{initialize:function(){},route:function(a,b,e){c.history||(c.history=new c.History),d.isRegExp(a)||(a=this._routeToRegExp(a)),c.history.route(a,d.bind(function(c){var d=this._extractParameters(a,c);e.apply(this,d),this.trigger.apply(this,["route:"+b].concat(d))},this))},navigate:function(a,b){c.history.navigate(a,b)},_bindRoutes:function(){if(!this.routes)return;var a=[];for(var b in this.routes)a.unshift([b,this.routes[b]]);for(var c=0,d=a.length;c<d;c++)this.route(a[c][0],a[c][1],this[a[c][1]])},_routeToRegExp:function(a){return a=a.replace(i,"\\$&").replace(g,"([^/]*)").replace(h,"(.*?)"),new RegExp("^"+a+"$")},_extractParameters:function(a,b){return a.exec(b).slice(1)}}),c.History=function(){this.handlers=[],d.bindAll(this,"checkUrl")};var j=/^#*/,k=/msie [\w.]+/,l=!1;d.extend(c.History.prototype,{interval:50,getFragment:function(a,b){if(a==null)if(this._hasPushState||b){a=window.location.pathname;var c=window.location.search;c&&(a+=c)}else a=window.location.hash;return a=decodeURIComponent(a.replace(j,"")),a.indexOf(this.options.root)||(a=a.substr(this.options.root.length)),a},start:function(a){if(l)throw new Error("Backbone.history has already been started");this.options=d.extend({},{root:"/"},this.options,a),this._wantsPushState=!!this.options.pushState,this._hasPushState=!!(this.options.pushState&&window.history&&window.history.pushState);var b=this.getFragment(),c=document.documentMode,f=k.exec(navigator.userAgent.toLowerCase())&&(!c||c<=7);f&&(this.iframe=e('<iframe src="javascript:0" tabindex="-1" />').hide().appendTo("body")[0].contentWindow,this.navigate(b)),this._hasPushState?e(window).bind("popstate",this.checkUrl):"onhashchange"in window&&!f?e(window).bind("hashchange",this.checkUrl):setInterval(this.checkUrl,this.interval),this.fragment=b,l=!0;var g=window.location,h=g.pathname==this.options.root;if(this._wantsPushState&&!this._hasPushState&&!h)return this.fragment=this.getFragment(null,!0),window.location.replace(this.options.root+"#"+this.fragment),!0;this._wantsPushState&&this._hasPushState&&h&&g.hash&&(this.fragment=g.hash.replace(j,""),window.history.replaceState({},document.title,g.protocol+"//"+g.host+this.options.root+this.fragment));if(!this.options.silent)return this.loadUrl()},route:function(a,b){this.handlers.unshift({route:a,callback:b})},checkUrl:function(a){var b=this.getFragment();b==this.fragment&&this.iframe&&(b=this.getFragment(this.iframe.location.hash));if(b==this.fragment||b==decodeURIComponent(this.fragment))return!1;this.iframe&&this.navigate(b),this.loadUrl()||this.loadUrl(window.location.hash)},loadUrl:function(a){var b=this.fragment=this.getFragment(a),c=d.any(this.handlers,function(a){if(a.route.test(b))return a.callback(b),!0});return c},navigate:function(a,b){var c=(a||"").replace(j,"");if(this.fragment==c||this.fragment==decodeURIComponent(c))return;if(this._hasPushState){var d=window.location;c.indexOf(this.options.root)!=0&&(c=this.options.root+c),this.fragment=c,window.history.pushState({},document.title,d.protocol+"//"+d.host+c)}else window.location.hash=this.fragment=c,this.iframe&&c!=this.getFragment(this.iframe.location.hash)&&(this.iframe.document.open().close(),this.iframe.location.hash=c);b&&this.loadUrl(a)}}),c.View=function(a){this.cid=d.uniqueId("view"),this._configure(a||{}),this._ensureElement(),this.delegateEvents(),this.initialize.apply(this,arguments)};var m=function(a){return e(a,this.el)},n=/^(\S+)\s*(.*)$/,o=["model","collection","el","id","attributes","className","tagName"];d.extend(c.View.prototype,c.Events,{tagName:"div",$:m,initialize:function(){},render:function(){return this},remove:function(){return e(this.el).remove(),this},make:function(a,b,c){var d=document.createElement(a);return b&&e(d).attr(b),c&&e(d).html(c),d},delegateEvents:function(a){if(!a&&!(a=this.events))return;d.isFunction(a)&&(a=a.call(this)),this.undelegateEvents();for(var b in a){var c=this[a[b]];if(!c)throw new Error('Event "'+a[b]+'" does not exist');var f=b.match(n),g=f[1],h=f[2];c=d.bind(c,this),g+=".delegateEvents"+this.cid,h===""?e(this.el).bind(g,c):e(this.el).delegate(h,g,c)}},undelegateEvents:function(){e(this.el).unbind(".delegateEvents"+this.cid)},_configure:function(a){this.options&&(a=d.extend({},this.options,a));for(var b=0,c=o.length;b<c;b++){var e=o[b];a[e]&&(this[e]=a[e])}this.options=a},_ensureElement:function(){if(!this.el){var a=this.attributes||{};this.id&&(a.id=this.id),this.className&&(a["class"]=this.className),this.el=this.make(this.tagName,a)}else d.isString(this.el)&&(this.el=e(this.el).get(0))}});var p=function(a,b){var c=s(this,a,b);return c.extend=this.extend,c};c.Model.extend=c.Collection.extend=c.Router.extend=c.View.extend=p;var q={create:"POST",update:"PUT","delete":"DELETE",read:"GET"};c.sync=function(a,b,f){var g=q[a],h=d.extend({type:g,dataType:"json"},f);return h.url||(h.url=t(b)||u()),!h.data&&b&&(a=="create"||a=="update")&&(h.contentType="application/json",h.data=JSON.stringify(b.toJSON())),c.emulateJSON&&(h.contentType="application/x-www-form-urlencoded",h.data=h.data?{model:h.data}:{}),c.emulateHTTP&&(g==="PUT"||g==="DELETE")&&(c.emulateJSON&&(h.data._method=g),h.type="POST",h.beforeSend=function(a){a.setRequestHeader("X-HTTP-Method-Override",g)}),h.type!=="GET"&&!c.emulateJSON&&(h.processData=!1),e.ajax(h)};var r=function(){},s=function(a,b,c){var e;return b&&b.hasOwnProperty("constructor")?e=b.constructor:e=function(){return a.apply(this,arguments)},d.extend(e,a),r.prototype=a.prototype,e.prototype=new r,b&&d.extend(e.prototype,b),c&&d.extend(e,c),e.prototype.constructor=e,e.__super__=a.prototype,e},t=function(a){return!a||!a.url?null:d.isFunction(a.url)?a.url():a.url},u=function(){throw new Error('A "url" property or function must be specified')},v=function(a,b,c){return function(d){a?a(b,d,c):b.trigger("error",b,d,c)}},w=function(a){return a.replace(/&(?!\w+;|#\d+;|#x[\da-f]+;)/gi,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#x27;").replace(/\//g,"&#x2F;")}}.call(this),AssetHost.Models=function(){function a(){}return a.Asset=Backbone.Model.extend({urlRoot:"http://"+AssetHost.SERVER+"/api/assets/",modal:function(){var a;return(a=this._modal)!=null?a:this._modal=new AssetHost.Models.AssetModalView({model:this})},editModal:function(){var a;return(a=this._emodal)!=null?a:this._emodal=new AssetHost.Models.AssetEditModalView({model:this})},url:function(){var a;return a=this.isNew()?this.urlRoot:this.urlRoot+encodeURIComponent(this.id),AssetHost.TOKEN&&(a=a+"?"+$.param({auth_token:AssetHost.TOKEN})),a},chopCaption:function(a){var b,c;return a==null&&(a=100),b=this.get("caption"),b&&b.length>a&&(c="^(.{"+a+"}\\w*)\\W",b=b.match(new RegExp(c)),b?b=""+b[1]+"...":b=this.get("caption")),b}}),a.Assets=Backbone.Collection.extend({baseUrl:"/api/assets",model:a.Asset,comparator:function(a){return a.get("ORDER")||-Number(a.get("id"))}}),a.PaginatedAssets=a.Assets.extend({initialize:function(){var a;return _.bindAll(this,"parse","url"),typeof a!="undefined"||(a={}),this._page=1,this._query="",this.per_page=24,this.total_entries=0,this},parse:function(a,b){return this.next_page=b.getResponseHeader("X-Next-Page"),this.total_entries=b.getResponseHeader("X-Total-Entries"),console.log("Next page for assets is "+this.next_page),a},url:function(){return this.baseUrl+"?"+$.param({page:this._page,q:this._query})},query:function(a){return a==null&&(a=this._query),a!=null&&(this._query=a),this._query},page:function(a){return a==null&&(a=null),console.log("page is ",this._page,a),a!=null&&a!==""&&(this._page=Number(a)),this._page}}),a.AssetDropAssetView=Backbone.View.extend({tagName:"li",template:'<button class="delete small awesome red">x</button>\n<%= tags ? tags.thumb : "INVALID" %>\n<b><%= title %></b>\n<p><%= chop %></p>',events:{"click button.delete":"_remove",click:"_click"},initialize:function(){var a=this;return this.drop=this.options.drop,this.model.bind("change",function(){return a.render()}),this.render()},_remove:function(){return console.log(""),this.drop.trigger("remove",this.model),!1},_click:function(a){if(!$(a.currentTarget).hasClass("delete"))return this.drop.trigger("click",this.model)},render:function(){return $(this.el).html(_.template(this.template,_(this.model.toJSON()).extend({chop:this.model.chopCaption()}))),$(this.el).attr("data-asset-id",this.model.get("id")),this}}),a.AssetDropView=Backbone.View.extend({tagName:"ul",className:"assets",initialize:function(){var a=this;return this._views={},this.collection.bind("add",function(b){return console.log("add event from ",b),a.collection.sort()}),this.collection.bind("remove",function(b){return console.log("remove event from ",b),a.collection.sort()}),this.collection.bind("reset",function(b){return console.log("reset event from ",b),_(a._views).each(function(a){return $(a.el).detach()}),a._views={},a.render()})},render:function(){var b=this;return this.collection.each(function(c){var d,e,f;return(f=(d=b._views)[e=c.cid])!=null?f:d[e]=new a.AssetDropAssetView({model:c,drop:b})}),$(this.el).append(_(this._views).map(function(a){return a.el})),$(this.el).sortable({update:function(a,c){return _(b.el.children).each(function(a,c){var d;return d=$(a).attr("data-asset-id"),b.collection.get(d).attributes.ORDER=c,console.log("set idx for "+d+" to "+c)}),b.collection.sort()}}),this}}),a.AssetSearchView=Backbone.View.extend({className:"search_box",template:'<input type="text" style="width: 200px" value="<%= query %>"/>\n<button class="large awesome orange">Search</button>',events:{"click button":"search","keypress input:text":"_keypress"},initialize:function(){var a=this;return this.collection.bind("all",function(){return a.render()})},_keypress:function(a){if(a.which===13)return this.search()},search:function(){var a;return a=$(this.el).find("input")[0].value,console.log("in search for ",a),this.trigger("search",a)},render:function(){return $(this.el).html(_.template(this.template,{query:this.collection.query()})),this}}),a.AssetBrowserAssetView=Backbone.View.extend({tagName:"li",template:'<button data-asset-url="<%= url %>" draggable="true"><%= tags.thumb %></button>',tipTemplate:"            <h3><%= title %></h3>\n<%= owner %>\n<br/><%= size %>                ",initialize:function(){var a=this;return this.id="ab_"+this.model.get("id"),$(this.el).attr("data-asset-url",this.model.get("url")),this.render(),$(this.el).find("button")[0].addEventListener("click",function(b){return a.trigger("click",a.model)},!0),$(this.el).tooltipsy({alignTo:"element",content:_.template(this.tipTemplate,this.model.toJSON())}),this.model.bind("change",function(){return a.render()})},render:function(){return $(this.el).html(_.template(this.template,this.model.toJSON())),$(this.el).attr("draggable",!0),this}}),a.AssetBrowserView=Backbone.View.extend({tagName:"ul",initialize:function(){var a=this;return this._views={},this.collection.bind("reset",function(){return _(a._views).each(function(a){return $(a.el).detach()}),a._views={},a.render()})},pages:function(){var a;return(a=this._pages)!=null?a:this._pages=(new AssetHost.Models.PaginationLinks(this.collection)).render()},loading:function(){return $(this.el).fadeOut()},render:function(){var a=this;return this.collection.each(function(b){var c,d,e;return(e=(c=a._views)[d=b.cid])==null&&(c[d]=new AssetHost.Models.AssetBrowserAssetView({model:b})),a._views[b.cid].bind("click",function(b){return a.trigger("click",b)})}),$(this.el).append(_(this._views).map(function(a){return a.el})),$(this.el).fadeIn(),this}}),a.AssetModalView=Backbone.View.extend({events:{"click button.select":"_select","click button.admin":"_admin"},template:'<div class="ah_asset_browse">\n    <%= tags.lead %>\n    <h1><%= title %></h1>\n    <h2><%= owner %></h2>\n    <h2><%= size %></h2>\n    <p><%= caption %></p> \n                    \n    <% if (admin) { %><button class="admin medium awesome yellow">View in Admin</button><% }; %>\n    <% if (select) { %><button class="select large awesome orange">Select Asset</button><% }; %>\n</div>',open:function(a){return this.options=a||{},console.log("modal options is ",this.options),$(this.render().el).dialog(_(_({}).extend({modal
:!0,width:600})).extend(this.options.options||{}))},close:function(){return $(this.el).dialog("close")},_select:function(){return this.close(),this.model.trigger("selected",this.model)},_admin:function(){return this.close(),this.model.trigger("admin",this.model)},render:function(){return $(this.el).html(_.template(this.template,_(this.model.toJSON()).extend({select:this.options.select!=null?this.options.select:!0,admin:this.options.admin!=null?this.options.admin:!1}))),this}}),a.SaveAndCloseView=Backbone.View.extend({events:{"click button":"saveAndClose"},initialize:function(){var a=this;return this.collection.bind("all",function(){return a.render()}),this.render()},template:'<button id="saveAndClose" class="large awesome orange">\n    Save and Close\n    <% if (count) { %>(<%= count %> Assets)<% } %>\n</button>',saveAndClose:function(){return console.log("saveAndClose Clicked with ",this.collection),this.collection.sort(),this.trigger("saveAndClose",this.collection.toJSON())},render:function(){return $(this.el).html(_.template(this.template,{count:this.collection.size()})),this}}),a.PaginationLinks=Backbone.View.extend({DefaultOptions:{inner_window:4,outer_window:1,prev_label:"&#8592; Previous",next_label:"Next &#8594;",separator:" ",spacer:"<li class='spacer'>...</li>"},events:{"click li":"clickPage"},initialize:function(a,b){var c=this;return this.options=_(_({}).extend(this.DefaultOptions)).extend(b||{}),this.collection=a,this.collection.bind("reset",function(){return c.render()}),this.collection.bind("add",function(){return c.render()}),this.collection.bind("change",function(){return c.render()})},template:'<ul class="pages">\n<% if (current > 1) { %>\n    <li data-page="<%= current - 1 %>" class="prev"><%= options.prev_label %></li>\n<% } %>\n<%= links %>\n<% if ( current + 1 <= pages ) { %>\n    <li data-page="<%= current + 1 %>" class="next"><%= options.next_label %></li>\n<% } %>\n</ul>',linkTemplate:'<li data-page="<%= page %>" <% if (current) { %>class="current"<% } %> ><%= page %></li>',clickPage:function(a){var b;b=$(a.currentTarget).attr("data-page");if(b)return console.log("in clickPage for ",b),this.trigger("page",b)},render:function(){var a,b,c,d,e=this;return c=Math.floor(this.collection.total_entries/this.collection.per_page+1),a=this.collection._page,console.log("current / total pages: ",a,c),d={},b=[],_(_.range(1,1+this.options.outer_window)).each(function(c){return b.push(_.template(e.linkTemplate,{page:c,current:a===c})),d[c]=!0}),_(_.range(a-this.options.inner_window,a)).each(function(a){if(a>0&&!d[a])return a-1>0&&!d[a-1]&&b.push(e.options.spacer),b.push(_.template(e.linkTemplate,{page:a,current:!1})),d[a]=!0}),d[a]||(a-1>0&&!d[a-1]&&b.push(this.options.spacer),b.push(_.template(this.linkTemplate,{page:a,current:!0})),d[a]=!0),_(_.range(a+1,a+this.options.inner_window+1)).each(function(a){if(a<c&&!d[a])return a-1>0&&!d[a-1]&&b.push(e.options.spacer),b.push(_.template(e.linkTemplate,{page:a,current:!1})),d[a]=!0}),_(_.range(c+1-this.options.outer_window,c+1)).each(function(c){if(c>0&&!d[c])return c-1>0&&!d[c-1]&&b.push(e.options.spacer),b.push(_.template(e.linkTemplate,{page:c,collection:e.collection,current:a===c})),d[c]=!0}),$(this.el).html(_.template(this.template,{current:a,pages:c,links:b.join(this.options.separator),options:this.options})),this}}),a.queuedSync=function(a,b,c,d){return console.log("in sync")},a.QueuedFile=Backbone.Model.extend({sync:a.queuedSync,upload:function(){var a=this;return this.xhr?!1:(this.xhr=new XMLHttpRequest,$(this.xhr.upload).bind("progress",function(b){return b=b.originalEvent,a.set({PERCENT:b.lengthComputable?Math.floor(b.loaded/b.total*100):b.loaded})}),$(this.xhr.upload).bind("complete",function(b){return a.set({STATUS:"pending"})}),this.xhr.onreadystatechange=function(b){console.log("in onreadystatechange",b);if(a.xhr.readyState===4&&a.xhr.status===200){console.log("got complete status"),a.set({STATUS:"complete"});if(b.responseText!=="ERROR")return a.set({ASSET:$.parseJSON(a.xhr.responseText)}),a.trigger("uploaded",a)}},this.xhr.open("POST",this.collection.urlRoot,!0),this.xhr.setRequestHeader("X_FILE_NAME",this.get("file").fileName),this.xhr.setRequestHeader("CONTENT_TYPE",this.get("file").type),this.xhr.setRequestHeader("HTTP_X_FILE_UPLOAD","true"),this.xhr.send(this.get("file")),this.set({STATUS:"uploading"}))},readableSize:function(){var a,b,c;if(!this.get("size"))return!1;b=this.get("size"),c=["B","KB","MB","GB","TB","PB","EB","ZB","YB"],a=0;while(b>=1024)b/=1024,++a;return b.toFixed(1)+" "+c[a]}}),a.QueuedFiles=Backbone.Collection.extend({model:a.QueuedFile,urlRoot:"/a/assets/upload",initialize:function(a,b){return this.urlRoot=b.urlRoot}}),a.QueuedFileView=Backbone.View.extend({events:{"click button.remove":"_remove","click button.upload":"_upload"},tagName:"li",template:'<% if (!xhr) { %>\n    <button class="remove small awesome red">x</button>\n    <button class="upload small awesome green">Upload</button>\n<% }; %>\n<% if (STATUS == \'uploading\') { %>\n    <b>(<%= PERCENT %>%)</b>\n    <br/>\n<% }; %>\n<%= name %>: <%= size %> ',initialize:function(){var a,b,c=this;return this.model.bind("change",function(){return c.render()}),this.img="",a=this.model.get("file"),a.type.match("image.*")&&(b=new FileReader,b.onload=function(b){var d;return console.log("got reader.onload for ",b),c.img=$("<img/>",{"class":"thumb",src:b.target.result,title:a.name}),d=/^([^,]+),(.*)$/.exec(b.target.result),c.exif=EXIF.readFromBinaryFile(window.atob(d[2])),c.render()},b.readAsDataURL(a)),this.render()},_remove:function(a){return console.log("calling remove for ",this),this.model.collection.remove(this.model)},_upload:function(a){return this.model.upload()},render:function(){return $(this.el).attr("class",this.model.get("STATUS")),$(this.el).html(_.template(this.template,{exif:this.exif,name:this.model.get("name"),size:this.model.readableSize(),STATUS:this.model.get("STATUS"),PERCENT:this.model.get("PERCENT"),xhr:this.model.xhr?!0:!1})),this.img&&$(this.el).prepend(this.img),this}}),a.QueuedFilesView=Backbone.View.extend({tagName:"ul",className:"uploads",initialize:function(){var b=this;return this._views={},this.collection.bind("add",function(c){return console.log("add event from ",c),b._views[c.cid]=new a.QueuedFileView({model:c}),b.render()}),this.collection.bind("remove",function(a){return console.log("remove event from ",a),$(b._views[a.cid].el).detach(),delete b._views[a.cid],b.render()}),this.collection.bind("reset",function(a){return console.log("reset event from ",a),b._views={}}),console.log("collection is ",this.collection)},_reset:function(a){return console.log("reset event from ",a)},render:function(){var b=this;return this.collection.each(function(c){var d,e,f;return(f=(d=b._views)[e=c.cid])!=null?f:d[e]=new a.QueuedFileView({model:c})}),$(this.el).append(_(this._views).map(function(a){return a.el})),console.log("rendered files el is ",this.el),this}}),a}(),function(){var a=Array.prototype.slice;AssetHost.Slideshow=function(){function b(a){var c=this;this.options=_(_({}).extend(this.DefaultOptions)).extend(a||{}),_.extend(this,Backbone.Events),$(function(){return c.hidden=$("<div/>",{style:"position:absolute; top:-10000px; width:0px; height:0px;"}),$("body").append(c.hidden),c.el=$(c.options.el),c.assets=new b.Assets(c.options.assets),c.nav=new b.NavigationLinks({current:c.options.start,total:c.assets.length}),c.slides=new b.Slides({collection:c.assets,hidden:c.hidden,initial:c.options.initial,imgwidth:c.options.imgwidth,imgheight:c.options.imgheight,nav:c.nav,margin:c.options.margin}),c.el.html(c.slides.el),c.slides.render(),c.nav.bind("slide",function(a){return c.slides.slideTo(a)}),c.slides.bind("slide",function(a){return c.nav.setCurrent(a),c.trigger("slide",a)})})}return b.prototype.DefaultOptions={el:"#photo",initial:4,start:0,imgwidth:null,imgheight:null,margin:12},b.Asset=Backbone.Model.extend({initialize:function(){}}),b.Assets=Backbone.Collection.extend({url:"/",model:b.Asset}),b.Slide=Backbone.View.extend({tagName:"li",className:"slide",template:'<div class="text" style="width: <%= width %>px;margin: 0 auto">\n    <div class="credit"><%= credit %></div>\n    <p><%= caption %></p>\n</div>',fullTemplate:"",initialize:function(){return this.slides=this.options.slides,this.hidden=this.options.hidden,this.index=this.options.index},render:function(){var a,b,c,d,e=this;return b=this.model.get("sizes"),_(b).each(function(a,b){return a.key=b}),b=_(b).sortBy(function(a){return-a.width}),this.imgSize=_(b).find(function(a,b){return a.width<=$(e.el).width()?!0:!1}),c=$("<div/>",{width:this.imgSize.width}),$(c).html(_.template(this.template,{credit:this.model.get("credit"),caption:this.model.get("caption"),url:this.model.get("url"),width:this.imgSize.width})),this.hidden.append(c),this.textHeight=$(c).height(),this.imgHeight=$(this.el).height()?$(this.el).height()-this.textHeight:this.imgSize.height,$(c).detach(),$(this.el).html(_.template(this.template,{credit:this.model.get("credit"),caption:this.model.get("caption"),url:this.model.get("url"),width:this.imgSize.width})),a=this.imgSize.height,this.scale=1,a>this.imgHeight&&(d=this.imgHeight/a,d<1&&(this.scale=d)),this.imgDiv=$("<div/>",{"class":"ah_imgholder",style:"width:"+this.imgSize.width*this.scale+"px;height:"+this.imgSize.height*this.scale+"px"}),$(this.el).prepend(this.imgDiv),this},loadImage:function(){var a=this;return this.slides.current===this.index?$(this.el).fadeOut():$(this.el).hide(),this.img=$("<img/>",{src:this.model.get("urls")[this.imgSize.key],width:this.imgSize.width*this.scale,height:this.imgSize.height*this.scale}),this.hidden.append(this.img),this.img.load(function(b){return a.imgDiv.css("margin-left",($(a.el).width()-a.img.width())/2),a.imgDiv.css("margin-top",(a.imgHeight-a.img.height())/2),a.img.detach(),a.imgDiv.html(a.img),a.slides.current===a.index?$(a.el).fadeIn("slow"):$(a.el).show(),a.trigger("imgload")})}}),b.Slides=Backbone.View.extend({className:"slideview",events:{mouseover:"_mouseover",mouseout:"_mouseout"},initialize:function(){var a,c,d=this;return this.hidden=this.options.hidden,this.slides=[],this.collection.each(function(a,c){var e;return e=new b.Slide({model:a,slides:d,hidden:d.hidden,index:c}),d.slides[c]=e}),a=this.slides[0],$(a.el).css("width",this.options.imgwidth+"px"),a.render(),c=a.textHeight,this.swidth=this.options.imgwidth,this.sheight=this.options.imgheight+c,console.log("slide height should be ",this.sheight),this.queued=[],this.loaded=[],this.active=!1,this.current=null,this.hasmouse=!1,$(window).bind("keydown",function(a){return d._keyhandler(a)})},render:function(){var a,b,c,d=this;return $(this.el).attr("tabindex",-1),$(this.el).css("width",this.swidth+"px"),c=this.collection.length*this.swidth,this.options.margin&&(c+=this.collection.length*this.options.margin),b=this.sheight,this.options.nav&&($(this.el).html(this.options.nav.el),this.options.nav.render(),a=$(this.options.nav.el).outerHeight(),b+=a),$(this.el).css("height",b+"px"),this.view=$("<ul/>",{style:"position:relative;width:"+c+"px;height:"+this.sheight+"px"}),$(this.el).prepend(this.view),_(this.slides).each(function(a,b){return a.bind("imgload",function(){return d._loaded(a,b)}),$(a.el).css("width",d.swidth+"px"),$(a.el).css("height",d.sheight+"px"),$(a.el).css("left",d.swidth*b+(d.options.margin||0)*b+"px"),$(d.view).append(a.render().el)}),this.queueSlides(_.range(0,4))},_mouseover:function(a){return this.hasmouse=!0},_mouseout:function(a){return this.hasmouse=!1},_keyhandler:function(a){if(this.hasmouse){if(a.which===37)return this.slideBy(-1);if(a.which===39)return this.slideBy(1)}},slideTo:function(a){return this.view.stop().animate({left:-$(this.slides[a].el).position().left},"slow"),this.current=a,this.trigger("slide",a),this._updateLoadQueue()},slideBy:function(a){var b;b=this.current+a;if(this.slides[b])return this.slideTo(b)},queueSlides:function(){var b,c=this;b=1<=arguments.length?a.call(arguments,0):[],_(_(b).flatten()).each(function(a){if(!c.loaded[a]||c.loaded[a]===0&&!_(c.queued).contains(a))return console.log("queuing "+a),c.queued.push(a)});if(!this.active)return this._fireUpQueue()},_updateLoadQueue:function(){var a,b=this;return(!this.loaded[this.current]||this.loaded[this.current]===0)&&this.queued.unshift(this.current),a=[],_(_.range(this.current+1,this.current+4)).each(function(c){if(b.slides[c])return a.push(c)}),_(_.range(this.current-2,this.current)).each(function(c){if(b.slides[c])return a.push(c)}),this.queueSlides(a)},_fireUpQueue:function(){var a,b;return!this.queued||this.queued.length===0?!1:(console.log("_fireUpQueue with queue of "+this.queued),a=this.queued.shift(),b=this.slides[a],!this.loaded[a]||this.loaded[a]===0?(console.log("triggering load on "+a),this.loaded[a]=1,this.active=a,b.loadImage()):this._fireUpQueue())},_loaded:function(a,b){console.log("got _loaded for "+b),this.loaded[b]=2;if(this.active===b)return this.active=null,this._fireUpQueue()}}),b.NavigationLinks=Backbone.View.extend({className:"nav",events:{"click button":"_buttonClick"},template:'<div style="width: 15%;">\n    <button <% print(prev ? "data-idx=\'"+prev+"\' class=\'prev-arrow\'" : "class=\'disabled prev-arrow\'"); %> >Prev</button>\n</div>\n<div class="buttons" style="width:70%;"></div>\n<div style="width: 15%">\n    <button <% print(next ? "data-idx=\'"+next+"\' class=\'next-arrow\'" : "class=\'disabled next-arrow\'"); %> >Next</button>\n</div>\n<br style="clear:both;line-height:0;height:0"/>',initialize:function(){return this.total=this.options.total,this.current=Number(this.options.current)+1,this.render()},_buttonClick:function(a){var b;b=$(a.currentTarget).attr("data-idx");if(b)return b=Number(b)-1,console.log("nav trigger slide to "+b),this.trigger("slide",b)},setCurrent:function(a){return this.current=Number(a)+1,console.log("nav set current to "+this.current),this.render()},render:function(){var a,b,c,d,e=this;return a=_(function(){d=[];for(var a=1,b=this.total;1<=b?a<=b:a>=b;1<=b?a++:a--)d.push(a);return d}.apply(this)).map(function(a){return $("<button/>",{"data-idx":a,text:a,"class":e.current===a?"current":""})[0]}),$(this.el).html(_.template(this.template,{current:this.current,total:this.total,prev:this.current-1>0?this.current-1:null,next:this.current+1<=this.total?this.current+1:null})),this.$(".buttons").html(a)}}),b}()}.call(this),AssetHost.Client=function(){function a(b){var c,d=this;this.options=_(_({}).extend(this.DefaultOptions)).extend(b||{}),this.clients=[],c=this.clients,$(function(){var b;return b=d.options.attr,$("img["+d.options.attr+"]").livequery(function(){var d;d=$(this).attr(b);if(a[d])return c.push(new a[d](this))})})}return a.prototype.DefaultOptions={attr:"data-assethost"},a}(),AssetHost.Client.BrightcoveVideo=function(){function a(a,b){var c=this;this.opts=_(_({}).extend(this.DefaultOptions)).extend(b||{}),this.el=$(a),this.w=$(a).width(),this.h=$(a).height(),this.videoid=this.el.attr("data-ah-videoid"),console.log("Setting up for brightcove video ",this.videoid),this.overlay=$("<div/>",{style:"position:relative;left:0;height:0;margin:0;padding:0;border:0"}),this.el.before(this.overlay),this.click=$("<div/>",{"class":"BrightcoveVideoOverlay",style:"width:"+this.w+"px;height:"+this.h+"px"}),this.overlay.append(this.click),this.click.bind("click",function(a){return c.launch()})}return a.prototype.DefaultOptions={playerKey:"AQ~~,AAAAmtVKbGE~,pW41hkPiaos27C7knwyeOWQgVlG4w7v5",playerId:"1247178207001",brightcoveJS:"http://admin.brightcove.com/js/BrightcoveExperiences_all.js"},a.prototype.template='<div style="display:none"></div>\n\n<object id="ah_bcove_<%= videoid %>" class="BrightcoveExperience">\n  <param name="bgcolor" value="#FFFFFF" />\n  <param name="width" value="<%= width %>" />\n  <param name="height" value="<%= height %>" />\n  <param name="playerID" value="<%= playerid %>" />\n  <param name="playerKey" value="<%= playerkey %>" />\n  <param name="isVid" value="true" />\n  <param name="isUI" value="true" />\n  <param name="dynamicStreaming" value="true" />\n  <param name="@videoPlayer" value="<%= videoid %>" />\n</object>',a.prototype.launch=function(){var a=this;return this.html=_.template(this.template,{width:this.w,height:this.h,videoid:this.videoid,playerid:this.opts.playerId,playerkey:this.opts.playerKey}),window.brightcove!=null?(this.overlay.detach(),this.swap()):$.getScript(this.opts.brightcoveJS,function(){return a.overlay.detach(),a.swap()})},a.prototype.swap=function(){var a;return a=$("<div/>",{style:"width:"+this.w+"px;height:"+this.h+"px"}),this.el.wrap(a),this.el.replaceWith(this.html),brightcove.createExperiences()},a}()
