(function(K,c,m,H,h,E){var b=this;var k=Math.floor(Math.random()*10000);var n=Function.prototype;var N=/^((http.?:)\/\/([^:\/\s]+)(:\d+)*)/;var O=/[\-\w]+\/\.\.\//;var C=/([^:])\/\//g;var F="";var l={};var J=K.easyXDM;var R="easyXDM_";var B;var v=false;function z(V,X){var W=typeof V[X];return W=="function"||(!!(W=="object"&&V[X]))||W=="unknown"}function r(V,W){return !!(typeof(V[W])=="object"&&V[W])}function o(V){return Object.prototype.toString.call(V)==="[object Array]"}function T(W){try{var V=new ActiveXObject(W);V=null;return true}catch(X){return false}}var s,u;if(z(K,"addEventListener")){s=function(X,V,W){X.addEventListener(V,W,false)};u=function(X,V,W){X.removeEventListener(V,W,false)}}else{if(z(K,"attachEvent")){s=function(V,X,W){V.attachEvent("on"+X,W)};u=function(V,X,W){V.detachEvent("on"+X,W)}}else{throw new Error("Browser not supported")}}var U=false,G=[],I;if("readyState" in c){I=c.readyState;U=I=="complete"||(~navigator.userAgent.indexOf("AppleWebKit/")&&(I=="loaded"||I=="interactive"))}else{U=!!c.body}function p(){if(U){return}U=true;for(var V=0;V<G.length;V++){G[V]()}G.length=0}if(!U){if(z(K,"addEventListener")){s(c,"DOMContentLoaded",p)}else{s(c,"readystatechange",function(){if(c.readyState=="complete"){p()}});if(c.documentElement.doScroll&&K===top){(function f(){if(U){return}try{c.documentElement.doScroll("left")}catch(V){H(f,1);return}p()}())}}s(K,"load",p)}function D(W,V){if(U){W.call(V);return}G.push(function(){W.call(V)})}function j(){var X=parent;if(F!==""){for(var V=0,W=F.split(".");V<W.length;V++){X=X[W[V]]}}return X.easyXDM}function d(V){K.easyXDM=J;F=V;if(F){R="easyXDM_"+F.replace(".","_")+"_"}return l}function w(V){return V.match(N)[3]}function e(V){return V.match(N)[4]||""}function g(X){var V=X.match(N);var Y=V[2],Z=V[3],W=V[4]||"";if((Y=="http:"&&W==":80")||(Y=="https:"&&W==":443")){W=""}return Y+"//"+Z+W}function y(V){V=V.replace(C,"$1/");if(!V.match(/^(http||https):\/\//)){var W=(V.substring(0,1)==="/")?"":m.pathname;if(W.substring(W.length-1)!=="/"){W=W.substring(0,W.lastIndexOf("/")+1)}V=m.protocol+"//"+m.host+W+V}while(O.test(V)){V=V.replace(O,"")}return V}function M(V,Y){var aa="",X=V.indexOf("#");if(X!==-1){aa=V.substring(X);V=V.substring(0,X)}var Z=[];for(var W in Y){if(Y.hasOwnProperty(W)){Z.push(W+"="+E(Y[W]))}}return V+(v?"#":(V.indexOf("?")==-1?"?":"&"))+Z.join("&")+aa}var P=(function(V){V=V.substring(1).split("&");var X={},Y,W=V.length;while(W--){Y=V[W].split("=");X[Y[0]]=h(Y[1])}return X}(/xdm_e=/.test(m.search)?m.search:m.hash));function q(V){return typeof V==="undefined"}var L=function(){var W={};var X={a:[1,2,3]},V='{"a":[1,2,3]}';if(typeof JSON!="undefined"&&typeof JSON.stringify==="function"&&JSON.stringify(X).replace((/\s/g),"")===V){return JSON}if(Object.toJSON){if(Object.toJSON(X).replace((/\s/g),"")===V){W.stringify=Object.toJSON}}if(typeof String.prototype.evalJSON==="function"){X=V.evalJSON();if(X.a&&X.a.length===3&&X.a[2]===3){W.parse=function(Y){return Y.evalJSON()}}}if(W.stringify&&W.parse){L=function(){return W};return W}return null};function Q(V,W,X){var Z;for(var Y in W){if(W.hasOwnProperty(Y)){if(Y in V){Z=W[Y];if(typeof Z==="object"){Q(V[Y],Z,X)}else{if(!X){V[Y]=W[Y]}}}else{V[Y]=W[Y]}}}return V}function a(){var V=c.createElement("iframe");V.name=R+"TEST";Q(V.style,{position:"absolute",left:"-2000px",top:"0px"});c.body.appendChild(V);B=V.contentWindow!==K.frames[V.name];c.body.removeChild(V)}function x(V){if(q(B)){a()}var X;if(B){X=c.createElement('<iframe name="'+V.props.name+'"/>')}else{X=c.createElement("IFRAME");X.name=V.props.name}X.id=X.name=V.props.name;delete V.props.name;if(V.onLoad){s(X,"load",V.onLoad)}if(typeof V.container=="string"){V.container=c.getElementById(V.container)}if(!V.container){X.style.position="absolute";X.style.top="-2000px";V.container=c.body}var W=V.props.src;delete V.props.src;Q(X,V.props);X.border=X.frameBorder=0;V.container.appendChild(X);X.src=W;V.props.src=W;return X}function S(Y,X){if(typeof Y=="string"){Y=[Y]}var W,V=Y.length;while(V--){W=Y[V];W=new RegExp(W.substr(0,1)=="^"?W:("^"+W.replace(/(\*)/g,".$1").replace(/\?/g,".")+"$"));if(W.test(X)){return true}}return false}function i(X){var ac=X.protocol,W;X.isHost=X.isHost||q(P.xdm_p);v=X.hash||false;if(!X.props){X.props={}}if(!X.isHost){X.channel=P.xdm_c;X.secret=P.xdm_s;X.remote=P.xdm_e;ac=P.xdm_p;if(X.acl&&!S(X.acl,X.remote)){throw new Error("Access denied for "+X.remote)}}else{X.remote=y(X.remote);X.channel=X.channel||"default"+k++;X.secret=Math.random().toString(16).substring(2);if(q(ac)){if(g(m.href)==g(X.remote)){ac="4"}else{if(z(K,"postMessage")||z(c,"postMessage")){ac="1"}else{if(z(K,"ActiveXObject")&&T("ShockwaveFlash.ShockwaveFlash")){ac="6"}else{if(navigator.product==="Gecko"&&"frameElement" in K&&navigator.userAgent.indexOf("WebKit")==-1){ac="5"}else{if(X.remoteHelper){X.remoteHelper=y(X.remoteHelper);ac="2"}else{ac="0"}}}}}}}switch(ac){case"0":Q(X,{interval:100,delay:2000,useResize:true,useParent:false,usePolling:false},true);if(X.isHost){if(!X.local){var aa=m.protocol+"//"+m.host,V=c.body.getElementsByTagName("img"),ab;var Y=V.length;while(Y--){ab=V[Y];if(ab.src.substring(0,aa.length)===aa){X.local=ab.src;break}}if(!X.local){X.local=K}}var Z={xdm_c:X.channel,xdm_p:0};if(X.local===K){X.usePolling=true;X.useParent=true;X.local=m.protocol+"//"+m.host+m.pathname+m.search;Z.xdm_e=X.local;Z.xdm_pa=1}else{Z.xdm_e=y(X.local)}if(X.container){X.useResize=false;Z.xdm_po=1}X.remote=M(X.remote,Z)}else{Q(X,{channel:P.xdm_c,remote:P.xdm_e,useParent:!q(P.xdm_pa),usePolling:!q(P.xdm_po),useResize:X.useParent?false:X.useResize})}W=[new l.stack.HashTransport(X),new l.stack.ReliableBehavior({}),new l.stack.QueueBehavior({encode:true,maxLength:4000-X.remote.length}),new l.stack.VerifyBehavior({initiate:X.isHost})];break;case"1":W=[new l.stack.PostMessageTransport(X)];break;case"2":W=[new l.stack.NameTransport(X),new l.stack.QueueBehavior(),new l.stack.VerifyBehavior({initiate:X.isHost})];break;case"3":W=[new l.stack.NixTransport(X)];break;case"4":W=[new l.stack.SameOriginTransport(X)];break;case"5":W=[new l.stack.FrameElementTransport(X)];break;case"6":if(!X.swf){X.swf="../../tools/easyxdm.swf"}W=[new l.stack.FlashTransport(X)];break}W.push(new l.stack.QueueBehavior({lazy:X.lazy,remove:true}));return W}function A(Y){var Z,X={incoming:function(ab,aa){this.up.incoming(ab,aa)},outgoing:function(aa,ab){this.down.outgoing(aa,ab)},callback:function(aa){this.up.callback(aa)},init:function(){this.down.init()},destroy:function(){this.down.destroy()}};for(var W=0,V=Y.length;W<V;W++){Z=Y[W];Q(Z,X,true);if(W!==0){Z.down=Y[W-1]}if(W!==V-1){Z.up=Y[W+1]}}return Z}function t(V){V.up.down=V.down;V.down.up=V.up;V.up=V.down=null}Q(l,{version:"2.4.13.0",query:P,stack:{},apply:Q,getJSONObject:L,whenReady:D,noConflict:d});l.DomHelper={on:s,un:u,requiresJSON:function(V){if(!r(K,"JSON")){c.write('<script type="text/javascript" src="'+V+'"><\/script>')}}};(function(){var V={};l.Fn={set:function(W,X){V[W]=X},get:function(X,W){var Y=V[X];if(W){delete V[X]}return Y}}}());l.Socket=function(W){var V=A(i(W).concat([{incoming:function(Z,Y){W.onMessage(Z,Y)},callback:function(Y){if(W.onReady){W.onReady(Y)}}}])),X=g(W.remote);this.origin=g(W.remote);this.destroy=function(){V.destroy()};this.postMessage=function(Y){V.outgoing(Y,X)};V.init()};l.Rpc=function(X,W){if(W.local){for(var Z in W.local){if(W.local.hasOwnProperty(Z)){var Y=W.local[Z];if(typeof Y==="function"){W.local[Z]={method:Y}}}}}var V=A(i(X).concat([new l.stack.RpcBehavior(this,W),{callback:function(aa){if(X.onReady){X.onReady(aa)}}}]));this.origin=g(X.remote);this.destroy=function(){V.destroy()};V.init()};l.stack.SameOriginTransport=function(W){var X,Z,Y,V;return(X={outgoing:function(ab,ac,aa){Y(ab);if(aa){aa()}},destroy:function(){if(Z){Z.parentNode.removeChild(Z);Z=null}},onDOMReady:function(){V=g(W.remote);if(W.isHost){Q(W.props,{src:M(W.remote,{xdm_e:m.protocol+"//"+m.host+m.pathname,xdm_c:W.channel,xdm_p:4}),name:R+W.channel+"_provider"});Z=x(W);l.Fn.set(W.channel,function(aa){Y=aa;H(function(){X.up.callback(true)},0);return function(ab){X.up.incoming(ab,V)}})}else{Y=j().Fn.get(W.channel,true)(function(aa){X.up.incoming(aa,V)});H(function(){X.up.callback(true)},0)}},init:function(){D(X.onDOMReady,X)}})};l.stack.FlashTransport=function(Y){var aa,V,Z,ab,W,ac;function ad(af,ae){H(function(){aa.up.incoming(af,ab)},0)}function X(ah){var ae=Y.swf+"?host="+Y.isHost;var ag="easyXDM_swf_"+Math.floor(Math.random()*10000);l.Fn.set("flash_loaded",function(){l.stack.FlashTransport.__swf=W=ac.firstChild;ah()});ac=c.createElement("div");Q(ac.style,{height:"1px",width:"1px",position:"absolute",left:0,top:0});c.body.appendChild(ac);var af="proto="+b.location.protocol+"&domain="+w(b.location.href)+"&port="+e(b.location.href)+"&ns="+F;ac.innerHTML="<object height='1' width='1' type='application/x-shockwave-flash' id='"+ag+"' data='"+ae+"'><param name='allowScriptAccess' value='always'></param><param name='wmode' value='transparent'><param name='movie' value='"+ae+"'></param><param name='flashvars' value='"+af+"'></param><embed type='application/x-shockwave-flash' FlashVars='"+af+"' allowScriptAccess='always' wmode='transparent' src='"+ae+"' height='1' width='1'></embed></object>"}return(aa={outgoing:function(af,ag,ae){W.postMessage(Y.channel,af.toString());if(ae){ae()}},destroy:function(){try{W.destroyChannel(Y.channel)}catch(ae){}W=null;if(V){V.parentNode.removeChild(V);V=null}},onDOMReady:function(){ab=Y.remote;W=l.stack.FlashTransport.__swf;l.Fn.set("flash_"+Y.channel+"_init",function(){H(function(){aa.up.callback(true)})});l.Fn.set("flash_"+Y.channel+"_onMessage",ad);var ae=function(){W.createChannel(Y.channel,Y.secret,g(Y.remote),Y.isHost);if(Y.isHost){Q(Y.props,{src:M(Y.remote,{xdm_e:g(m.href),xdm_c:Y.channel,xdm_p:6,xdm_s:Y.secret}),name:R+Y.channel+"_provider"});V=x(Y)}};if(W){ae()}else{X(ae)}},init:function(){D(aa.onDOMReady,aa)}})};l.stack.PostMessageTransport=function(Y){var aa,ab,W,X;function V(ac){if(ac.origin){return g(ac.origin)}if(ac.uri){return g(ac.uri)}if(ac.domain){return m.protocol+"//"+ac.domain}throw"Unable to retrieve the origin of the event"}function Z(ad){var ac=V(ad);if(ac==X&&ad.data.substring(0,Y.channel.length+1)==Y.channel+" "){aa.up.incoming(ad.data.substring(Y.channel.length+1),ac)}}return(aa={outgoing:function(ad,ae,ac){W.postMessage(Y.channel+" "+ad,ae||X);if(ac){ac()}},destroy:function(){u(K,"message",Z);if(ab){W=null;ab.parentNode.removeChild(ab);ab=null}},onDOMReady:function(){X=g(Y.remote);if(Y.isHost){var ac=function(ad){if(ad.data==Y.channel+"-ready"){W=("postMessage" in ab.contentWindow)?ab.contentWindow:ab.contentWindow.document;u(K,"message",ac);s(K,"message",Z);H(function(){aa.up.callback(true)},0)}};s(K,"message",ac);Q(Y.props,{src:M(Y.remote,{xdm_e:g(m.href),xdm_c:Y.channel,xdm_p:1}),name:R+Y.channel+"_provider"});ab=x(Y)}else{s(K,"message",Z);W=("postMessage" in K.parent)?K.parent:K.parent.document;W.postMessage(Y.channel+"-ready",X);H(function(){aa.up.callback(true)},0)}},init:function(){D(aa.onDOMReady,aa)}})};l.stack.FrameElementTransport=function(W){var X,Z,Y,V;return(X={outgoing:function(ab,ac,aa){Y.call(this,ab);if(aa){aa()}},destroy:function(){if(Z){Z.parentNode.removeChild(Z);Z=null}},onDOMReady:function(){V=g(W.remote);if(W.isHost){Q(W.props,{src:M(W.remote,{xdm_e:g(m.href),xdm_c:W.channel,xdm_p:5}),name:R+W.channel+"_provider"});Z=x(W);Z.fn=function(aa){delete Z.fn;Y=aa;H(function(){X.up.callback(true)},0);return function(ab){X.up.incoming(ab,V)}}}else{if(c.referrer&&g(c.referrer)!=P.xdm_e){K.top.location=P.xdm_e}Y=K.frameElement.fn(function(aa){X.up.incoming(aa,V)});X.up.callback(true)}},init:function(){D(X.onDOMReady,X)}})};l.stack.NameTransport=function(Z){var aa;var ac,ag,Y,ae,af,W,V;function ad(aj){var ai=Z.remoteHelper+(ac?"#_3":"#_2")+Z.channel;ag.contentWindow.sendMessage(aj,ai)}function ab(){if(ac){if(++ae===2||!ac){aa.up.callback(true)}}else{ad("ready");aa.up.callback(true)}}function ah(ai){aa.up.incoming(ai,W)}function X(){if(af){H(function(){af(true)},0)}}return(aa={outgoing:function(aj,ak,ai){af=ai;ad(aj)},destroy:function(){ag.parentNode.removeChild(ag);ag=null;if(ac){Y.parentNode.removeChild(Y);Y=null}},onDOMReady:function(){ac=Z.isHost;ae=0;W=g(Z.remote);Z.local=y(Z.local);if(ac){l.Fn.set(Z.channel,function(aj){if(ac&&aj==="ready"){l.Fn.set(Z.channel,ah);ab()}});V=M(Z.remote,{xdm_e:Z.local,xdm_c:Z.channel,xdm_p:2});Q(Z.props,{src:V+"#"+Z.channel,name:R+Z.channel+"_provider"});Y=x(Z)}else{Z.remoteHelper=Z.remote;l.Fn.set(Z.channel,ah)}ag=x({props:{src:Z.local+"#_4"+Z.channel},onLoad:function ai(){var aj=ag||this;u(aj,"load",ai);l.Fn.set(Z.channel+"_load",X);(function ak(){if(typeof aj.contentWindow.sendMessage=="function"){ab()}else{H(ak,50)}}())}})},init:function(){D(aa.onDOMReady,aa)}})};l.stack.HashTransport=function(X){var aa;var af=this,ad,Y,V,ab,ak,Z,aj;var ae,W;function ai(am){if(!aj){return}var al=X.remote+"#"+(ak++)+"_"+am;((ad||!ae)?aj.contentWindow:aj).location=al}function ac(al){ab=al;aa.up.incoming(ab.substring(ab.indexOf("_")+1),W)}function ah(){if(!Z){return}var al=Z.location.href,an="",am=al.indexOf("#");if(am!=-1){an=al.substring(am)}if(an&&an!=ab){ac(an)}}function ag(){Y=setInterval(ah,V)}return(aa={outgoing:function(al,am){ai(al)},destroy:function(){K.clearInterval(Y);if(ad||!ae){aj.parentNode.removeChild(aj)}aj=null},onDOMReady:function(){ad=X.isHost;V=X.interval;ab="#"+X.channel;ak=0;ae=X.useParent;W=g(X.remote);if(ad){X.props={src:X.remote,name:R+X.channel+"_provider"};if(ae){X.onLoad=function(){Z=K;ag();aa.up.callback(true)}}else{var an=0,al=X.delay/50;(function am(){if(++an>al){throw new Error("Unable to reference listenerwindow")}try{Z=aj.contentWindow.frames[R+X.channel+"_consumer"]}catch(ao){}if(Z){ag();aa.up.callback(true)}else{H(am,50)}}())}aj=x(X)}else{Z=K;ag();if(ae){aj=parent;aa.up.callback(true)}else{Q(X,{props:{src:X.remote+"#"+X.channel+new Date(),name:R+X.channel+"_consumer"},onLoad:function(){aa.up.callback(true)}});aj=x(X)}}},init:function(){D(aa.onDOMReady,aa)}})};l.stack.ReliableBehavior=function(W){var Y,aa;var Z=0,V=0,X="";return(Y={incoming:function(ad,ab){var ac=ad.indexOf("_"),ae=ad.substring(0,ac).split(",");ad=ad.substring(ac+1);if(ae[0]==Z){X="";if(aa){aa(true)}}if(ad.length>0){Y.down.outgoing(ae[1]+","+Z+"_"+X,ab);if(V!=ae[1]){V=ae[1];Y.up.incoming(ad,ab)}}},outgoing:function(ad,ab,ac){X=ad;aa=ac;Y.down.outgoing(V+","+(++Z)+"_"+ad,ab)}})};l.stack.QueueBehavior=function(X){var aa,ab=[],ae=true,Y="",ad,V=0,W=false,Z=false;function ac(){if(X.remove&&ab.length===0){t(aa);return}if(ae||ab.length===0||ad){return}ae=true;var af=ab.shift();aa.down.outgoing(af.data,af.origin,function(ag){ae=false;if(af.callback){H(function(){af.callback(ag)},0)}ac()})}return(aa={init:function(){if(q(X)){X={}}if(X.maxLength){V=X.maxLength;Z=true}if(X.lazy){W=true}else{aa.down.init()}},callback:function(ag){ae=false;var af=aa.up;ac();af.callback(ag)},incoming:function(ai,ag){if(Z){var ah=ai.indexOf("_"),af=parseInt(ai.substring(0,ah),10);Y+=ai.substring(ah+1);if(af===0){if(X.encode){Y=h(Y)}aa.up.incoming(Y,ag);Y=""}}else{aa.up.incoming(ai,ag)}},outgoing:function(aj,ag,ai){if(X.encode){aj=E(aj)}var af=[],ah;if(Z){while(aj.length!==0){ah=aj.substring(0,V);aj=aj.substring(ah.length);af.push(ah)}while((ah=af.shift())){ab.push({data:af.length+"_"+ah,origin:ag,callback:af.length===0?ai:null})}}else{ab.push({data:aj,origin:ag,callback:ai})}if(W){aa.down.init()}else{ac()}},destroy:function(){ad=true;aa.down.destroy()}})};l.stack.VerifyBehavior=function(Z){var aa,Y,W,X=false;function V(){Y=Math.random().toString(16).substring(2);aa.down.outgoing(Y)}return(aa={incoming:function(ad,ab){var ac=ad.indexOf("_");if(ac===-1){if(ad===Y){aa.up.callback(true)}else{if(!W){W=ad;if(!Z.initiate){V()}aa.down.outgoing(ad)}}}else{if(ad.substring(0,ac)===W){aa.up.incoming(ad.substring(ac+1),ab)}}},outgoing:function(ad,ab,ac){aa.down.outgoing(Y+"_"+ad,ab,ac)},callback:function(ab){if(Z.initiate){V()}}})};l.stack.RpcBehavior=function(ab,W){var Y,ad=W.serializer||L();var ac=0,aa={};function V(ae){ae.jsonrpc="2.0";Y.down.outgoing(ad.stringify(ae))}function Z(ae,ag){var af=Array.prototype.slice;return function(){var ah=arguments.length,aj,ai={method:ag};if(ah>0&&typeof arguments[ah-1]==="function"){if(ah>1&&typeof arguments[ah-2]==="function"){aj={success:arguments[ah-2],error:arguments[ah-1]};ai.params=af.call(arguments,0,ah-2)}else{aj={success:arguments[ah-1]};ai.params=af.call(arguments,0,ah-1)}aa[""+(++ac)]=aj;ai.id=ac}else{ai.params=af.call(arguments,0)}if(ae.namedParams&&ai.params.length===1){ai.params=ai.params[0]}V(ai)}}function X(al,ak,ag,aj){if(!ag){if(ak){V({id:ak,error:{code:-32601,message:"Procedure not found."}})}return}var ai,af;if(ak){ai=function(am){ai=n;V({id:ak,result:am})};af=function(am,an){af=n;var ao={id:ak,error:{code:-32099,message:am}};if(an){ao.error.data=an}V(ao)}}else{ai=af=n}if(!o(aj)){aj=[aj]}try{var ae=ag.method.apply(ag.scope,aj.concat([ai,af]));if(!q(ae)){ai(ae)}}catch(ah){af(ah.message)}}return(Y={incoming:function(af,ae){var ag=ad.parse(af);if(ag.method){if(W.handle){W.handle(ag,V)}else{X(ag.method,ag.id,W.local[ag.method],ag.params)}}else{var ah=aa[ag.id];if(ag.error){if(ah.error){ah.error(ag.error)}}else{if(ah.success){ah.success(ag.result)}}delete aa[ag.id]}},init:function(){if(W.remote){for(var ae in W.remote){if(W.remote.hasOwnProperty(ae)){ab[ae]=Z(W.remote[ae],ae)}}}Y.down.init()},destroy:function(){for(var ae in W.remote){if(W.remote.hasOwnProperty(ae)&&ab.hasOwnProperty(ae)){delete ab[ae]}}Y.down.destroy()}})};b.easyXDM=l})(window,document,location,window.setTimeout,decodeURIComponent,encodeURIComponent);(function(){var o=this;var n=o.Backbone;var b;if(typeof exports!=="undefined"){b=exports}else{b=o.Backbone={}}b.VERSION="0.5.1";var w=o._;if(!w&&(typeof require!=="undefined")){w=require("underscore")._}var e=o.jQuery||o.Zepto;b.noConflict=function(){o.Backbone=n;return this};b.emulateHTTP=false;b.emulateJSON=false;b.Events={bind:function(y,A){var x=this._callbacks||(this._callbacks={});var z=x[y]||(x[y]=[]);z.push(A);return this},unbind:function(A,C){var z;if(!A){this._callbacks={}}else{if(z=this._callbacks){if(!C){z[A]=[]}else{var B=z[A];if(!B){return this}for(var y=0,x=B.length;y<x;y++){if(C===B[y]){B[y]=null;break}}}}}return this},trigger:function(z){var A,F,D,E,B;var C=2;if(!(F=this._callbacks)){return this}while(C--){D=C?z:"all";if(A=F[D]){for(var y=0,x=A.length;y<x;y++){if(!(E=A[y])){A.splice(y,1);y--;x--}else{B=C?Array.prototype.slice.call(arguments,1):arguments;E.apply(this,B)}}}}return this}};b.Model=function(x,y){var z;x||(x={});if(z=this.defaults){if(w.isFunction(z)){z=z()}x=w.extend({},z,x)}this.attributes={};this._escapedAttributes={};this.cid=w.uniqueId("c");this.set(x,{silent:true});this._changed=false;this._previousAttributes=w.clone(this.attributes);if(y&&y.collection){this.collection=y.collection}this.initialize(x,y)};w.extend(b.Model.prototype,b.Events,{_previousAttributes:null,_changed:false,idAttribute:"id",initialize:function(){},toJSON:function(){return w.clone(this.attributes)},get:function(x){return this.attributes[x]},escape:function(x){var y;if(y=this._escapedAttributes[x]){return y}var z=this.attributes[x];return this._escapedAttributes[x]=m(z==null?"":""+z)},has:function(x){return this.attributes[x]!=null},set:function(A,z){z||(z={});if(!A){return this}if(A.attributes){A=A.attributes}var y=this.attributes,C=this._escapedAttributes;if(!z.silent&&this.validate&&!this._performValidation(A,z)){return false}if(this.idAttribute in A){this.id=A[this.idAttribute]}var B=this._changing;this._changing=true;for(var x in A){var D=A[x];if(!w.isEqual(y[x],D)){y[x]=D;delete C[x];this._changed=true;if(!z.silent){this.trigger("change:"+x,this,D,z)}}}if(!B&&!z.silent&&this._changed){this.change(z)}this._changing=false;return this},unset:function(x,y){if(!(x in this.attributes)){return this}y||(y={});var A=this.attributes[x];var z={};z[x]=void 0;if(!y.silent&&this.validate&&!this._performValidation(z,y)){return false}delete this.attributes[x];delete this._escapedAttributes[x];if(x==this.idAttribute){delete this.id}this._changed=true;if(!y.silent){this.trigger("change:"+x,this,void 0,y);this.change(y)}return this},clear:function(z){z||(z={});var x;var y=this.attributes;var A={};for(x in y){A[x]=void 0}if(!z.silent&&this.validate&&!this._performValidation(A,z)){return false}this.attributes={};this._escapedAttributes={};this._changed=true;if(!z.silent){for(x in y){this.trigger("change:"+x,this,void 0,z)}this.change(z)}return this},fetch:function(y){y||(y={});var x=this;var z=y.success;y.success=function(C,A,B){if(!x.set(x.parse(C,B),y)){return false}if(z){z(x,C)}};y.error=c(y.error,x,y);return(this.sync||b.sync).call(this,"read",this,y)},save:function(z,y){y||(y={});if(z&&!this.set(z,y)){return false}var x=this;var A=y.success;y.success=function(E,C,D){if(!x.set(x.parse(E,D),y)){return false}if(A){A(x,E,D)}};y.error=c(y.error,x,y);var B=this.isNew()?"create":"update";return(this.sync||b.sync).call(this,B,this,y)},destroy:function(y){y||(y={});if(this.isNew()){return this.trigger("destroy",this,this.collection,y)}var x=this;var z=y.success;y.success=function(A){x.trigger("destroy",x,x.collection,y);if(z){z(x,A)}};y.error=c(y.error,x,y);return(this.sync||b.sync).call(this,"delete",this,y)},url:function(){var x=p(this.collection)||this.urlRoot||r();if(this.isNew()){return x}return x+(x.charAt(x.length-1)=="/"?"":"/")+encodeURIComponent(this.id)},parse:function(y,x){return y},clone:function(){return new this.constructor(this)},isNew:function(){return this.id==null},change:function(x){this.trigger("change",this,x);this._previousAttributes=w.clone(this.attributes);this._changed=false},hasChanged:function(x){if(x){return this._previousAttributes[x]!=this.attributes[x]}return this._changed},changedAttributes:function(z){z||(z=this.attributes);var y=this._previousAttributes;var A=false;for(var x in z){if(!w.isEqual(y[x],z[x])){A=A||{};A[x]=z[x]}}return A},previous:function(x){if(!x||!this._previousAttributes){return null}return this._previousAttributes[x]},previousAttributes:function(){return w.clone(this._previousAttributes)},_performValidation:function(z,y){var x=this.validate(z);if(x){if(y.error){y.error(this,x,y)}else{this.trigger("error",this,x,y)}return false}return true}});b.Collection=function(y,x){x||(x={});if(x.comparator){this.comparator=x.comparator}w.bindAll(this,"_onModelEvent","_removeReference");this._reset();if(y){this.reset(y,{silent:true})}this.initialize.apply(this,arguments)};w.extend(b.Collection.prototype,b.Events,{model:b.Model,initialize:function(){},toJSON:function(){return this.map(function(x){return x.toJSON()})},add:function(A,y){if(w.isArray(A)){for(var z=0,x=A.length;z<x;z++){this._add(A[z],y)}}else{this._add(A,y)}return this},remove:function(A,y){if(w.isArray(A)){for(var z=0,x=A.length;z<x;z++){this._remove(A[z],y)}}else{this._remove(A,y)}return this},get:function(x){if(x==null){return null}return this._byId[x.id!=null?x.id:x]},getByCid:function(x){return x&&this._byCid[x.cid||x]},at:function(x){return this.models[x]},sort:function(x){x||(x={});if(!this.comparator){throw new Error("Cannot sort a set without a comparator")}this.models=this.sortBy(this.comparator);if(!x.silent){this.trigger("reset",this,x)}return this},pluck:function(x){return w.map(this.models,function(y){return y.get(x)})},reset:function(y,x){y||(y=[]);x||(x={});this.each(this._removeReference);this._reset();this.add(y,{silent:true});if(!x.silent){this.trigger("reset",this,x)}return this},fetch:function(x){x||(x={});var z=this;var y=x.success;x.success=function(C,A,B){z[x.add?"add":"reset"](z.parse(C,B),x);if(y){y(z,C)}};x.error=c(x.error,z,x);return(this.sync||b.sync).call(this,"read",this,x)},create:function(y,x){var z=this;x||(x={});y=this._prepareModel(y,x);if(!y){return false}var A=x.success;x.success=function(B,D,C){z.add(B,x);if(A){A(B,D,C)}};y.save(null,x);return y},parse:function(y,x){return y},chain:function(){return w(this.models).chain()},_reset:function(x){this.length=0;w;this.models=[];this._byId={};this._byCid={}},_prepareModel:function(z,y){if(!(z instanceof b.Model)){var x=z;z=new this.model(x,{collection:this});if(z.validate&&!z._performValidation(x,y)){z=false}}else{if(!z.collection){z.collection=this}}return z},_add:function(z,y){y||(y={});z=this._prepareModel(z,y);if(!z){return false}var A=this.getByCid(z)||this.get(z);if(A){A.set(z.attributes);return A}else{this._byId[z.id]=z;this._byCid[z.cid]=z;var x=y.at!=null?y.at:this.comparator?this.sortedIndex(z,this.comparator):this.length;this.models.splice(x,0,z);z.bind("all",this._onModelEvent);this.length++;if(!y.silent){z.trigger("add",z,this,y)}return z}},_remove:function(y,x){x||(x={});y=this.getByCid(y)||this.get(y);if(!y){return null}delete this._byId[y.id];delete this._byCid[y.cid];this.models.splice(this.indexOf(y),1);this.length--;if(!x.silent){y.trigger("remove",y,this,x)}this._removeReference(y);return y},_removeReference:function(x){if(this==x.collection){delete x.collection}x.unbind("all",this._onModelEvent)},_onModelEvent:function(z,y,A,x){if((z=="add"||z=="remove")&&A!=this){return}if(z=="destroy"){this._remove(y,x)}if(y&&z==="change:"+y.idAttribute){delete this._byId[y.previous(y.idAttribute)];this._byId[y.id]=y}this.trigger.apply(this,arguments)}});var u=["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"];w.each(u,function(x){b.Collection.prototype[x]=function(){return w[x].apply(w,[this.models].concat(w.toArray(arguments)))}});b.Router=function(x){x||(x={});if(x.routes){this.routes=x.routes}this._bindRoutes();this.initialize.apply(this,arguments)};var g=/:([\w\d]+)/g;var v=/\*([\w\d]+)/g;var d=/[-[\]{}()+?.,\\^$|#\s]/g;w.extend(b.Router.prototype,b.Events,{initialize:function(){},route:function(x,y,z){b.history||(b.history=new b.History);if(!w.isRegExp(x)){x=this._routeToRegExp(x)}b.history.route(x,w.bind(function(B){var A=this._extractParameters(x,B);z.apply(this,A);this.trigger.apply(this,["route:"+y].concat(A))},this))},navigate:function(x,y){b.history.navigate(x,y)},_bindRoutes:function(){if(!this.routes){return}var y=[];for(var z in this.routes){y.unshift([z,this.routes[z]])}for(var A=0,x=y.length;A<x;A++){this.route(y[A][0],y[A][1],this[y[A][1]])}},_routeToRegExp:function(x){x=x.replace(d,"\\$&").replace(g,"([^/]*)").replace(v,"(.*?)");return new RegExp("^"+x+"$")},_extractParameters:function(x,y){return x.exec(y).slice(1)}});b.History=function(){this.handlers=[];w.bindAll(this,"checkUrl")};var l=/^#*/;var h=/msie [\w.]+/;var j=false;w.extend(b.History.prototype,{interval:50,getFragment:function(y,x){if(y==null){if(this._hasPushState||x){y=window.location.pathname;var z=window.location.search;if(z){y+=z}if(y.indexOf(this.options.root)==0){y=y.substr(this.options.root.length)}}else{y=window.location.hash}}return y.replace(l,"")},start:function(z){if(j){throw new Error("Backbone.history has already been started")}this.options=w.extend({},{root:"/"},this.options,z);this._wantsPushState=!!this.options.pushState;this._hasPushState=!!(this.options.pushState&&window.history&&window.history.pushState);var y=this.getFragment();var x=document.documentMode;var B=(h.exec(navigator.userAgent.toLowerCase())&&(!x||x<=7));if(B){this.iframe=e('<iframe src="javascript:0" tabindex="-1" />').hide().appendTo("body")[0].contentWindow;this.navigate(y)}if(this._hasPushState){e(window).bind("popstate",this.checkUrl)}else{if("onhashchange" in window&&!B){e(window).bind("hashchange",this.checkUrl)}else{setInterval(this.checkUrl,this.interval)}}this.fragment=y;j=true;var C=window.location;var A=C.pathname==this.options.root;if(this._wantsPushState&&!this._hasPushState&&!A){this.fragment=this.getFragment(null,true);window.location.replace(this.options.root+"#"+this.fragment)}else{if(this._wantsPushState&&this._hasPushState&&A&&C.hash){this.fragment=C.hash.replace(l,"");window.history.replaceState({},document.title,C.protocol+"//"+C.host+this.options.root+this.fragment)}}return this.loadUrl()},route:function(x,y){this.handlers.unshift({route:x,callback:y})},checkUrl:function(y){var x=this.getFragment();if(x==this.fragment&&this.iframe){x=this.getFragment(this.iframe.location.hash)}if(x==this.fragment||x==decodeURIComponent(this.fragment)){return false}if(this.iframe){this.navigate(x)}this.loadUrl()||this.loadUrl(window.location.hash)},loadUrl:function(z){var y=this.fragment=this.getFragment(z);var x=w.any(this.handlers,function(A){if(A.route.test(y)){A.callback(y);return true}});return x},navigate:function(x,y){var A=(x||"").replace(l,"");if(this.fragment==A||this.fragment==decodeURIComponent(A)){return}if(this._hasPushState){var z=window.location;if(A.indexOf(this.options.root)!=0){A=this.options.root+A}this.fragment=A;window.history.pushState({},document.title,z.protocol+"//"+z.host+A)}else{window.location.hash=this.fragment=A;if(this.iframe&&(A!=this.getFragment(this.iframe.location.hash))){this.iframe.document.open().close();this.iframe.location.hash=A}}if(y){this.loadUrl(x)}}});b.View=function(x){this.cid=w.uniqueId("view");this._configure(x||{});this._ensureElement();this.delegateEvents();this.initialize.apply(this,arguments)};var k=function(x){return e(x,this.el)};var a=/^(\S+)\s*(.*)$/;var s=["model","collection","el","id","attributes","className","tagName"];w.extend(b.View.prototype,b.Events,{tagName:"div",$:k,initialize:function(){},render:function(){return this},remove:function(){e(this.el).remove();return this},make:function(y,x,A){var z=document.createElement(y);if(x){e(z).attr(x)}if(A){e(z).html(A)}return z},delegateEvents:function(B){if(!(B||(B=this.events))){return}e(this.el).unbind(".delegateEvents"+this.cid);for(var A in B){var C=this[B[A]];if(!C){throw new Error('Event "'+B[A]+'" does not exist')}var z=A.match(a);var y=z[1],x=z[2];C=w.bind(C,this);y+=".delegateEvents"+this.cid;if(x===""){e(this.el).bind(y,C)}else{e(this.el).delegate(x,y,C)}}},_configure:function(z){if(this.options){z=w.extend({},this.options,z)}for(var A=0,y=s.length;A<y;A++){var x=s[A];if(z[x]){this[x]=z[x]}}this.options=z},_ensureElement:function(){if(!this.el){var x=this.attributes||{};if(this.id){x.id=this.id}if(this.className){x["class"]=this.className}this.el=this.make(this.tagName,x)}else{if(w.isString(this.el)){this.el=e(this.el).get(0)}}}});var t=function(x,y){var z=i(this,x,y);z.extend=this.extend;return z};b.Model.extend=b.Collection.extend=b.Router.extend=b.View.extend=t;var q={create:"POST",update:"PUT","delete":"DELETE",read:"GET"};b.sync=function(B,y,x){var z=q[B];var A=w.extend({type:z,dataType:"json",processData:false},x);if(!A.url){A.url=p(y)||r()}if(!A.data&&y&&(B=="create"||B=="update")){A.contentType="application/json";A.data=JSON.stringify(y.toJSON())}if(b.emulateJSON){A.contentType="application/x-www-form-urlencoded";A.processData=true;A.data=A.data?{model:A.data}:{}}if(b.emulateHTTP){if(z==="PUT"||z==="DELETE"){if(b.emulateJSON){A.data._method=z}A.type="POST";A.beforeSend=function(C){C.setRequestHeader("X-HTTP-Method-Override",z)}}}return e.ajax(A)};var f=function(){};var i=function(y,x,z){var A;if(x&&x.hasOwnProperty("constructor")){A=x.constructor}else{A=function(){return y.apply(this,arguments)}}w.extend(A,y);f.prototype=y.prototype;A.prototype=new f();if(x){w.extend(A.prototype,x)}if(z){w.extend(A,z)}A.prototype.constructor=A;A.__super__=y.prototype;return A};var p=function(x){if(!(x&&x.url)){return null}return w.isFunction(x.url)?x.url():x.url};var r=function(){throw new Error('A "url" property or function must be specified')};var c=function(z,y,x){return function(A){if(z){z(y,A,x)}else{y.trigger("error",y,A,x)}}};var m=function(x){return x.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);(function(){var a=function(b,c){return function(){return b.apply(c,arguments)}};window.Backbone.Rails={popRootKey:function(b){return _.first(_.values(b))},popRootKeys:function(b){if(!_.isArray(b)){b=[b]}return _.map(b,a(function(c){return this.popRootKey(c)},this))},rootKey:function(b,c){var d;d={};d[b]=c;return d},model_type:function(b){return _.first(_.keys(b))},pluralize:function(c,b){if(c===1){return b}else{return b+"s"}}}}).call(this);$(function(){window.Poll=Backbone.Model.extend({defaults:{group_id:null,owner_id:null,sharing_enabled:true,web_enabled:true},modelProperties:["sequence","title","group_id","state","sms_enabled","web_enabled","sharing_enabled","twitter_enabled"],resequence:false,initialize:function(){_.bindAll(this,"start","stop","url","group","moveToGroup","cleanTitle","clear","toggleState","toggleSharingEnabled","toggleWebEnabled","toggleSmsEnabled","toggleTwitterEnabled","toggle","refreshArchives","isWebRespondable","isWebRespondableFor","hasMaximumResponses","changeType");this.archives=new ArchiveCollection;this.archives.url="/my/polls/"+this.get("permalink")+"/archives"},parse:function(a){return Backbone.Rails.popRootKey(a)},start:function(a){this.toggle("state",a,"opened")},stop:function(a){this.toggle("state",a,"closed")},toggleState:function(a){var b=this.get("state")==="opened"?"closed":"opened";return this.toggle("state",a,b)},toggleTwitterEnabled:function(a){return this.toggle("twitter_enabled",a)},toggleSmsEnabled:function(a){return this.toggle("sms_enabled",a)},toggleSharingEnabled:function(a){return this.toggle("sharing_enabled",a)},toggleWebEnabled:function(a){return this.toggle("web_enabled",a)},toggle:function(a,b,d){var c={};c[a]=(d?d:!this.get(a));b||(b={});b.data||(b.data={});b.data[this.model_type]=c;b.processData=true;return this.save(c,b)},isWebRespondable:function(){return this.get("state")==="opened"&&this.get("web_enabled")},votingInstructions:function(a){var e="";if(this.isStopped()){e="This poll hasn't been started yet."}else{if(!this.isWebEnabled()){e="Web Voting has not been turned on for this poll."}else{if(!this.isRegisteredFor(a)){e="This poll requires you to be registered with the presenter. See the presenter to find out how to get registered."}else{if(this.get("max_votes")){var b=a.resultsForPoll(this,false).size(),d=this.get("max_votes"),c=d-b;if(b===0){e="You can respond "+d+" "+Backbone.Rails.pluralize(d,"time")}else{if(b>=d){e="You responded the maximum number of times to this poll"}else{e="You have "+c+" "+Backbone.Rails.pluralize(c,"response")+" remaining"}}}}}}return e},isStopped:function(){return this.get("state")==="closed"},isWebEnabled:function(){return this.get("web_enabled")},isSharingEnabled:function(){return this.get("sharing_enabled")},isWebRespondableFor:function(a){return !this.hasMaximumResponses(a)&&this.isWebRespondable()},isRegisteredFor:function(a){if(this.get("registered_participants_only")===true){var b=a.get("membership_ids");if(b===null){b=new Array()}if($.inArray(this.get("account_id"),b)>-1){return true}else{return false}}else{return true}},hasMaximumResponses:function(a){if(this.get("max_votes")){return a.resultsForPoll(this,false).size()>=this.get("max_votes")}else{return false}},url:function(){var a="/"+this.pluralize(this.model_type);return this.isNew()?a:a+"/"+this.get("permalink")},resultsUrl:function(){return"/polls/"+this.get("permalink")+"/results"},editUrl:function(){return"/"+this.pluralize(this.model_type)+"/"+this.get("permalink")+"/edit"},copyUrl:function(){return"/"+this.pluralize(this.model_type)+"/"+this.get("permalink")+"/copy"},clearUrl:function(){return"/"+this.pluralize(this.model_type)+"/"+this.get("permalink")+"/clear"},pluralize:function(a){return a+"s"},toJSON:function(){var a={};a[this.model_type]={};_.each(this.modelProperties,function(b){a[this.model_type][b]=this.attributes[b]},this);if(a[this.model_type]["group_id"]==Group.defaultId){a[this.model_type]["group_id"]=null}if(this.resequence){a.resequence=this.resequence}return a},group:function(){return window.PollEverywhere.Groups.get(this.get("group_id"))||this.owner().ungroup},owner:function(){return window.PollEverywhere.Users.get(this.get("owner_id"))},moveToGroup:function(a){this.set({group_id:a.id})},cleanTitle:function(){return this.get("title")?this.get("title").replace(/\\n/i,""):""},clear:function(b){var a=this;var c=b.success;b.success=function(f,d,e){if(!a.set(a.parse(f,e),b)){return false}if(c){c(a,f,e)}};b.url=this.clearUrl();Backbone.sync("delete",this,b)},refreshArchives:function(){if(this.archives.models.length>0){_.each(this.archives.pluck("id"),function(a){this.archives.remove(this.archives.get(a))},this)}this.archives.fetch()}},{factory:function(c){if(!c){return}var b=Backbone.Rails.popRootKey(c),a=Backbone.Rails.model_type(c);switch(a){case"multiple_choice_poll":return new MultipleChoicePoll(b);break;case"free_text_poll":return new FreeTextPoll(b);break;case"pledge_poll":return new PledgePoll(b);break}},parseFromText:function(b){var a={multiple_choice_poll:{expression:/^(.+[\:\?\.])(.+)$/,constructor:function(e,c){var f=function(g){if((c=g.split(","))&&c.length>1){c=_(c).map(function(h){return $.trim(h)});c[c.length-1]=c[c.length-1].replace(/^or|and/i,"").replace(/\?/,"");return _(c).map(function(h){return{value:$.trim(h)}})}else{if((c=g.split(/or|and|\/|\|/))&&c.length===2){c=_(c).map(function(h){return $.trim(h)});c[c.length-1]=c[c.length-1].replace(/\?/,"");return _(c).map(function(h){return{value:h}})}else{return{value:$.trim(g)}}}};var d=function(g){return $.trim(g).replace(/\:$/,"")};poll=new MultipleChoicePoll({title:d(e)});poll.options.add(f(c));return poll}},free_text_poll:{expression:/^(.+)$/m,constructor:function(c){return new FreeTextPoll({title:c})}}};parsed=_.detect(a,function(d,c){if(d.captures=$.trim(b).match(d.expression)){return d}});if(parsed){return parsed.constructor.apply(this,parsed.captures.slice(1,parsed.captures.length))}}})});$(function(){window.User=Backbone.Model.extend({url:"/profile",initialize:function(a){_.bind(this,"bindCurrentPoll","unbindCurrentPoll","currentPollUrl","setCurentPoll","getCurentPoll","currentPollPath","pollEvPageAvailable","toJSON","isAdmin","isOwner","fullName","owns","groups","results","resultsForPoll");this.model_type="user";if(a.current_poll){this.setCurrentPoll(Poll.factory(a.current_poll))}this.ungroup=new Group({id:null,name:"Ungrouped",owner_id:this.id})},validate:function(a){if(a.login){if((/^\s*$/).test(a.login)){return"can't be blank"}else{if(!(/^[a-z0-9\_]+$/i).test(a.login)){return"can only contain letters, numbers, and underscores"}else{if(false){return"taken"}}}}},parse:function(a){return Backbone.Rails.popRootKey(a)},toJSON:function(){var a=Backbone.Rails.rootKey(this.model_type,this.attributes);delete a.user.created_within_last_week;delete a.user.is_psu;delete a.user.alone_on_big_account;return a},fullName:function(){return this.get("first_name")+" "+this.get("last_name")},groups:function(){var a=window.PollEverywhere.Groups.select(function(b){return this.owns(b)},this);a.unshift(this.ungroup);return _(a)},polls:function(){return _(window.PollEverywhere.Polls.select(function(a){return this.id==a.get("owner_id")},this))},results:function(a){a=(a||false);return _(PollEverywhere.Results.select(function(b){if(a){return b.get("voter_id")===this.id}else{return b.get("voter_id")===this.id&&!b.isArchived()}},this))},resultsForPoll:function(b,a){a=(a||false);return _(PollEverywhere.Results.select(function(c){if(a){return c.get("voter_id")===this.id&&c.get("poll_id")===b.id}else{return c.get("voter_id")===this.id&&c.get("poll_id")===b.id&&!c.isArchived()}},this))},answeredPolls:function(){return _.map(_.uniq(this.results().pluck("get","poll_id")),function(a){PollEverywhere.Polls.get(a)})},pollEvPageAvailable:_.debounce(function(){var a=this.get("login");$.ajax({url:"/"+a,type:"GET",success:_.bind(function(){this.trigger("pollev_page:taken",a)},this),error:_.bind(function(b){if(b.status===404){this.trigger("pollev_page:available",a)}},this)})},350),bindCurrentPoll:function(){var d=this,i=0,g=5000,f=0,n,j=5000,k=(($.meta("stream.long_poll.timeout")*1000)+j),h=(function(o){matches=o.match(/(.+\:\/\/[^\/]+)(\/.+)?/);return{url:o,host:matches[1],path:matches[2]}})($.meta("stream.long_poll.url")),l=(h.url+"/_xdr_proxy"),e=function(o){var p;return function(q){if(q!==p){p=q;o(q)}}},a=e(function(o){d.trigger(o)}),m=new easyXDM.Rpc({remote:l},{remote:{request:{}}}),c=function(p){var o={delay:0,sid:$.meta("sid")};$.extend(o,(p||{}));setTimeout(function(){f++;m.request({method:"GET",url:h.path?(h.path+d.currentPollPath()):d.currentPollPath(),data:{sid:o.sid,t:f},timeout:k},function(q){a("connection:connected");if(q.status===204){c({delay:i})}else{var r=q.data?Poll.factory(JSON.parse(q.data)):q.data;d.setCurrentPoll(r);c({delay:i})}},function(q){clearTimeout(n);a("connection:disconnected");n=setTimeout(function(){a("connection:connected")},g+j);c({delay:g})})},o.delay)};var b=function(v,o){var s={timeout:3000,interval:250,died:v,heartbeat:function(){}};$.extend(s,(o||{}));var x,r=0,u=false,p=function(){return new Date()},y=function(){return x=p()},w=function(){return(p().getTime()-x.getTime())>s.timeout},t=function(){y();q()},q=function(){r++;s.heartbeat(r);if(w()){s.died({live:t})}else{y();setTimeout(q,s.interval)}};$(document).bind("touchmove",function(z){y()});t()};c({delay:0});b(function(o){a("connection:disconnected");$.getJSON("/users/"+d.get("id")+".json",function(p){if(p.current_poll){d.setCurrentPoll(Poll.factory(p.current_poll))}a("connection:connected");c({delay:0});o.live()})})},setCurrentPoll:function(b){PollEverywhere.Polls.add(b);var a=PollEverywhere.Polls.get(b);if(a.get("max_votes")&&a.get("results_count")===0){PollEverywhere.Results.archive(a)}if(!this._currentPoll||(this._currentPoll.id!==b.id)){this._currentPoll=a;this.trigger("change:current_poll",this._currentPoll)}return this._currentPoll},getCurrentPoll:function(){return this._currentPoll},currentPollPath:function(){return"/users/"+this.get("id")+"/polls/current.json"},currentPollUrl:function(){return $.meta("stream.long_poll.url")+currentPollPath()},isOwner:function(){return this.account_relationship===2},isAdmin:function(){return this.account_relationship===1},isPsu:function(){return true},isCurrentUser:function(){return PollEverywhere.CurrentUser?PollEverywhere.CurrentUser.id===this.id:false},isCreatedWithinLastWeek:function(){return this.get("created_within_last_week")===true},isAloneOnBigAccount:function(){return this.get("alone_on_big_account")===true},owns:function(b){var a=b.get("owner_id")||b.get("user_id");return a===this.get("id")}})});$(function(){window.UserCollection=Backbone.Collection.extend({model:User,comparator:function(a){return a.fullName()},any:function(){return this.length>0},parse:function(a){return UserCollection.parse(a)}},{parse:function(a){return Backbone.Rails.popRootKeys(a)}})});$(function(){window.Result=Backbone.Model.extend({initialize:function(a){_.bindAll(this,"parse","poll","isArchived")},parse:function(a){return Backbone.Rails.popRootKey(a)},toJSON:function(){return{result:this.attributes}},poll:function(){return PollEverywhere.Polls.get(this.get("poll_id"))},isArchived:function(){return this.get("archive_id")||false}})});$(function(){window.ResultCollection=Backbone.Collection.extend({model:Result,url:"/my/results",initialize:function(){_.bindAll(this,"forPoll")},parse:function(a){return ResultCollection.parse(a)},forPoll:function(b,a){a=(a||false);return this.select(function(c){if(a){return c.get("poll_id")===b.id}else{return c.get("poll_id")===b.id&&!c.isArchived()}})},archive:function(b){var a=[];_(this.forPoll(b)).each(function(c){a.push(c.id);c.set({archive_id:-1},{silent:true})});PollEverywhere.Results.fetch({data:"result_id="+a.join(","),processData:false});b.trigger("archive")},fetchSet:function(b,a){a||(a={});a.url=this.url+"/"+_.flatten([b]).join("/");a.processData=true;a.add=true;this.fetch(a)}},{parse:function(a){return Backbone.Rails.popRootKeys(a)}})});$(function(){window.Archive=Backbone.Model.extend({defaults:{current:false},initialize:function(){_.bindAll(this,"toJSON","url")},parse:function(a){return Archive.parse(a)},toJSON:function(){var a={};a.archive={};a.archive["name"]=this.get("name");return a}},{parse:function(a){return _.first(_.values(a))},type:function(a){return _.first(_.keys(a))}})});$(function(){window.ArchiveCollection=Backbone.Collection.extend({model:Archive,parse:function(a){return _.flatten(_.map(a,function(b){return _.values(b)}))},initialize:function(){_.bindAll(this,"comparator");this.bind("reset",function(){var a=new Archive({id:0,name:"Current Run"});this.add(a,{silent:true})})},comparator:function(a){if(a.get("id")==0){return -(_.max(this.pluck("unix_time"))+1000)}else{return -a.get("unix_time")}}})});$(function(){window.Group=Backbone.Model.extend({defaults:{id:null,name:"New Group"},initialize:function(){_.bindAll(this,"toJSON","addPolls","toggleCollapse","isRealGroup")},polls:function(){return _(window.PollEverywhere.Polls.select(function(a){return this.owner().owns(a)&&a.get("group_id")==this.id},this))},toJSON:function(){return{group:this.attributes}},parse:function(a){return _.first(_.values(a))},addPolls:function(a){a.each(function(b){b.moveToGroup(this)},this)},toggleCollapse:function(){this.set({collapsed:!this.get("collapsed")});if(this.isRealGroup()&&this.owner().isCurrentUser()){this.save()}},expand:function(){$(this.el).removeClass("collapsed").addClass("expanded")},owner:function(){return window.PollEverywhere.Users.get(this.get("owner_id"))},inSession:function(){return !!this.get("keyword")},validate:function(a){if(a.name!=undefined&&a.name.length===0){return"Group name cannot be empty."}if(a.keyword&&!a.keyword.match(/^[A-Z0-9]{1,15}$/i)){return"Group keyword may contain up to 15 numbers and letters."}},isRealGroup:function(){return this.id!=Group.defaultId}},{defaultId:null})});$(function(){window.PollCollection=Backbone.Collection.extend({model:Poll,url:"/my/polls",initialize:function(a){_.bindAll(this,"bulkAction","bulkDelete","next","previous");this.bind("bulk:start",this.bulkStart);this.bind("bulk:stop",this.bulkStop);this.bind("bulk:delete",this.bulkDelete);if(slideDomain=$.meta("slides.domain")){this.slides.domain=slideDomain}},comparator:function(a){return a.get("sequence")},search:function(b){var a=new RegExp(b,"i");return this.filter(function(c){return a.test(c.get("title"))})},parse:function(a){return PollCollection.parse(a)},findByPermalink:function(a){return this.find(function(b){return b.get("permalink")===a})},next:function(a){return this.at(this.indexOf(a)+1)},previous:function(a){return this.at(this.indexOf(a)-1)},group:function(a,b){_.each(a,function(c){c.moveToGroup(b)})},forGroup:function(a){return this.filter(function(b){return b.get("group_id")===a})},findByField:function(b,a){return this.filter(function(c){return c.get(b)===a})},ungroup:function(a){$.ajax({url:"/my/groups/ungroup_polls",type:"post",dataType:"json",data:{permalinks:a.map(function(b){return b.get("permalink")})},success:function(){a.each(function(b){b.moveToGroup(b.owner().ungroup)})}})},bulkAction:function(d,c,b){var a={};_.extend(a,{url:"/my/polls/bulk?operation="+d,data:{id:c.pluck("id").join(",")},dataType:"json",type:"post"},b,{success:_.wrap(b.success,_.bind(function(f,e){_.each(e,function(h){var g=Backbone.Rails.popRootKey(h);window.PollEverywhere.Polls.get(g.id).set(g)});if(f){f(e)}},this))});if(!a.silent){this.trigger("bulk",c);this.trigger("bulk:"+d,c)}$.ajax(a)},bulkDelete:function(a){this.remove(a)},bulkStart:function(a){a.each(function(b){b.set({state:"opened"})})},bulkStop:function(a){a.each(function(b){b.set({state:"closed"})})},slides:(function(){var c=function(g){return g+"s"};var b=function(i){var h=40;var g="...";return(i.length>h)?(i.slice(0,40)+g):i};var d=function(g){return g.reduce(function(h,j){var i={};i[j.get("permalink")]={q:b(j.get("title")),t:c(j.model_type)};h.push(i);return h},[])};var a=function(g,i,h){return $('<form method="post"></form>').attr("action",g).html($('<input type="hidden" name="polls"></input>').attr("value",JSON.stringify(h))).append($('<input type="hidden" name="domain"></input>').attr("value",i))};var f=function(g,i,h){$(a(g,i,h)).appendTo($("body")).submit().remove()};var e=function(i,j,h){var g="http://ppt.polleverywhere.com/slideshow."+j;f(g,h,d(i))};return{domain:"www.polleverywhere.com",downloadKeynote:function(i){var h=_.map(i.filter(function(j){return j.get("type")==="MultipleChoicePoll"}),function(j){return j.get("permalink")});var g="http://macslides.polleverywhere.com/multiple_choice_polls/"+h.join(",")+".key";window.location.href=g},downloadPowerPoint:function(g){e(g,"pptx",this.domain)},downloadLegacyPowerPoint:function(g){e(g,"ppt",this.domain)}}})()},{parse:function(a){return _.map(a,function(b){return Poll.factory(b)})}})});$(function(){window.GroupCollection=Backbone.Collection.extend({model:Group,url:"/my/groups",states:{},initialize:function(a){_.bindAll(this,"createWithPolls","toggleCollapsed","saveStates");a=(a?a:{})},search:function(b){var a=new RegExp(b,"i");return this.filter(function(c){return a.test(c.get("name"))})},parse:function(a){return GroupCollection.parse(a)},comparator:function(a){return a.get("id")},createWithPolls:function(c,b){var d=new Group,a={group:d.attributes,permalinks:c.map(function(f){return f.get("permalink")}).join(",")},b=(b?b:{}),e=(b.success||function(){});$.ajax(_.extend(b,{url:this.url,type:"post",dataType:"json",data:a,success:_.wrap(e,_.bind(function(f,g){window.PollEverywhere.Groups.add(d.set(d.parse(g)));d.addPolls(c);f&&f.call()},this))}))},saveStates:function(a){if(a){return}this.states=_.inject(this.models,function(b,c){b[c.cid]=!!c.get("collapsed");return b},{})},toggleCollapsed:function(a){_(this.models).each(function(b){if(a){b.expand()}else{}})}},{parse:function(a){return _.flatten(_.map(a,function(b){return _.values(b)}))}})});$(function(){window.MCPOption=Backbone.Model.extend({initialize:function(a){_.bindAll(this,"respond","toJSON")},respond:function(b){var c=this.collection.poll,a=new Result({value:this.get("value"),poll_id:c.id,voter_id:b.id});$.ajax({type:"post",url:"/multiple_choice_polls/"+c.get("permalink")+"/options/"+this.id+"/results",success:_.bind(function(d){a.set(Backbone.Rails.popRootKey(d))},this),error:_.bind(function(d,f,e){alert("Error processing your response.")},this),dataType:"json"});PollEverywhere.Results.add(a);return a}});window.MCPOptions=Backbone.Collection.extend({model:MCPOption});window.MultipleChoicePoll=Poll.extend({initialize:function(a){Poll.prototype.initialize.call(this,a);_.bindAll(this,"toJSON","updateOptions");this.model_type="multiple_choice_poll";this.options=new MCPOptions(this.attributes.options);this.options.poll=this;this.bind("change:options",this.updateOptions)},updateOptions:function(){this.options.reset(this.attributes.options)},toJSON:function(){var a=Poll.prototype.toJSON.call(this);a[this.model_type].options=this.options.invoke("toJSON");return a},parse:function(a){a=Backbone.Rails.popRootKey(a);if(a.options){this.options.reset(a.options)}return a},clone:function(){return new this.constructor(Backbone.Rails.popRootKey(this.toJSON()))}})});$(function(){window.FreeTextPoll=Poll.extend({initialize:function(a){Poll.prototype.initialize.call(this,a);this.model_type="free_text_poll";_.bindAll(this,"respond","changeType")},respond:function(c,b){var a=new Result({poll_id:this.id,voter_id:b.id});a.save({value:c},{url:"/free_text_polls/"+this.get("permalink")+"/results",success:function(d){a.set(Backbone.Rails.popRootKey(d))}});PollEverywhere.Results.add(a);return a},changeType:function(a){if(a=="multiple_choice_poll"&&!this.options){this.options=new MCPOptions;this.options.poll=this}this.model_type=a}})});$(function(){window.PledgePoll=Poll.extend({initialize:function(a){Poll.prototype.initialize.call(this,a);this.model_type="pledge_poll"}})});(function(b){var a={init:function(c){var d={valueField:"id",placeholderText:"Find by poll or group name"};var e=function(h){var g=h.get("title");var f=h.group();if(!_.isUndefined(f)&&f.isRealGroup()){g="<div class='group'>"+f.get("name")+"</div>"+g}return g};b.extend(d,c);return this.each(function(){var i=b(this);var k=b("<div>").addClass("poll_selector_options").appendTo("body");var h=b("<input>").addClass("name").attr({name:d.valueField+"_input",type:"text",placeholder:d.placeholderText}).appendTo(i).autocomplete({appendTo:k,minLength:3,html:true,position:{offset:"0 2"},source:function(o,n){var p=[];var l=d.groups.search(o.term);p=p.concat(d.polls.search(o.term));_.each(d.groups.search(o.term),function(q){_.each(d.polls.forGroup(q.id),function(r){p.push(r)})});var m=[];_.each(_.uniq(p),function(q){m.push({value:q.get(d.valueField),label:e(q),title:q.get("title")})});n(m)},select:function(o,p){var r=p.item.label,n=b("<div>").addClass("option"),m=b("<a>").addClass("remove").attr({href:"javascript:",title:"Remove "+r}).text("x").appendTo(n),q=b("<div>").addClass("title").html(r).appendTo(n),l=b("<input>").attr({name:d.fieldName,value:p.item.value,type:"hidden",id:d.fieldName}).appendTo(n);n.insertBefore(b(this));b(this).hide()},focus:function(l,m){b(this).val(m.item.title);l.preventDefault()}});i.find(".option .remove").live("click",function(){b(this).parent().remove();b(h).val("").show();i.find("input.name").trigger("autocompleteremove")});i.find("input.name").live("blur",function(){b(this).val("")});if(d.selectedValue){var f=d.polls.findByField(d.valueField,d.selectedValue);if(f.length>0){var j=f[0];var g={value:j.get(d.valueField),label:e(j),title:j.get("title")};h.data("autocomplete")._trigger("select",null,{item:g})}}})}};b.fn.pollAutocomplete=function(c){if(a[c]){return a[c].apply(this,Array.prototype.slice.call(arguments,1))}else{if(typeof c==="object"||!c){return a.init.apply(this,arguments)}else{b.error("Method "+c+" does not exist on jQuery.pollAutocomplete")}}}})(jQuery);$(function(){window.PollEverywhereApp=function(b){var a={initialize:function(c){this.polls=c.polls||new PollCollection();this.groups=c.groups||new GroupCollection();this.users=c.users||new UserCollection();this.results=c.results||new ResultCollection();this.currentUser=c.currentUser;_.bindAll(this,"syncCurrentUser");this.users.bind("reset",this.syncCurrentUser);this.syncCurrentUser()},syncCurrentUser:function(){if(this.currentUser&&this.users.get(this.currentUser.id)==null){this.users.add(this.currentUser)}else{if(this.currentUser){this.currentUser=this.users.get(this.currentUser.id)}}}};$.extend(this,a);this.initialize(b);return{Polls:this.polls,Groups:this.groups,Users:this.users,CurrentUser:this.currentUser,Results:this.results,Router:{},View:{},Model:{},Collection:{}}}});
