
var EventManagerImpl=function(){
}
EventManagerImpl.prototype.handlerTable=new Object();
EventManagerImpl.prototype.fireEvent=function(name,arg){
if(this.handlerTable[name]==null){
return;
}
var handlers=this.handlerTable[name];
for(var i=0;i<handlers.length;i++){
handlers[i](arg);
}
}
EventManagerImpl.prototype.addHandler=function(name,fn){
if(this.handlerTable[name]==null){
this.handlerTable[name]=new Array();
}
this.handlerTable[name].push(fn);
return fn;
}
EventManagerImpl.prototype.removeHandler=function(name,fn){
if(this.handlerTable[name]==null){
return false;
}
var index=this.handlerTable[name].indexOf(fn);
if(index==-1){
return false;
}
this.handlerTable[name].splice(index,1);
return true;
}
yt.EventManager=new EventManagerImpl();
var EventManager=yt.EventManager;
(function(){var aa=navigator,i=Error,m=undefined,o=String,p=Object,q=Array;function r(a,b){return a.length=b}function t(a,b){return a.currentTarget=b}function ba(a,b){return a.target=b}function ca(a,b){return a.keyCode=b}function u(a,b){return a.type=b}var v="length",_P="prototype",w="message",da="hasOwnProperty",ea="capture",fa="keyCode",x="type",ga="fileName",ha=ha||{},y=this;var ia=function(a,b){var c=a.split("."),d=y,e;if(!(c[0]in d)&&d.execScript)d.execScript("var "+c[0]);while(e=c.shift())if(!c[v]&&typeof b!=
"undefined")d[e]=b;else d=d[e]?d[e]:(d[e]={})},ja=function(a){var b=a.split("."),c=y;for(var d;d=b.shift();)if(c[d])c=c[d];else return null;return c},ka=function(){};var z=function(a){var b=typeof a;if(b=="object")if(a){if(typeof a[v]=="number"&&typeof a.splice!="undefined"&&!la(a,"length"))return"array";if(typeof a.call!="undefined")return"function"}else return"null";else if(b=="function"&&typeof a.call=="undefined")return"object";return b};if(p[_P].propertyIsEnumerable)var la=function(a,b){return p[_P].propertyIsEnumerable.call(a,
b)};else la=function(a,b){if(b in a)for(var c in a)if(c==b)return true;return false};var ma=function(a){return z(a)=="array"},na=function(a){var b=z(a);return b=="array"||b=="object"&&typeof a[v]=="number"},A=function(a){return typeof a=="string"},oa=function(a){return z(a)=="function"},pa=function(a){var b=z(a);return b=="object"||b=="array"||b=="function"},B=function(a){if(a[da]&&a.hasOwnProperty(qa))return a[qa];if(!a[qa])a[qa]=++ra;return a[qa]},qa="closure_hashCode_",ra=0,sa=function(a){var b=
z(a);if(b=="object"||b=="array"){if(a.clone)return a.clone();var c=b=="array"?[]:{};for(var d in a)c[d]=sa(a[d]);return c}return a},C=function(a,b){var c=a.Ya;if(arguments[v]>2){var d=q[_P].slice.call(arguments,2);if(c)d.unshift.apply(d,c);c=d}b=a.$a||b;a=a.Za||a;var e,f=b||y;e=c?function(){var g=q[_P].slice.call(arguments);g.unshift.apply(g,c);return a.apply(f,g)}:function(){return a.apply(f,arguments)};e.Ya=c;e.$a=b;e.Za=a;return e},ta=function(a){var b=q[_P].slice.call(arguments,1);b.unshift(a,
null);return C.apply(null,b)},D=Date.now||function(){return(new Date).getTime()},ua=function(a,b){ia(a,b)};if(!Function[_P].apply)Function[_P].apply=function(a,b){var c=[],d,e;if(!a)a=y;if(!b)b=[];for(var f=0;f<b[v];f++)c[f]="args["+f+"]";e="oScope.__applyTemp__.peek().("+c.join(",")+");";if(!a.__applyTemp__)a.__applyTemp__=[];a.__applyTemp__.push(this);d=eval(e);a.__applyTemp__.pop();return d};var E=function(a,b){function c(){}c.prototype=b[_P];a.aa=b[_P];a.prototype=new c;a[_P].constructor=a};var va="complete";var xa=function(){return wa()};var wa=null,ya=null,za=null,Aa=function(a,b){wa=a;ya=b;za=null},Ca=function(){var a=Ba();return a?new ActiveXObject(a):new XMLHttpRequest},Da=function(){var a=Ba(),b={};if(a){b[0]=true;b[1]=true}return b};Aa(Ca,Da);var Ea=null,Ba=function(){if(!Ea&&typeof XMLHttpRequest=="undefined"&&typeof ActiveXObject!="undefined"){var a=["MSXML2.XMLHTTP.6.0","MSXML2.XMLHTTP.3.0","MSXML2.XMLHTTP","Microsoft.XMLHTTP"];for(var b=0;b<a[v];b++){var c=a[b];try{new ActiveXObject(c);Ea=
c;return c}catch(d){}}throw i("Could not create ActiveXObject. ActiveX might be disabled, or MSXML might not be installed");}return Ea};;var La=function(a,b){if(b)return a.replace(Fa,"&amp;").replace(Ga,"&lt;").replace(Ha,"&gt;").replace(Ia,"&quot;");else{if(!Ka.test(a))return a;if(a.indexOf("&")!=-1)a=a.replace(Fa,"&amp;");if(a.indexOf("<")!=-1)a=a.replace(Ga,"&lt;");if(a.indexOf(">")!=-1)a=a.replace(Ha,"&gt;");if(a.indexOf('"')!=-1)a=a.replace(Ia,"&quot;");return a}},Fa=/&/g,Ga=/</g,Ha=/>/g,Ia=/\"/g,Ka=/[&<>\"]/;var Ma=function(a,b,c){if(a.indexOf)return a.indexOf(b,c);if(q.indexOf)return q.indexOf(a,b,c);var d=c==null?0:(c<0?Math.max(0,a[v]+c):c);for(var e=d;e<a[v];e++)if(e in a&&a[e]===b)return e;return-1},Na=function(a,b,c){if(a.forEach)a.forEach(b,c);else if(q.forEach)q.forEach(a,b,c);else{var d=a[v],e=A(a)?a.split(""):a;for(var f=0;f<d;f++)if(f in e)b.call(c,e[f],f,a)}},Oa=function(a,b){if(a.contains)return a.contains(b);return Ma(a,b)>-1};var Pa=function(a,b){var c=Ma(a,b),d;if(d=c!=-1)q[_P].splice.call(a,
c,1)[v]==1;return d};if("StopIteration"in y)var Qa=y.StopIteration;else Qa=i("StopIteration");var Ra=function(){};Ra[_P].next=function(){throw Qa;};Ra[_P].__iterator__=function(){return this};var Sa=function(a,b,c){for(var d in a)b.call(c,a[d],d,a)},Ta=function(a){var b=[];for(var c in a)b.push(a[c]);return b},Ua=function(a){var b=[];for(var c in a)b.push(c);return b};var Va=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"],Wa=function(a){var b,c;for(var d=1;d<arguments[v];d++){c=arguments[d];for(b in c)a[b]=c[b];for(var e=0;e<Va[v];e++){b=Va[e];if(p[_P][da].call(c,b))a[b]=c[b]}}};var Xa=function(a){if(typeof a.m=="function")return a.m();if(A(a))return a.split("");if(na(a)){var b=[],c=a[v];for(var d=0;d<c;d++)b.push(a[d]);return b}return Ta(a)},Ya=function(a){if(typeof a.T=="function")return a.T();if(typeof a.m=="function")return m;if(na(a)||A(a)){var b=[],c=a[v];for(var d=0;d<c;d++)b.push(d);return b}return Ua(a)},Za=function(a,b,c){if(typeof a.forEach=="function")a.forEach(b,c);else if(na(a)||A(a))Na(a,b,c);else{var d=Ya(a),e=Xa(a),f=e[v];for(var g=0;g<f;g++)b.call(c,e[g],
d&&d[g],a)}};var F=function(a){this.b={};this.d=[];if(a)this.D(a)};F[_P].c=0;F[_P].C=0;F[_P].S=function(){return this.c};F[_P].m=function(){this.H();var a=[];for(var b=0;b<this.d[v];b++){var c=this.d[b];a.push(this.b[c])}return a};F[_P].T=function(){this.H();return this.d.concat()};F[_P].da=function(a){return G(this.b,a)};F[_P].W=function(){return this.c==0};F[_P].clear=function(){this.b={};r(this.d,0);this.c=0;this.C=0};F[_P].remove=function(a){if(G(this.b,a)){delete this.b[a];this.c--;this.C++;if(this.d[v]>
2*this.c)this.H();return true}return false};F[_P].H=function(){if(this.c!=this.d[v]){var a=0,b=0;while(a<this.d[v]){var c=this.d[a];if(G(this.b,c))this.d[b++]=c;a++}r(this.d,b)}if(this.c!=this.d[v]){var d={},a=0,b=0;while(a<this.d[v]){var c=this.d[a];if(!G(d,c)){this.d[b++]=c;d[c]=1}a++}r(this.d,b)}};F[_P].set=function(a,b){if(!G(this.b,a)){this.c++;this.d.push(a);this.C++}this.b[a]=b};F[_P].D=function(a){var b,c;if(a instanceof F){b=a.T();c=a.m()}else{b=Ua(a);c=Ta(a)}for(var d=0;d<b[v];d++)this.set(b[d],
c[d])};F[_P].clone=function(){return new F(this)};F[_P].__iterator__=function(a){this.H();var b=0,c=this.d,d=this.b,e=this.C,f=this,g=new Ra;g.next=function(){while(true){if(e!=f.C)throw i("The map has changed since the iterator was created");if(b>=c[v])throw Qa;var h=c[b++];return a?h:d[h]}};return g};if(p[_P][da])var G=function(a,b){return p[_P][da].call(a,b)};else G=function(a,b){return b in a&&a[b]!==p[_P][b]};var H=function(a){this.b=new F;if(a)this.D(a)},$a=function(a){var b=typeof a;return b=="object"?"o"+B(a):b.substr(0,1)+a};H[_P].S=function(){return this.b.S()};H[_P].add=function(a){this.b.set($a(a),a)};H[_P].D=function(a){var b=Xa(a),c=b[v];for(var d=0;d<c;d++)this.add(b[d])};H[_P].remove=function(a){return this.b.remove($a(a))};H[_P].clear=function(){this.b.clear()};H[_P].W=function(){return this.b.W()};H[_P].contains=function(a){return this.b.da($a(a))};H[_P].m=function(){return this.b.m()};H[_P].clone=
function(){return new H(this)};H[_P].__iterator__=function(){return this.b.__iterator__(false)};var ab=function(a){var b=[];for(var c=0;c<a[v];c++)if(ma(a[c]))b.push(ab(a[c]));else b.push(a[c]);return"[ "+b.join(", ")+" ]"},db=function(a,b){try{var c=bb(a),d="Message: "+La(c[w])+'\nUrl: <a href="view-source:'+c[ga]+'" target="_new">'+c[ga]+"</a>\nLine: "+c.lineNumber+"\n\nBrowser stack:\n"+La(c.stack+"-> ")+"[end]\n\nJS stack traversal:\n"+La(cb(b)+"-> ");return d}catch(e){return"Exception trying to expose exception! You win, we lose. "+e}},bb=function(a){var b=ja("document.location.href");
return typeof a=="string"?{message:a,name:"Unknown error",lineNumber:"Not available",fileName:b,stack:"Not available"}:(!a.lineNumber||!a[ga]||!a.stack?{message:a[w],name:a.name,lineNumber:a.lineNumber||a.line||"Not available",fileName:a[ga]||a.sourceURL||b,stack:a.stack||"Not available"}:a)},cb=function(a){return eb(a||arguments.callee.caller,[])},eb=function(a,b){var c=[];if(Oa(b,a))c.push("[...circular reference...]");else if(a&&b[v]<50){c.push(fb(a)+"(");var d=a.arguments;for(var e=0;e<d[v];e++){if(e>
0)c.push(", ");var f,g=d[e];switch(typeof g){case "object":f=g?"object":"null";break;case "string":f=g;break;case "number":f=o(g);break;case "boolean":f=g?"true":"false";break;case "function":f=fb(g);f=f?f:"[fn]";break;case "undefined":default:f=typeof g;break}if(f[v]>40)f=f.substr(0,40)+"...";c.push(f)}b.push(a);c.push(")\n");try{c.push(eb(a.caller,b))}catch(h){c.push("[exception trying to get caller]\n")}}else if(a)c.push("[...long stack...]");else c.push("[end]");return c.join("")},fb=function(a){var b=
o(a);if(!gb[b]){var c=/function([^\(]+)/.exec(b);if(c){var d=c[1],e=/^\$(.+)\$$/.exec(d);if(e)d=e[1].replace(/\${1,2}/g,".");gb[b]=d}else gb[b]="[Anonymous]"}return gb[b]},hb=function(a,b,c,d){if(ja("document.all"))return"";var e=b||y,f=c||"",g=d||0;if(e==a)return f;for(var h in e){if(h=="Packages"||h=="sun"||h=="netscape"||h=="java")continue;if(e[h]==a)return f+h;if((typeof e[h]=="function"||typeof e[h]=="object")&&e[h]!=y&&e[h]!=ja("document")&&e.hasOwnProperty(h)&&g<6){var k=hb(a,e[h],f+h+".",
g+1);if(k)return k}}return""},gb={};var I=function(a,b,c){this.gb=ib++;this.ib=D();this.g=a;this.eb=b;this.db=c};I[_P].Ea=null;I[_P].Da=null;var ib=0;I[_P].Ra=function(a){this.Ea=a};I[_P].Sa=function(a){this.Da=a};I[_P].U=function(){return this.g};I[_P].Z=function(a){this.g=a};var J=function(a){this.bb=a;this.z=null;this.ab={};this.Ia=[]};J[_P].g=null;var K=function(a,b){this.name=a;this.value=b};K[_P].toString=function(){return this.name};new K("OFF",Infinity);new K("SHOUT",1200);new K("SEVERE",1000);var jb=new K("WARNING",900);new K("INFO",800);var kb=new K("CONFIG",700),lb=new K("FINE",500);new K("FINER",400);var mb=new K("FINEST",300);new K("ALL",0);var ob=function(a){return nb(a)};J[_P].Ga=function(){return this.z};J[_P].Z=function(a){this.g=a};J[_P].U=function(){return this.g};
J[_P].Fa=function(){if(this.g)return this.g;if(this.z)return this.z.Fa();return null};J[_P].Y=function(a){if(this.g)return a.value>=this.g.value;if(this.z)return this.z.Y(a);return false};J[_P].log=function(a,b,c){if(!this.Y(a))return;var d=new I(a,o(b),this.bb);if(c){d.Ra(c);d.Sa(db(c,arguments.callee.caller))}this.Ka(d)};J[_P].warning=function(a,b){this.log(jb,a,b)};J[_P].fine=function(a,b){this.log(lb,a,b)};J[_P].finest=function(a,b){this.log(mb,a,b)};J[_P].Ka=function(a){if(!this.Y(a.U()))return;
var b=this;while(b){b.Aa(a);b=b.Ga()}};J[_P].Aa=function(a){for(var b=0;b<this.Ia[v];b++)this.Ia[b](a)};J[_P].Ta=function(a){this.z=a};J[_P].za=function(a,b){this.ab[a]=b};var pb={},qb=null,rb=function(){if(!qb){qb=new J("");pb[""]=qb;qb.Z(kb)}},nb=function(a){rb();return a in pb?pb[a]:sb(a)},sb=function(a){var b=new J(a),c=a.split("."),d=c[c[v]-1];r(c,c[v]-1);var e=c.join("."),f=nb(e);f.za(d,b);b.Ta(f);pb[a]=b;return b};var tb=function(){this.cb=D()},ub=new tb;tb[_P].set=function(a){this.cb=a};tb[_P].reset=function(){this.set(D())};var vb=function(a){this.fb=a||"";this.hb=ub},wb=function(a){vb.call(this,a)};E(wb,vb);var xb=function(a){vb.call(this,a)};E(xb,vb);var yb,zb,L,Ab,Bb,Cb,Db,Eb,Fb,Gb,Hb,Ib;(function(){var a=false,b=false,c=false,d=false,e=false,f=false,g=false,h=false,k=false,j="";if(y.navigator){var l=aa.userAgent;a=typeof opera!="undefined";b=!a&&l.indexOf("MSIE")!=-1;c=!a&&l.indexOf("WebKit")!=-1;k=c&&l.indexOf("Mobile")!=-1;d=!a&&aa.product=="Gecko"&&!c;e=d&&aa.vendor=="Camino";var n,s;if(a)n=opera.version();else{if(d)s=/rv\:([^\);]+)(\)|;)/;else if(b)s=/MSIE\s+([^\);]+)(\)|;)/;else if(c)s=/WebKit\/(\S+)/;if(s){s.test(l);n=RegExp.$1}}j=aa.platform;
f=j.indexOf("Mac")!=-1;g=j.indexOf("Win")!=-1;h=j.indexOf("Linux")!=-1}yb=a;zb=b;L=d;Ab=e;Bb=c;Cb=Bb;Db=n;Eb=j;Fb=f;Gb=g;Hb=h;Ib=k})();var M=function(){if(!L)return;this.o={};this.ba={};this.$=[]};M[_P].e=ob("goog.net.xhrMonitor");M[_P].va=function(a){if(!L)return;var b=A(a)?a:(pa(a)?B(a):"");this.e.finest("Pushing context: "+a+" ("+b+")");this.$.push(b)};M[_P].ua=function(){if(!L)return;var a=this.$.pop();this.e.finest("Popping context: "+a);this.Xa(a)};M[_P].Ma=function(a){if(!L)return;var b=B(a);this.e.fine("Opening XHR : "+b);for(var c=0;c<this.$[v];c++){var d=this.$[c];this.F(this.o,d,b);this.F(this.ba,b,d)}};M[_P].La=function(a){if(!L)return;
var b=B(a);this.e.fine("Closing XHR : "+b);delete this.ba[b];for(var c in this.o){Pa(this.o[c],b);if(this.o[c][v]==0)delete this.o[c]}};M[_P].Xa=function(a){var b=this.ba[a],c=this.o[a];if(b&&c){this.e.finest("Updating dependent contexts");Na(b,function(d){Na(c,function(e){this.F(this.o,d,e);this.F(this.ba,e,d)},this)},this)}};M[_P].F=function(a,b,c){if(!a[b])a[b]=[];if(!Oa(a[b],c))a[b].push(c)};var N=new M;var O=function(){};O[_P].Q=false;O[_P].v=function(){return this.Q};O[_P].dispose=function(){if(!this.Q)this.Q=true};var P=function(a,b){u(this,a);ba(this,b);t(this,this.target)};E(P,O);P[_P].j=false;P[_P].u=true;P[_P].stopPropagation=function(){this.j=true};P[_P].preventDefault=function(){this.u=false};var Q=function(a,b){O.call(this);this.Na=b;this.p=[];this.Ba(a)};E(Q,O);Q[_P].O=null;Q[_P].P=null;Q[_P].A=function(a){this.O=a};Q[_P].ya=function(a){this.P=a};Q[_P].i=function(){if(this.p[v])return this.p.pop();return this.ea()};Q[_P].t=function(a){if(this.p[v]<this.Na)this.p.push(a);else this.ha(a)};Q[_P].Ba=function(a){if(a>this.Na)throw i("[goog.structs.SimplePool] Initial cannot be greater than max");for(var b=0;b<a;b++)this.p.push(this.ea())};Q[_P].ea=function(){return this.O?this.O():{}};Q[_P].ha=
function(a){if(this.P)this.P(a);else if(oa(a.dispose))a.dispose();else for(var b in a)delete a[b]};Q[_P].dispose=function(){if(!this.v()){Q.aa.dispose.call(this);var a=this.p;while(a[v])this.ha(a.pop());this.p=null}};var R=function(a,b){if(a)this.init(a,b)};E(R,P);u(R[_P],null);ba(R[_P],null);t(R[_P],null);R[_P].relatedTarget=null;R[_P].offsetX=0;R[_P].offsetY=0;R[_P].clientX=0;R[_P].clientY=0;R[_P].screenX=0;R[_P].screenY=0;R[_P].button=0;ca(R[_P],0);R[_P].charCode=0;R[_P].ctrlKey=false;R[_P].altKey=false;R[_P].shiftKey=false;R[_P].metaKey=false;R[_P].f=null;R[_P].init=function(a,b){u(this,a[x]);ba(this,a.target||a.srcElement);t(this,b);this.relatedTarget=a.relatedTarget?a.relatedTarget:(this[x]=="mouseover"?
a.fromElement:(this[x]=="mouseout"?a.toElement:null));this.offsetX=typeof a.layerX=="number"?a.layerX:a.offsetX;this.offsetY=typeof a.layerY=="number"?a.layerY:a.offsetY;this.clientX=typeof a.clientX=="number"?a.clientX:a.pageX;this.clientY=typeof a.clientY=="number"?a.clientY:a.pageY;this.screenX=a.screenX||0;this.screenY=a.screenY||0;this.button=a.button;ca(this,a[fa]||0);this.charCode=a.charCode||(this[x]=="keypress"?a[fa]:0);this.ctrlKey=a.ctrlKey;this.altKey=a.altKey;this.shiftKey=a.shiftKey;
this.metaKey=a.metaKey;this.f=a;this.u=null;this.j=null};R[_P].stopPropagation=function(){this.j=true;if(this.f.stopPropagation)this.f.stopPropagation();else this.f.cancelBubble=true};R[_P].preventDefault=function(){this.u=false;if(!this.f.preventDefault){this.f.returnValue=false;try{ca(this.f,-1)}catch(a){}}else this.f.preventDefault()};R[_P].dispose=function(){if(!this.v()){P[_P].dispose.call(this);this.f=null}};var S=function(){},Jb=0;S[_P].X=null;S[_P].listener=null;S[_P].proxy=null;S[_P].src=null;u(S[_P],null);S[_P].capture=null;S[_P].handler=null;S[_P].key=0;S[_P].removed=false;S[_P].N=false;S[_P].init=function(a,b,c,d,e,f){if(oa(a))this.X=true;else if(a&&a.q&&oa(a.q))this.X=false;else throw i("Invalid listener argument");this.listener=a;this.proxy=b;this.src=c;u(this,d);this.capture=!(!e);this.handler=f;this.N=false;this.key=++Jb;this.removed=false};S[_P].q=function(a){if(this.X)return this.listener.call(this.handler||
this.src,a);return this.listener.q.call(this.listener,a)};var T={},U={},V={},W=new Q(0,600);W.A(function(){return{c:0}});W.ya(function(a){a.c=0});var X=new Q(0,600);X.A(function(){return[]});X.ya(function(a){r(a,0);delete a.K;delete a.ra});var Kb=new Q(0,600);Kb.A(function(){var a=function(b){return Lb.call(a.src,a.key,b)};return a});var Mb=function(){return new S},Nb=new Q(0,600);Nb.A(Mb);var Ob=function(){return new R},Pb=function(){var a=null;if(zb){a=new Q(0,600);a.A(Ob)}return a},Qb=Pb(),Rb="on",Sb={},Tb=function(a,b,c,d,e){if(!b)throw i("Invalid event type");
else if(ma(b)){for(var f=0;f<b[v];f++)Tb(a,b[f],c,d,e);return null}var g=!(!d),h=U;if(!(b in h))h[b]=W.i();h=h[b];if(!(g in h)){h[g]=W.i();h.c++}h=h[g];var k=B(a),j,l;if(!h[k]){j=(h[k]=X.i());h.c++}else{j=h[k];for(var f=0;f<j[v];f++){l=j[f];if(l.listener==c&&l.handler==e){if(l.removed)break;return j[f].key}}}var n=Kb.i();n.src=a;l=Nb.i();l.init(c,n,a,b,g,e);var s=l.key;n.key=s;j.push(l);T[s]=l;if(!V[k])V[k]=X.i();V[k].push(l);if(a.addEventListener){if(a==y||!a.fa)a.addEventListener(b,n,g)}else a.attachEvent(Ub(b),
n);return s},Vb=function(a,b,c,d,e){if(ma(b)){for(var f=0;f<b[v];f++)Vb(a,b[f],c,d,e);return null}var g=Tb(a,b,c,d,e),h=T[g];h.N=true;return g},Wb=function(a,b,c,d,e){if(ma(b)){for(var f=0;f<b[v];f++)Wb(a,b[f],c,d,e);return null}var g=!(!d),h=Xb(a,b,g);if(!h)return false;for(var f=0;f<h[v];f++)if(h[f].listener==c&&h[f][ea]==g&&h[f].handler==e)return Yb(h[f].key);return false},Yb=function(a){if(!T[a])return false;var b=T[a];if(b.removed)return false;var c=b.src,d=b[x],e=b.proxy,f=b[ea];if(c.removeEventListener){if(c==
y||!c.fa)c.removeEventListener(d,e,f)}else if(c.detachEvent)c.detachEvent(Ub(d),e);var g=B(c),h=U[d][f][g];if(V[g]){var k=V[g];Pa(k,b);if(k[v]==0)delete V[g]}b.removed=true;h.ra=true;Zb(d,f,g,h);delete T[a];return true},Zb=function(a,b,c,d){if(!d.K)if(d.ra){for(var e=0,f=0;e<d[v];e++){if(d[e].removed){Nb.t(d[e]);continue}if(e!=f)d[f]=d[e];f++}r(d,f);d.ra=false;if(f==0){X.t(d);delete U[a][b][c];U[a][b].c--;if(U[a][b].c==0){W.t(U[a][b]);delete U[a][b];U[a].c--}if(U[a].c==0){W.t(U[a]);delete U[a]}}}},
$b=function(a,b,c){var d=0,e=a==null,f=b==null,g=c==null;c=!(!c);if(!e){var h=B(a);if(V[h]){var k=V[h];for(var j=k[v]-1;j>=0;j--){var l=k[j];if((f||b==l[x])&&(g||c==l[ea])){Yb(l.key);d++}}}}else Sa(V,function(n){for(var s=n[v]-1;s>=0;s--){var Ja=n[s];if((f||b==Ja[x])&&(g||c==Ja[ea])){Yb(Ja.key);d++}}});return d},Xb=function(a,b,c){var d=U;if(b in d){d=d[b];if(c in d){d=d[c];var e=B(a);if(d[e])return d[e]}}return null},Ub=function(a){if(a in Sb)return Sb[a];return Sb[a]=Rb+a},bc=function(a,b,c,d){var e=
1,f=U;if(b in f){f=f[b];if(c in f){f=f[c];var g=B(a);if(f[g]){var h=f[g];if(!h.K)h.K=1;else h.K++;try{var k=h[v];for(var j=0;j<k;j++){var l=h[j];if(l&&!l.removed)e&=ac(l,d)!==false}}finally{h.K--;Zb(b,c,g,h)}}}}return Boolean(e)},ac=function(a,b){var c=a.q(b);if(a.N)Yb(a.key);return c},cc=function(a,b){if(A(b))b=new P(b,a);else if(!(b instanceof P)){var c=b;b=new P(b[x],a);Wa(b,c)}else ba(b,b.target||a);var d=1,e,f=b[x],g=U;if(!(f in g))return true;g=g[f];var h=true in g,k=false in g;if(h){e=[];for(var j=
a;j;j=j.la())e.push(j);for(var l=e[v]-1;!b.j&&l>=0;l--){t(b,e[l]);d&=bc(e[l],b[x],true,b)&&b.u!=false}}if(k)if(h)for(var l=0;!b.j&&l<e[v];l++){t(b,e[l]);d&=bc(e[l],b[x],false,b)&&b.u!=false}else for(var n=a;!b.j&&n;n=n.la()){t(b,n);d&=bc(n,b[x],false,b)&&b.u!=false}return Boolean(d)},Lb=function(a,b){if(!T[a])return true;var c=T[a],d=c[x],e=U;if(!(d in e))return true;e=e[d];var f;if(zb){var g=b||ja("window.event"),h=true in e;if(h){if(g[fa]<0||g.returnValue!=m)return true;dc(g)}B(c.src);var k=Qb.i();
k.init(g,this);f=true;try{if(h){var j=X.i();for(var l=k.currentTarget;l;l=l.parentNode)j.push(l);for(var n=j[v]-1;!k.j&&n>=0;n--){t(k,j[n]);f&=bc(j[n],d,true,k)}for(var n=0;!k.j&&n<j[v];n++){t(k,j[n]);f&=bc(j[n],d,false,k)}}else f=ac(c,k)}finally{if(j){r(j,0);X.t(j)}k.dispose();Qb.t(k)}return f}var s=new R(b,this);try{f=ac(c,s)}finally{s.dispose()}return f},dc=function(a){var b=false;if(a[fa]==0)try{ca(a,-1);return}catch(c){b=true}if(b||a.returnValue==m)a.returnValue=true};var Y=function(){};E(Y,O);Y[_P].fa=true;Y[_P].ta=null;Y[_P].la=function(){return this.ta};Y[_P].addEventListener=function(a,b,c,d){Tb(this,a,b,c,d)};Y[_P].removeEventListener=function(a,b,c,d){Wb(this,a,b,c,d)};Y[_P].dispatchEvent=function(a){return cc(this,a)};Y[_P].dispose=function(){if(!this.v()){O[_P].dispose.call(this);$b(this);this.ta=null}};var ec=function(a){if(/^\s*$/.test(a))return false;var b=/\\["\\\/bfnrtu]/g,c=/"[^"\\\n\r\u2028\u2029\x00-\x1f\x7f-\x9f]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,d=/(?:^|:|,)(?:[\s\u2028\u2029]*\[)+/g,e=/^[\],:{}\s\u2028\u2029]*$/;return e.test(a.replace(b,"@").replace(c,"]").replace(d,""))},fc=function(a){a=o(a);if(typeof a.parseJSON=="function")return a.parseJSON();if(ec(a))try{return eval("("+a+")")}catch(b){}throw i("Invalid JSON string: "+a);},gc=function(){};gc[_P].xa=function(a,
b){switch(typeof a){case "string":this.wa(a,b);break;case "number":this.Pa(a,b);break;case "boolean":b.push(a);break;case "undefined":b.push("null");break;case "object":if(a==null){b.push("null");break}if(ma(a)){this.Oa(a,b);break}this.Qa(a,b);break;default:throw i("Unknown type: "+typeof a);}};var hc={'"':'\\"',"\\":"\\\\","/":"\\/","\u0008":"\\b","\u000c":"\\f","\n":"\\n","\r":"\\r","\t":"\\t","\u000b":"\\u000b"};gc[_P].wa=function(a,b){b.push('"',a.replace(/[\\\"\x00-\x1f\x80-\uffff]/g,function(c){if(c in
hc)return hc[c];var d=c.charCodeAt(0),e="\\u";if(d<16)e+="000";else if(d<256)e+="00";else if(d<4096)e+="0";return hc[c]=e+d.toString(16)}),'"')};gc[_P].Pa=function(a,b){b.push(isFinite(a)&&!isNaN(a)?a:"null")};gc[_P].Oa=function(a,b){var c=a[v];b.push("[");var d="";for(var e=0;e<c;e++){b.push(d);this.xa(a[e],b);d=","}b.push("]")};gc[_P].Qa=function(a,b){b.push("{");var c="";for(var d in a){b.push(c);this.wa(d,b);b.push(":");this.xa(a[d],b);c=","}b.push("}")};var Z=function(a,b){Y.call(this);this.J=a||1;this.L=b||ic;this.ca=C(this.Va,this);this.qa=D()};E(Z,Y);Z[_P].enabled=false;var ic=y.window,jc=0.8;Z[_P].k=null;Z[_P].setInterval=function(a){this.J=a;if(this.k&&this.enabled){this.stop();this.start()}else if(this.k)this.stop()};Z[_P].Va=function(){if(this.enabled){var a=D()-this.qa;if(a>0&&a<this.J*jc){this.k=this.L.setTimeout(this.ca,this.J-a);return}this.Ca();if(this.enabled){this.k=this.L.setTimeout(this.ca,this.J);this.qa=D()}}};Z[_P].Ca=function(){this.dispatchEvent("tick")};
Z[_P].start=function(){this.enabled=true;if(!this.k){this.k=this.L.setTimeout(this.ca,this.J);this.qa=D()}};Z[_P].stop=function(){this.enabled=false;this.L.clearTimeout(this.k);this.k=null};Z[_P].dispose=function(){if(!this.v()){Y[_P].dispose.call(this);this.stop();this.L=null}};var kc=function(a,b,c){if(oa(a)){if(c)a=C(a,c)}else if(a&&typeof a.q=="function")a=C(a.q,a);else throw i("Invalid listener argument");return ic.setTimeout(a,b||0)};var $=function(){Y.call(this);this.headers=new F};E($,Y);$[_P].e=ob("goog.net.XhrLite");var lc=[],nc=function(a,b,c,d,e,f){var g=new $;lc.push(g);if(b)Tb(g,va,b);Tb(g,"ready",ta(mc,g));if(f)g.Ua(f);g.send(a,c,d,e)},mc=function(a){a.dispose();Pa(lc,a)};$[_P].l=false;$[_P].a=null;$[_P].M=null;$[_P].pa="";$[_P].oa="";$[_P].r=0;$[_P].s="";$[_P].R=false;$[_P].V=false;$[_P].B=0;$[_P].n=null;$[_P].Ua=function(a){this.B=Math.max(0,a)};$[_P].send=function(a,b,c,d){if(this.l)throw i("[goog.net.XhrLite] Object is active with another request");
var e=b||"GET";this.pa=a;this.s="";this.r=0;this.oa=e;this.l=true;this.a=new xa;this.M=za||(za=ya());N.Ma(this.a);this.a.onreadystatechange=C(this.sa,this);try{this.h("Opening Xhr");this.a.open(e,a,true)}catch(f){this.h("Error opening Xhr: "+f[w]);this.ia(5,f);return}var g=c?o(c):"",h=this.headers.clone();if(d)Za(d,function(k,j){h.set(j,k)});if(e=="POST"&&!h.da("Content-Type"))h.set("Content-Type","application/x-www-form-urlencoded;charset=utf-8");Za(h,function(k,j){this.a.setRequestHeader(j,k)},
this);try{if(this.n){ic.clearTimeout(this.n);this.n=null}if(this.B>0){this.h("Will abort after "+this.B+"ms if incomplete");this.n=ic.setTimeout(C(this.Wa,this),this.B)}this.h("Sending request");this.R=false;this.V=true;this.a.send(g);this.V=false}catch(f){this.h("Send error: "+f[w]);this.ia(5,f)}};$[_P].dispatchEvent=function(a){if(this.a){N.va(this.a);try{$.aa.dispatchEvent.call(this,a)}finally{N.ua()}}else $.aa.dispatchEvent.call(this,a)};$[_P].Wa=function(){if(typeof ha=="undefined"){}else if(this.a){this.s=
"Timed out after "+this.B+"ms, aborting";this.r=8;this.h(this.s);this.dispatchEvent("timeout");this.abort(8)}};$[_P].ia=function(a,b){this.l=false;if(this.a)this.a.abort();this.s=b;this.r=a;this.ga();this.G()};$[_P].ga=function(){if(!this.R){this.R=true;this.dispatchEvent(va);this.dispatchEvent("error")}};$[_P].abort=function(a){if(this.a){this.h("Aborting");this.l=false;this.a.abort();this.r=a||7;this.dispatchEvent(va);this.dispatchEvent("abort");this.G()}};$[_P].dispose=function(){if(!this.v()){if(this.a){this.l=
false;this.a.abort();this.G(true)}$.aa.dispose.call(this)}};$[_P].sa=function(){if(!this.l)return;if(typeof ha=="undefined"){}else if(this.M[1]&&this.w()==4&&this.I()==2)this.h("Local request error detected and ignored");else{if(this.V&&this.w()==4){kc(this.sa,0,this);return}this.dispatchEvent("readystatechange");if(this.na()){this.h("Request complete");this.l=false;if(this.Ja()){this.dispatchEvent(va);this.dispatchEvent("success")}else{this.r=6;this.s=this.Ha()+" ["+this.I()+"]";this.ga()}this.G()}}};
$[_P].G=function(a){if(this.a){this.a.onreadystatechange=this.M[0]?ka:null;var b=this.a;this.a=null;this.M=null;if(this.n){ic.clearTimeout(this.n);this.n=null}if(!a){N.va(b);this.dispatchEvent("ready");N.ua()}N.La(b)}};$[_P].na=function(){return this.w()==4};$[_P].Ja=function(){switch(this.I()){case 0:case 200:case 204:case 304:return true;default:return false}};$[_P].w=function(){return this.a?this.a.readyState:0};$[_P].I=function(){try{return this.w()>2?this.a.status:-1}catch(a){this.e.warning("Can not get status: "+
a[w]);return-1}};$[_P].Ha=function(){try{return this.w()>2?this.a.statusText:""}catch(a){this.e.fine("Can not get status: "+a[w]);return""}};$[_P].ma=function(){return this.a?fc(this.a.responseText):m};$[_P].getResponseHeader=function(a){return this.a&&this.na()?this.a.getResponseHeader(a):m};$[_P].ka=function(){return this.r};$[_P].ja=function(){return this.s};$[_P].h=function(a){this.e.fine(a+" ["+this.oa+" "+this.pa+" "+this.I()+"]")};function oc(a){switch(typeof a){case "string":return a;case "object":var b=[];for(var c in a||{})b.push(c+"="+encodeURIComponent(a[c]).toString());return b.join("&");default:throw"Invalid post data type";}}function pc(a,b,c){nc(a,function(){var d=this.ka();if(d==0)b(this.ma());else if(c)c(d,this.ja())})}function qc(a,b,c,d){nc(a,function(){var e=this.ka();if(e==0)c(this.ma());else if(d)d(e,this.ja())},"POST",oc(b))}ua("getAjaxResponseJson",pc);ua("postAjaxResponseJson",qc);})();
function showMessage(text,cls,target){
target=(target?_gel(target):_gel("messages"));
if(target){
_removeclass(target,'hidden');
target.innerHTML+="<span class=\""+cls+"\">"+text+" (<a href=\"#\" onClick=\"clearMessages('"+target.id+"'); return false;\">X</a>)</span>";
}
}
function showErrorMessage(text,target){
showMessage(text,"yte-error",target);
}
function showInfoMessage(text,target){
showMessage(text,"yte-info",target);
}
function showSuccessMessage(text,target){
showMessage(text,"yte-success",target);
}
function clearMessages(target){
target=(target?_gel(target):_gel("messages"));
if(target){
_addclass(target,'hidden');
target.innerHTML="";
}
}
function getSelectedItems(target){
var items=new Array();
target=(target?_gel(target):_gel("items"));
if(target){
var checkboxes=target.getElementsByTagName('INPUT');
goog.array.forEach(target.getElementsByTagName('INPUT'),function(input){
if(input.type=='checkbox'&&input.checked){
items.push(input.value);
}
});
}
return items;
}
function createViewState(initState,callback){
var result=new Object();
result.pageIndex=0;
result.pageSize=20;
result.sortField='';
result.sortAscending=false;
result.searchQuery='';
result.displayMode=0;
var _applyState=function(src,state){
if(state){
for(var key in state){
if(src[key]!==undefined)src[key]=state[key];
}
}
};
_applyState(result,initState);
result.applyState=function(state){
_applyState(this,state);
if(callback)callback(this);
};
return result;
}
function selectItem(item){
item.checked=true;
}
function deselectItem(item){
item.checked=false;
}
function selectAllItems(target){
target=(target?_gel(target):_gel("items"));
if(target){
var checkboxes=target.getElementsByTagName('INPUT');
goog.array.forEach(target.getElementsByTagName('INPUT'),function(input){
if(input.type=='checkbox'){
selectItem(input);
}
});
}
}
function deselectAllItems(target){
target=(target?_gel(target):_gel("items"));
if(target){
var checkboxes=target.getElementsByTagName('INPUT');
goog.array.forEach(target.getElementsByTagName('INPUT'),function(input){
if(input.type=='checkbox'){
deselectItem(input);
}
});
}
}
function disableItem(item){
item.disabled=true;
}
function enableItem(item){
item.disabled=false;
}
function disableAllItems(target){
target=(target?_gel(target):_gel("items"));
if(target){
var checkboxes=target.getElementsByTagName('INPUT');
goog.array.forEach(target.getElementsByTagName('INPUT'),function(input){
if(input.type=='checkbox'){
disableItem(input);
}
});
}
}
function enableAllItems(target){
target=(target?_gel(target):_gel("items"));
if(target){
var checkboxes=target.getElementsByTagName('INPUT');
goog.array.forEach(target.getElementsByTagName('INPUT'),function(input){
if(input.type=='checkbox'){
enableItem(input);
}
});
}
}
function replaceClass(target,currentClass,newClass){
var target=_gel(target);
if(_hasclass(target,currentClass)){
_removeclass(target,currentClass);
_addclass(target,newClass);
}
}
function swapClass(target,classA,classB){
var target=_gel(target);
if(_hasclass(target,classA)){
replaceClass(target,classA,classB);
}else if(_hasclass(target,classB)){
replaceClass(target,classB,classA);
}
}
function disableButton(target){
target=_gel(target);
if(target){
if(_hasclass(target,'yt-button'))replaceClass(target,'yt-button','yt-button-disabled');
if(_hasclass(target,'yt-button-alt'))replaceClass(target,'yt-button-alt','yt-button-alt-disabled');
if(_hasclass(target,'yt-button-compact'))replaceClass(target,'yt-button-compact','yt-button-compact-disabled');
}
}
function enableButton(target){
target=_gel(target);
if(target){
if(_hasclass(target,'yt-button-disabled'))replaceClass(target,'yt-button-disabled','yt-button');
if(_hasclass(target,'yt-button-alt-disabled'))replaceClass(target,'yt-button-alt-disabled','yt-button-alt');
if(_hasclass(target,'yt-button-compact-disabled'))replaceClass(target,'yt-button-compact-disabled','yt-button-compact');
}
}
function isButtonEnabled(target){
target=_gel(target);
return _hasclass(target,'yt-button')||_hasclass(target,'yt-button-alt')||_hasclass(target,'yt-button-compact');
}
function buildPostData(data){
var pairs=new Array();
for(var prop in data){
pairs.push(prop+"="+encodeURIComponent(data[prop].toString()));
}
return pairs.join("&");
}
function onTransportError(code,message){
yt.EventManager.fireEvent("TransportError");
}
function deleteVideos(ids,secureTokenCallback){
var url="/video_ajax";
var onSuccess=function(data){
var errors=data.errors;
if(errors.length>0){
yt.EventManager.fireEvent("VideosDeletedError",errors.pop());
}else{
yt.EventManager.fireEvent("VideosDeleted",ids);
}
}
var postData={};
postData['action_delete_videos']=1;
postData['v']=ids.join(',');
postData['session_token']=secureTokenCallback('video_ajax');
postAjaxResponseJson(url,postData,onSuccess,onTransportError);
}
function addVideosToQuicklist(ids,secureTokenCallback){
var url="/video_ajax";
var onSuccess=function(data){
var errors=data.errors;
if(errors.length>0){
yt.EventManager.fireEvent("VideosAddedToQuicklistError",errors.pop());
}else{
yt.EventManager.fireEvent("VideosAddedToQuicklist",ids);
}
}
var postData={};
postData['action_add_videos_to_quicklist']=1;
postData['v']=ids.join(',');
postData['session_token']=secureTokenCallback('video_ajax');
postAjaxResponseJson(url,postData,onSuccess,onTransportError);
}
function addVideosToFavorites(ids,secureTokenCallback){
var url="/video_ajax";
var onSuccess=function(data){
var errors=data.errors;
if(errors.length>0){
yt.EventManager.fireEvent("VideosAddedToFavoritesError",errors.pop());
}else{
yt.EventManager.fireEvent("VideosAddedToFavorites",ids);
}
}
var postData={};
postData['action_add_videos_to_favorites']=1;
postData['v']=ids.join(',');
postData['session_token']=secureTokenCallback('video_ajax');
postAjaxResponseJson(url,postData,onSuccess,onTransportError);
}
function addVideosToPlaylists(video_ids,playlist_ids,secureTokenCallback){
var url="/playlist_ajax";
var onSuccess=function(data){
var errors=data.errors;
if(errors.length>0){
yt.EventManager.fireEvent("VideosAddedToPlaylistsError",errors.pop());
}else{
yt.EventManager.fireEvent("VideosAddedToPlaylists",null);
}
}
var postData={};
postData['action_add_videos_to_playlists']=1;
postData['v']=video_ids.join(',');
postData['p']=playlist_ids.join(',');
postData['session_token']=secureTokenCallback('playlist_ajax');
postAjaxResponseJson(url,postData,onSuccess,onTransportError);
}
function createNewPlaylist(name,secureTokenCallback){
var url="/playlist_ajax";
var onSuccess=function(data){
var errors=data.errors;
if(errors.length>0){
yt.EventManager.fireEvent("PlaylistCreatedError",errors.pop());
}else{
var response=data.response;
var playlist={"id":response.playlistId,"name":response.playlistName};
yt.EventManager.fireEvent("PlaylistCreated",playlist);
}
}
var postData={};
postData['action_create_playlist']=1;
postData['n']=name;
postData['session_token']=secureTokenCallback('playlist_ajax');
postAjaxResponseJson(url,postData,onSuccess,onTransportError);
}
function deleteFavorites(ids,secureTokenCallback){
var url="/video_ajax";
var onSuccess=function(data){
var errors=data.errors;
if(errors.length>0){
yt.EventManager.fireEvent("FavoritesDeletedError",errors.pop());
}else{
yt.EventManager.fireEvent("FavoritesDeleted",ids);
}
}
var postData={};
postData['action_remove_videos_from_favorites']=1;
postData['v']=ids.join(',');
postData['session_token']=secureTokenCallback('video_ajax');
postAjaxResponseJson(url,postData,onSuccess,onTransportError);
}
function hideVideo(id,secureTokenCallback){
var url="/video_developer_ajax";
var onSuccess=function(data){
var errors=data.errors;
if(errors.length>0){
yt.EventManager.fireEvent("HideVideoError",errors.pop());
}else{
yt.EventManager.fireEvent("HideVideoSuccess",id);
}
}
var postData={};
postData['action_hide_video']=1;
postData['v']=id;
postData['session_token']=secureTokenCallback('video_developer_ajax');
postAjaxResponseJson(url,postData,onSuccess,onTransportError);
}
function showVideo(id,secureTokenCallback){
var url="/video_developer_ajax";
var onSuccess=function(data){
var errors=data.errors;
if(errors.length>0){
yt.EventManager.fireEvent("ShowVideoError",errors.pop());
}else{
yt.EventManager.fireEvent("ShowVideoSuccess",id);
}
}
var postData={};
postData['action_show_video']=1;
postData['v']=id;
postData['session_token']=secureTokenCallback('video_developer_ajax');
postAjaxResponseJson(url,postData,onSuccess,onTransportError);
}
function changePlaylistThumbnail(playlistId,videoSetId,videoId,secureTokenCallback){
var url="/playlist_ajax";
var onSuccess=function(data){
var errors=data.errors;
if(errors.length>0){
yt.EventManager.fireEvent("PlaylistThumbnailChangedError",errors.pop())
}else{
yt.EventManager.fireEvent("PlaylistThumbnailChanged",{"playlistId":playlistId,"videoId":videoId});
}
}
var postData={};
postData['action_set_playlist_thumbnail']=1;
postData['p']=playlistId;
postData['v']=videoSetId;
postData['session_token']=secureTokenCallback('playlist_ajax');
postAjaxResponseJson(url,postData,onSuccess,onTransportError);
}
function deletePlaylist(id,secureTokenCallback){
var url="/playlist_ajax";
var onSuccess=function(data){
var errors=data.errors;
if(errors.length>0){
yt.EventManager.fireEvent("PlaylistDeletedError",errors.pop());
}else{
yt.EventManager.fireEvent("PlaylistDeleted",id);
}
}
var postData={};
postData['action_delete_playlist']=1;
postData['p']=id;
postData['session_token']=secureTokenCallback("playlist_ajax");
postAjaxResponseJson(url,postData,onSuccess,onTransportError);
}
function updatePlaylist(id,title,desc,tags,isPublic,allowEmbed,isVlog,isSeries,secureTokenCallback){
var url="/playlist_ajax";
var onSuccess=function(data){
var errors=data.errors;
if(errors.length>0){
yt.EventManager.fireEvent("PlaylistUpdatedError",errors);
}else{
yt.EventManager.fireEvent("PlaylistUpdated",id);
}
}
var postData={};
postData['action_edit_playlist']=1;
postData['p']=id;
postData['t']=title;
postData['d']=desc;
postData['k']=tags;
postData['y']=(isPublic?0:1);
postData['e']=(allowEmbed?1:0);
postData['v']=(isVlog?1:0);
postData['s']=(isSeries?1:0);
postData['session_token']=secureTokenCallback('playlist_ajax');
postAjaxResponseJson(url,postData,onSuccess,onTransportError);
}
function removeVideosFromPlaylist(playlistId,ids,secureTokenCallback){
var url="/playlist_ajax";
var onSuccess=function(data){
var errors=data.errors;
if(errors.length>0){
yt.EventManager.fireEvent("VideosRemovedFromPlaylistError",errors.pop());
}else{
yt.EventManager.fireEvent("VideosRemovedFromPlaylist",{"playlistId":playlistId,"videoIds":ids});
}
}
var postData={};
postData['action_remove_videos_from_playlist']=1;
postData['p']=playlistId;
postData['v']=ids.join(',');
postData['session_token']=secureTokenCallback('playlist_ajax');
postAjaxResponseJson(url,postData,onSuccess,onTransportError);
}
function removeSubscriptions(ids,secureTokenCallback){
var url="/subscription_ajax";
var onSuccess=function(data){
var errors=data.errors;
if(errors.length>0){
yt.EventManager.fireEvent("SubscriptionsRemovedError",errors.pop());
}else{
yt.EventManager.fireEvent("SubscriptionsRemoved",ids);
}
}
var postData={};
postData['action_remove_subscriptions']=1;
postData['s']=ids.join(',');
postData['session_token']=secureTokenCallback('subscription_ajax');
postAjaxResponseJson(url,postData,onSuccess,onTransportError);
}
function createSubscriptionToTags(tags,secureTokenCallback){
var url="/subscription_ajax";
var onSuccess=function(data){
var errors=data.errors;
if(errors.length>0){
yt.EventManager.fireEvent("SubscriptionCreatedError",errors.pop());
}else{
yt.EventManager.fireEvent("SubscriptionCreated",data.response);
}
}
var postData={};
postData['action_create_subscription_to_tags']=1;
postData['t']=tags;
postData['session_token']=secureTokenCallback('subscription_ajax');
postAjaxResponseJson(url,postData,onSuccess,onTransportError);
}
function createSubscriptionToUser(username,secureTokenCallback){
var url="/subscription_ajax";
var onSuccess=function(data){
var errors=data.errors;
if(errors.length>0){
yt.EventManager.fireEvent("SubscriptionCreatedError",errors.pop());
}else{
yt.EventManager.fireEvent("SubscriptionCreated",data.response);
}
}
var postData={};
postData['action_create_subscription_to_user']=1;
postData['u']=username;
postData['session_token']=secureTokenCallback('subscription_ajax');
postAjaxResponseJson(url,postData,onSuccess,onTransportError);
}
function disableRevenueShareOnVideos(ids,secureTokenCallback){
var url="/video_ajax";
var onSuccess=function(data){
var errors=data.errors;
if(errors.length>0){
yt.EventManager.fireEvent("RevenueShareOnVideosDisabledError",errors.pop());
}else{
yt.EventManager.fireEvent("RevenueShareOnVideosDisabled",ids);
}
}
var postData={};
postData['action_disable_revenue_sharing_on_videos']=1;
postData['v']=ids.join(",");
postData['session_token']=secureTokenCallback('video_ajax');
postAjaxResponseJson(url,postData,onSuccess,onTransportError);
}
function disableDownloadOptionOnVideos(ids,agreement_type,secureTokenCallback){
var url="/video_ajax";
var onSuccess=function(data){
var errors=data.errors;
if(errors.length>0){
yt.EventManager.fireEvent("DownloadOptionOnVideosDisabledError",errors.pop());
}else{
yt.EventManager.fireEvent("DownloadOptionOnVideosDisabled",ids);
}
}
var postData={};
postData['action_disable_download_option_on_videos']=1;
postData['v']=ids.join(",");
postData['agreement_type']=agreement_type;
postData['session_token']=secureTokenCallback('video_ajax');
postAjaxResponseJson(url,postData,onSuccess,onTransportError);
}
function onKeyDownHandler(e,src,callback){
var key;
if(window.event){
key=e.keyCode;
}else if(e.which){
key=e.which;
}
callback(key,src);
}
bind=function(fn,self,var_args){
var boundArgs=fn.boundArgs_;
if(arguments.length>2){
var args=Array.prototype.slice.call(arguments,2);
if(boundArgs){
args.unshift.apply(args,boundArgs);
}
boundArgs=args;
}
self=fn.boundSelf_||self;
fn=fn.boundFn_||fn;
var newfn;
if(boundArgs){
newfn=function(){
var args=Array.prototype.slice.call(arguments);
args.unshift.apply(args,boundArgs);
return fn.apply(self,args);
}
}else{
newfn=function(){
return fn.apply(self,arguments);
}
}
newfn.boundArgs_=boundArgs;
newfn.boundSelf_=self;
newfn.boundFn_=fn;
return newfn;
};
Function.prototype.bind=function(self,var_args){
if(arguments.length>1){
var args=Array.prototype.slice.call(arguments,1);
args.unshift(this,self);
return bind.apply(null,args);
}else{
return bind(this,self);
}
};
Function.prototype.inherits=function(parentCtor){
inherits(this,parentCtor);
};
inherits=function(childCtor,parentCtor){
function tempCtor(){};
tempCtor.prototype=parentCtor.prototype;
childCtor.superClass_=parentCtor.prototype;
childCtor.prototype=new tempCtor();
childCtor.prototype.constructor=childCtor;
};
var goog=window.goog?window.goog:{};
window.goog=goog;
goog.typeOf=function(value){
var s=typeof value;
if(s=='object'){
if(value){
if(typeof value.length=='number'&&
typeof value.splice=='function'&&
typeof value.propertyIsEnumerable=='function'&&
!value.propertyIsEnumerable('length')){
return 'array';
}
}else{
return 'null';
}
}
return s;
};
function htmlEscape(str){
var result=str;
result=result.replace(/&/g,'&amp;');
result=result.replace(/</g,'&lt;');
result=result.replace(/>/g,'&gt;');
return result;
}
window.YT_stats_zippy=function(id,ajaxUrl,loginUrl,opt_cookie_flag,opt_onexpand,opt_onminimize){
this.id_=id;
this.url_=ajaxUrl;
this.loginUrl_=loginUrl;
this.div_content_=_gel(id+"-content");
this.div_contentClosed_=_gel(id+"-content-closed");
this.div_bottomCapOpen_=_gel(id+"-bcap-open");
this.div_bottomCapClosed_=_gel(id+"-bcap-closed");
this.div_arrowRight_=_gel(id+"-arrowRight");
this.div_arrowDown_=_gel(id+"-arrowDown");
this.div_titleBtmClose_=_gel(id+"-titleBtmClose");
this.div_titleBtmOpen_=_gel(id+"-titleBtmOpen");
this.div_title_=_gel(id+"-title");
this.div_titleText_=_gel(id+"-titleText");
this.div_arrowRight_.onmousedown=function(){this.expand();}.bind(this);
this.div_arrowDown_.onmousedown=function(){this.minimize();}.bind(this);
this.div_titleText_.onmousedown=function(){this.toggleState();}.bind(this);
this.onexpand_=opt_onexpand;
this.onminimize_=opt_onminimize;
this.cookie_flag_=opt_cookie_flag;
if(this.cookie_flag_){
try{
var collapsed=yt.UserPrefs.getFlag(this.get_state_cookie_name());
if(collapsed){
this.minimize();
}else{
this.expand();
}
}catch(e){
}
}
};
YT_stats_zippy.prototype.minimizeForeignZippies=function(zippyList){
for(var i=0;i<zippyList.length;++i){
var cz=zippyList[i];
if(cz&&cz!=this&&cz.isExpanded()){
cz.minimize();
}
}
};
YT_stats_zippy.prototype.get_state_cookie_name=function(){
return yt.UserPrefs.Flags[this.cookie_flag_];
};
YT_stats_zippy.prototype.save_state=function(state){
if(this.cookie_flag_){
try{
yt.UserPrefs.setFlag(this.get_state_cookie_name(),state);
yt.UserPrefs.save();
}catch(e){
}
}
};
YT_stats_zippy.prototype.isExpanded=function(){
return(this.div_arrowRight_.style.display=="none");
};
YT_stats_zippy.prototype.toggleState=function(){
if(this.isExpanded()){
this.minimize();
}else{
this.expand();
}
};
YT_stats_zippy.prototype.expandUI=function(){
this.div_arrowRight_.style.display="none";
this.div_arrowDown_.style.display="inline";
this.div_content_.style.display="block";
if(this.div_contentClosed_){
this.div_contentClosed_.style.display="none";
}
_addclass(this.div_title_,'statModule-title-open');
if(this.div_titleBtmClose_&&this.div_titleBtmOpen_){
this.div_titleBtmClose_.style.display="none";
this.div_titleBtmOpen_.style.display="block";
}
if(this.div_bottomCapOpen_&&this.div_bottomCapClosed_){
this.div_bottomCapClosed_.style.display="none";
this.div_bottomCapOpen_.style.display="block";
}
}
YT_stats_zippy.prototype.expand=function(){
this.save_state(false);
this.expandUI();
if(this.div_content_.innerHTML.match(/^\s*$/)&&this.url_){
this.ajax_fetch();
}
if(typeof this.onexpand_=='function'){
this.onexpand_(this);
}
};
YT_stats_zippy.prototype.ajax_fetch=function(){
this.div_content_.innerHTML='<div style="text-align: center; margin: 35px;"><img src="http://s.ytimg.com/yt/img/icn_loading_animated-vfl24663.gif"></div>';
var handleResponse=function(xhr){
this.handleAjaxResponse(
xhr,
this.div_content_,
this.loginUrl_
);
}.bind(this);
var fetchContent=function(){
yt.net.ajax.sendRequest(this.url_,{method:"GET",onComplete:handleResponse});
}.bind(this);
setTimeout(fetchContent,0);
};
YT_stats_zippy.prototype.minimizeUI=function(){
this.div_arrowRight_.style.display="inline";
this.div_arrowDown_.style.display="none";
this.div_content_.style.display="none";
if(this.div_contentClosed_){
this.div_contentClosed_.style.display="";
}
_removeclass(this.div_title_,'statModule-title-open');
if(this.div_titleBtmClose_&&this.div_titleBtmOpen_){
this.div_titleBtmClose_.style.display="block";
this.div_titleBtmOpen_.style.display="none";
}
if(this.div_bottomCapOpen_&&this.div_bottomCapClosed_){
this.div_bottomCapClosed_.style.display="block";
this.div_bottomCapOpen_.style.display="none";
}
}
YT_stats_zippy.prototype.minimize=function(){
this.save_state(true);
this.minimizeUI();
if(typeof this.onminimize_=='function'){
this.onminimize_(this);
}
};
YT_stats_zippy.prototype.flashUI=function(){
if(this.isExpanded()){
this.minimizeUI();
this.expandUI();
}else{
this.expandUI();
this.minimizeUI();
}
}
YT_stats_zippy.prototype.handleAjaxResponse=function(xmlHttpRequest,content,loginUrl){
if(xmlHttpRequest.readyState==4){
if(xmlHttpRequest.status==200){
content.innerHTML=xmlHttpRequest.responseText;
}else if(xmlHttpRequest.status==401){
window.location.pathname=loginUrl;
}else{
if(this.error_page_){
var error_page=_gel(this.error_page_);
content.innerHTML=error_page.innerHTML;
}
}
}
};
(function(){
var YT_cache=function(opt_max_age){
this.cache_=new Object();
this.timestamp_=new Object();
if(!opt_max_age||opt_max_age<0){
opt_max_age=-1
}
this.expiration_diff_=opt_max_age;
}
window.YT_cache=YT_cache;
YT_cache.prototype.put=function(key,value){
if(key==undefined||value==undefined){
return null;
}
this.cache_[key]=value;
this.timestamp_[key]=new Date();
}
YT_cache.prototype.get=function(key,opt_default_value){
if(this.contains(key)){
return this.cache_[key];
}else{
return opt_default_value;
}
}
YT_cache.prototype.invalidate=function(){
this.cache_=new Object();
};
YT_cache.prototype.contains=function(key){
var contains_key=(this.cache_[key]!=null&&this.cache_[key]!=undefined);
return contains_key&&!this.isExpired(key);
}
YT_cache.prototype.isExpired=function(key){
var currDate=new Date();
if(this.expiration_diff_!=-1&&currDate-this.timestamp_[key]>this.expiration_diff_){
return true;
}
return false;
}
})();
(function(){
var AjaxQueue=function(url,opt_session_param,opt_get){
this.messages_=[];
this.logging_info_=[];
this.url_=url;
this.post_=!opt_get;
this.session_param_=opt_session_param;
this.last_delivery_=(new Date()).getTime();
this.response_handlers_={};
this.outstanding_delivery_=null;
this.idle_send_messages_timeout_=null;
this.delivery_timeout_=null;
this.error_handler_=null;
this.add_unload_handler();
};
window.AjaxQueue=AjaxQueue;
var MAX_DELAY_BEFORE_DELIVERY=15000;
var MAX_UNSENT_MESSAGES=10;
var MAGIC_PREFIX="while(1);";
AjaxQueue.prototype.add_unload_handler=function(){
var old_unload=function(){};
if(window.onunload){
old_unload=window.onunload;
}
var aq=this;
window.onunload=function(){
if(aq.messages_&&aq.messages_.length>0){
aq.deliver_messages();
}
old_unload();
};
};
AjaxQueue.prototype.should_send_messages_=function(){
var time_to_go=(new Date()).getTime()-this.last_delivery_>MAX_DELAY_BEFORE_DELIVERY;
var too_many=this.messages_.length>MAX_UNSENT_MESSAGES;
return time_to_go||too_many;
};
AjaxQueue.prototype.set_timeout_=function(){
if(this.should_send_messages_()){
this.deliver_messages();
}else{
this.idle_send_messages_timeout_=window.setTimeout(function(){this.set_timeout_();}.bind(this),5000);
}
};
AjaxQueue.prototype.send_message=function(message,type,opt_critical,opt_logging_info){
var real_message={'type':type,'request':message};
this.messages_.push(real_message);
if(opt_logging_info){
this.logging_info_.push(opt_logging_info)
}
if(opt_critical||this.should_send_messages_()){
this.deliver_messages();
}else if(!this.idle_send_messages_timeout_){
this.set_timeout_();
}
};
AjaxQueue.prototype.quick_send=function(message,type,callback,opt_logging_info){
var real_message={'type':type,'request':message};
var successCallback=function(response){
var responseText=response.responseText.substring(MAGIC_PREFIX.length);
if(this.check_redirect_or_reload(responseText)){
return;
}
var responses;
try{
responses=goog.json.unsafeParse(responseText);
}catch(e){
this.report_error(status,yt.getMsg('BAD_RESPONSE'));
return;
}
for(var i=0;i<responses.length;i++){
var response=responses[i];
if(response.type==type){
callback(response);
}
}
}.bind(this);
var error_callback=function(response){
this.report_error(status,yt.getMsg('UNABLE_TO_CONTACT_SERVER'));
}.bind(this);
this.contact_server([real_message],successCallback,error_callback,opt_logging_info?[opt_logging_info]:null);
};
AjaxQueue.prototype.register_handler=function(type,handler){
this.response_handlers_[type]=handler;
};
AjaxQueue.prototype.register_error_handler=function(handler){
this.error_handler_=handler;
};
AjaxQueue.prototype.report_error=function(http_code,error_message){
if(this.error_handler_){
this.error_handler_(http_code,error_message);
}else{
alert(error_message);
}
};
AjaxQueue.prototype.handle_message_responses_=function(responses){
if(!responses)return;
for(var i in responses){
var response=responses[i];
if(response.type&&this.response_handlers_[response.type]){
this.response_handlers_[response.type](response);
}
}
};
var REDIRECT_COMMAND="LOGIN_REDIRECT:";
var RELOAD_COMMAND="RELOAD_PAGE:";
AjaxQueue.prototype.redirect_login=function(url){
url="/login?next="+encodeURIComponent(url);
window.location.href=url;
};
AjaxQueue.prototype.reload_page=function(url){
var href=window.location.href;
if(href.indexOf(url)!=href.length-url.length){
window.location.href=url;
}else{
window.location.reload(true);
}
};
AjaxQueue.prototype.check_redirect_or_reload=function(responseText){
if(responseText.indexOf(REDIRECT_COMMAND)==0){
this.redirect_login(responseText.substring(REDIRECT_COMMAND.length));
return true;
}
if(responseText.indexOf(RELOAD_COMMAND)==0){
this.reload_page(responseText.substring(RELOAD_COMMAND.length));
return true;
}
return false;
}
AjaxQueue.prototype.deliver_messages=function(){
if(this.outstanding_delivery_){
this.redelivery_=true;
return;
}
this.redelivery_=false;
if(this.idle_send_messages_timeout_){
window.clearTimeout(this.idle_send_messages_timeout_);
this.idle_send_messages_timeout_=null;
}
var callback=function(response){
var responseText=response.responseText.substring(MAGIC_PREFIX.length);
if(this.check_redirect_or_reload(responseText)){
return;
}
var responses;
try{
responses=goog.json.unsafeParse(responseText);
}catch(e){
this.report_error(status,yt.getMsg('BAD_RESPONSE'));
return;
}
this.handle_message_responses_(responses);
if(this.redelivery_){
window.setTimeout(function(){
this.deliver_messages();}.bind(this),10);
}
this.outstanding_delivery_=null;
this.last_delivery_=(new Date()).getTime();
}.bind(this);
var error_callback=function(response){
if(this.outstanding_delivery_){
this.messages_=this.outstanding_delivery_.concat(this.messages_);
}
this.report_error(status,yt.getMsg('UNABLE_TO_CONTACT_SERVER'));
this.outstanding_delivery_=null;
this.last_delivery_=(new Date()).getTime();
}.bind(this);
this.contact_server(this.messages_,callback,error_callback,this.logging_info_);
this.outstanding_delivery_=this.messages_;
this.messages_=[];
this.logging_info_=[];
};
AjaxQueue.prototype.contact_server=function(messages,callback,error_callback,opt_logging_info){
var message_param="messages="+encodeURIComponent(goog.json.serialize(messages));
var url=this.url_;
if(opt_logging_info&&opt_logging_info.length>0){
url+='&'+opt_logging_info.join('&');
}
if(this.post_){
if(this.session_param_){
yt.net.ajax.sendRequest(url,{postBody:this.session_param_+"&"+message_param,onComplete:callback,onException:error_callback});
}else{
yt.net.ajax.sendRequest(url,{postBody:message_param,onComplete:callback,onException:error_callback});
}
}else{
yt.net.ajax.sendRequest(url+"&"+message_param,{method:"GET",onComplete:callback,onException:error_callback});
}
};
})();
(function(){
window.goog=window.goog?window.goog:{};
var goog=window.goog;
goog.json={};
goog.json.isValid_=function(s){
if(s==''){
return false;
}
s=s.replace(/"(\\.|[^"\\])*"/g,'');
return s==''||!/[^,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]/.test(s);
};
goog.json.parse=function(s){
s=String(s);
if(typeof s.parseJSON=='function'){
return s.parseJSON();
}
if(goog.json.isValid_(s)){
try{
return eval('('+s+')');
}catch(ex){
}
}
throw Error('Invalid JSON string: '+s);
};
goog.json.unsafeParse=function(s){
return eval('('+s+')');
};
goog.json.serializer_=null;
goog.json.serialize=function(object){
if(!goog.json.serializer_){
goog.json.serializer_=new goog.json.Serializer;
}
return goog.json.serializer_.serialize(object);
};
goog.json.Serializer=function(){
};
goog.json.Serializer.prototype.serialize=function(object){
if(object!=null&&typeof object.toJSONString=='function'){
return object.toJSONString();
}
var sb=[];
this.serialize_(object,sb);
return sb.join('');
};
goog.json.Serializer.prototype.serialize_=function(object,sb){
switch(goog.typeOf(object)){
case 'string':
this.serializeString_(object,sb);
break;
case 'number':
this.serializeNumber_(object,sb);
break;
case 'boolean':
sb.push(object);
break;
case 'undefined':
sb.push('null');
break;
case 'null':
sb.push('null');
break;
case 'array':
this.serializeArray_(object,sb);
break;
case 'object':
this.serializeObject_(object,sb);
break;
default:
throw Error('Unknown type: '+typeof object);
}
};
goog.json.Serializer.charToJsonCharCache_={
'\"':'\\"',
'\\': '\\\\',
'/':'\\/',
'\b':'\\b',
'\f':'\\f',
'\n':'\\n',
'\r':'\\r',
'\t':'\\t',
'\x0B':'\\u000b'
};
goog.json.Serializer.prototype.serializeString_=function(s,sb){
sb.push('"',s.replace(/[\\\"\x00-\x1f\x80-\uffff]/g,function(c){
if(c in goog.json.Serializer.charToJsonCharCache_){
return goog.json.Serializer.charToJsonCharCache_[c];
}
var cc=c.charCodeAt(0);
var rv='\\u';
if(cc<16){
rv+='000';
}else if(cc<256){
rv+='00';
}else if(cc<4096){
rv+='0';
}
return goog.json.Serializer.charToJsonCharCache_[c]=rv+cc.toString(16);
}),'"');
};
goog.json.Serializer.prototype.serializeNumber_=function(n,sb){
sb.push(isFinite(n)&&!isNaN(n)?n:'null');
};
goog.json.Serializer.prototype.serializeArray_=function(arr,sb){
var l=arr.length;
sb.push('[');
var sep='';
for(var i=0;i<l;i++){
sb.push(sep)
this.serialize_(arr[i],sb);
sep=',';
}
sb.push(']');
};
goog.json.Serializer.prototype.serializeObject_=function(obj,sb){
sb.push('{');
var sep='';
for(var key in obj){
sb.push(sep);
this.serializeString_(key,sb);
sb.push(':');
this.serialize_(obj[key],sb);
sep=',';
}
sb.push('}');
};
})();
(function(){
window.updateEllipses=function(opt_el){
if(navigator.userAgent.indexOf('Firefox')==-1){
return;
}
if(!(opt_el.getElementsByTagName)){
opt_el=null;
}
var els=goog.dom.getElementsByTagNameAndClass('div','ellipsis',opt_el);
for(var i=els.length-1;i>=0;i--){
setupEllipsis(els[i]);
}
};
function setupEllipsis(el){
if(!el.__span){
var dots=document.createElement('div');
dots.appendChild(document.createTextNode('...'));
dots.style.display='none';
el.appendChild(dots);
if(el.className){
dots.className=el.className.replace('ellipsis','ellipsis-dots');
}
var ds=dots.style;
el.__dotstyle=ds;
el.__span=el.getElementsByTagName('span')[0]||el.getElementsByTagName('a')[0];
el.addEventListener("overflow",function(e){handleEllipsis(el)},false);
el.addEventListener("underflow",function(e){handleEllipsis(el)},false);
}
handleEllipsis(el);
};
function handleEllipsis(el){
window.setTimeout(function(){
if(el.clientWidth==0)return;
el.__dotstyle.display=
(el.__span.scrollWidth>=el.clientWidth)?'block':'none';
},5);
}
function getStyle(el,styleProp){
var y=null;
if(el.currentStyle){
y=el.currentStyle[styleProp];
}else if(window.getComputedStyle){
var computed=document.defaultView.getComputedStyle(el,'');
var hyphen=toHyphen(styleProp);
if(computed&&computed.getPropertyValue(hyphen)){
y=computed.getPropertyValue(hyphen);
}
}
return y;
}
function toHyphen(property){
if(property.indexOf('-')>-1){
return property;
}
var converted='';
var len=property.length;
for(var i=0;i<len;i++){
if(property.charAt(i)==property.charAt(i).toUpperCase()){
converted=converted+'-'+property.charAt(i).toLowerCase();
}else{
converted=converted+property.charAt(i);
}
}
return converted;
}
window.initEllipsis=function(){
var sTextOverFlow=getStyle(document.body,'textOverflow');
if(typeof(sTextOverFlow)=='string'||!document.getBoxObjectFor){
return;
}
window.setTimeout(window.updateEllipses,5);
}
yt.pubsub.subscribe('init',window.initEllipsis);
})();
(function(){
var MAX_CACHE_AGE=60000;
var MAX_MESSAGE_HISTORY=40;
var YTInbox=function(session_param,read_only_mode,message_pane,opt_error_pane){
this.aq_=new AjaxQueue("/inbox?action_ajax=1",session_param);
this.aq_.register_handler("display_messages",(function(response){this.handle_messages(response)}).bind(this));
this.aq_.register_handler("send_message",(function(response){this.message_sent(response)}).bind(this));
this.aq_.register_handler("accept_messages",(function(response){this.generic_response(response)}).bind(this));
this.aq_.register_handler("accept_message",(function(response){this.generic_response(response)}).bind(this));
this.aq_.register_handler("ignore_messages",(function(response){this.generic_response(response)}).bind(this));
this.aq_.register_handler("ignore_message",(function(response){this.generic_response(response)}).bind(this));
this.aq_.register_handler("delete_messages",(function(response){this.generic_response(response)}).bind(this));
this.aq_.register_handler("delete_message",(function(response){this.generic_response(response)}).bind(this));
this.aq_.register_handler("mark_as_spam",(function(response){this.generic_response(response)}).bind(this));
this.aq_.register_handler("block_user",(function(response){this.generic_response(response)}).bind(this));
this.aq_.register_error_handler(YTInbox.prototype.handle_error.bind(this));
this.cache_=new YT_cache(MAX_CACHE_AGE);
this.read_only_mode_=read_only_mode;
this.marked_as_deleted_=[];
this.marked_as_read_=[];
this.message_pane_=message_pane;
this.unread_counts_={};
this.ignore_responses={};
this.outstanding_folder_request_=null;
this.error_pane_=opt_error_pane;
this.num_error_retries_=0;
};
window.YTInbox=YTInbox;
function array_contains(array,elem){
for(var i=0;i<array.length;i++){
if(array[i]==elem){
return true;
}
}
return false;
};
YTInbox.prototype.remove_message=function(message_id,opt_delay_server_call){
if(!array_contains(this.marked_as_deleted_,message_id)&&!this.read_only_mode_){
this.marked_as_deleted_.unshift(message_id);
this.marked_as_deleted_=this.marked_as_deleted_.slice(0,MAX_MESSAGE_HISTORY);
var message=_gel("msg-"+message_id);
if(_hasclass(message,'unread')){
this.decrement_unread_count(message_id,opt_delay_server_call);
}
}
if(!opt_delay_server_call){
this.display_messages(current_folder_name,start);
}
};
YTInbox.prototype.remove_messages=function(message_ids){
for(var idx=0;idx<message_ids.length;idx++){
this.remove_message(message_ids[idx],true);
}
this.show_unread_counts();
this.display_messages(current_folder_name,start);
};
YTInbox.prototype.decrement_unread_count=function(message_id,opt_no_update){
var temp=message_id.split('.');
var folder=temp[0];
var count=this.unread_counts_[folder];
count--;
if(count<0){
count=0;
}
this.unread_counts_[folder]=count;
if(!opt_no_update){
this.show_unread_counts();
}
};
YTInbox.prototype.show_unread_counts=function(){
this.unread_counts_['inbox']=this.unread_counts_['messages']+this.unread_counts_['videos']+this.unread_counts_['comments']+this.unread_counts_['responses']+this.unread_counts_['invites'];
for(var folder in this.unread_counts_){
var count=this.unread_counts_[folder];
if(_gel("tab-"+folder)){
_gel("tab-"+folder+"-unread").innerHTML=count?"("+count+")":"";
if(count>0){
_addclass(_gel("tab-"+folder),"folder_unread");
}else{
_removeclass(_gel("tab-"+folder),"folder_unread");
}
}
}
};
YTInbox.prototype.mark_as_read=function(message_id){
if(!array_contains(this.marked_as_read_,message_id)&&!this.read_only_mode_){
this.marked_as_read_.unshift(message_id);
this.marked_as_read_=this.marked_as_read_.slice(0,MAX_MESSAGE_HISTORY);
this.aq_.send_message({'message_id':message_id},'mark_as_read');
this.decrement_unread_count(message_id);
this.clear_cache();
}
};
YTInbox.prototype.mark_as_spam=function(message_id){
this.aq_.send_message({'message_id':message_id},'mark_as_spam');
this.remove_message(message_id);
};
YTInbox.prototype.delete_message=function(message_id){
this.aq_.send_message({'message_id':message_id},'delete_message');
this.remove_message(message_id);
};
YTInbox.prototype.delete_messages=function(message_ids){
this.aq_.send_message({'message_ids':message_ids},'delete_messages');
this.remove_messages(message_ids);
};
YTInbox.prototype.accept_message=function(message_id){
this.aq_.send_message({'message_id':message_id},'accept_message');
this.remove_message(message_id);
};
YTInbox.prototype.ignore_message=function(message_id){
this.aq_.send_message({'message_id':message_id},'ignore_message');
this.remove_message(message_id);
};
YTInbox.prototype.accept_messages=function(message_ids){
this.aq_.send_message({'message_ids':message_ids},'accept_messages');
this.remove_messages(message_ids);
};
YTInbox.prototype.ignore_messages=function(message_ids){
this.aq_.send_message({'message_ids':message_ids},'ignore_messages');
this.remove_messages(message_ids);
};
YTInbox.prototype.block_user=function(nemesis_id){
this.aq_.send_message({'nemesis_id':nemesis_id},'block_user');
};
YTInbox.prototype.clear_cache=function(){
this.cache_.invalidate();
};
YTInbox.prototype.generic_response=function(response){
if(response.data&&response.data.message){
this.display_error(response.data.message,response.data.success);
if(window.pmsForwarder&&response.data.pms_notify_tokens){
pmsForwarder.notifyChanges(response.data.pms_notify_tokens);
};
}else if(response.errors&&response.errors.length>0){
this.display_error(response.errors.join('\n'));
}
};
var DEFAULT_NUM=20;
function make_key(request){
return request.folder+"-"+request.start;
}
YTInbox.prototype.display_message=function(folder,message_id){
var request={};
request.folder=folder;
request.start=0;
request.num=DEFAULT_NUM;
request.message_id=message_id;
this.aq_.send_message(request,'display_messages',true,'folder='+folder);
this.message_pane_.innerHTML=LOADING_GRAPHIC;
cur_open_message=null;
};
YTInbox.prototype.display_messages=function(folder,start,opt_num,opt_cacheable){
this.clear_error_display();
if(this.outstanding_folder_request_){
if(this.outstanding_folder_request_.folder==folder){
return;
}
this.ignore_responses[make_key(this.outstanding_folder_request_)]=true;
}
this.display_pagination(false);
var request={};
request.folder=folder;
request.start=start;
if(opt_num){
request.num=opt_num;
}else{
request.num=DEFAULT_NUM;
}
request.messages_deleted=this.marked_as_deleted_;
request.messages_read=this.marked_as_read_;
var key=make_key(request);
this.outstanding_folder_request_=request;
if(opt_cacheable&&this.cache_.contains(key)){
window.setTimeout(function(){
this.handle_messages(this.cache_.get(key),true);
}.bind(this),5);
}else{
this.aq_.send_message(request,'display_messages',true,"folder="+folder);
this.message_pane_.innerHTML=LOADING_GRAPHIC;
}
cur_open_message=null;
};
YTInbox.prototype.handle_messages=function(response,opt_cached){
if(!opt_cached){
this.cache_.put(make_key(response.request),response);
}
if(this.ignore_responses[make_key(response.request)]){
this.ignore_responses[make_key(response.request)]=false;
return;
}
if(this.message_pane_&&response.data&&response.data.success){
this.unread_counts_=response.data.unread_counts;
this.show_unread_counts();
this.update_pagination_(response.data.pagination);
this.message_pane_.innerHTML=response.data.message_pane;
window.setTimeout(initEllipsis,10);
if(response.data.message_id){
var message_id=response.data.message_id;
window.setTimeout(function(){
inbox.open_message(message_id);
},1);
}
}else{
this.handle_error(200,yt.getMsg('UNABLE_TO_PROCESS_MESSAGES'));
}
if(response.data.error){
this.handle_error(200,response.data.error);
}
this.num_error_retries_=0;
this.outstanding_folder_request_=null;
};
var CLEAR_ERROR_DELAY=10000;
YTInbox.prototype.display_error=function(message,opt_good_message){
this.clear_error_display();
if(this.error_pane_){
var pane=this.error_pane_;
if(opt_good_message){
pane.style.background="#d1f0b4";
}else{
pane.style.background="#ffadaf";
}
pane.childNodes[0].nodeValue=message;
pane.style.display="";
ani.fadeAndSlideUp(pane,ani.DEFAULT_MESSAGE_DELAY,
ani.DEFAULT_MESSAGE_FADEOUT,ani.DEFAULT_MESSAGE_SLIDE);
}
};
YTInbox.prototype.clear_error_display=function(){
if(this.error_pane_){
var pane=this.error_pane_;
endAnimations(pane.parentNode);
}
};
YTInbox.prototype.handle_error=function(status,message){
this.display_error(message);
if(inbox.composition){
inbox.composition.handle_error();
}
};
YTInbox.prototype.display_pagination=function(visible){
inbox.update_buttons();
for(var idx=0;idx<2;idx++){
_gel("pagination-"+idx).style.display=visible?"":"none";
}
};
YTInbox.prototype.update_pagination_=function(pagination){
if(!pagination){
return;
}
if(!inbox.composition){
this.display_pagination(true);
}
for(var idx=0;idx<2;idx++){
if(pagination.end>pagination.start){
_gel("page-start-"+idx).innerHTML=pagination.start+1;
_gel("page-end-"+idx).innerHTML=pagination.end;
_gel("page-numbers-"+idx).style.display="";
}else{
_gel("page-numbers-"+idx).style.display="none";
}
_gel("page-next-"+idx).style.display=pagination.has_next?"":"none";
_gel("page-prev-"+idx).style.display=pagination.has_prev?"":"none";
}
start=pagination.start;
};
YTInbox.prototype.check_send_field_for_content=function(field_content,error_message){
if(!field_content||/^\s*$/.test(field_content)){
window.setTimeout(function(){
var response={};
response.data={};
response.data.success=false;
response.data.message=error_message;
this.message_sent(response);
}.bind(this),250);
return true;
}
return false;
};
YTInbox.prototype.send_message=function(to_users,to_all_subscribers,subject,video_id,message_text,in_reply_to){
if(this.check_send_field_for_content(to_users,yt.getMsg('ERROR_NO_RECIPIENTS'))||
this.check_send_field_for_content(subject,yt.getMsg('ERROR_NO_SUBJECT'))||
this.check_send_field_for_content(message_text,yt.getMsg('ERROR_NO_MESSAGE_TEXT'))){
return;
}
var request={};
request.to_users=to_users;
request.to_all_subscribers=to_all_subscribers;
request.subject=subject;
if(video_id){
request.video_id=video_id;
}
if(in_reply_to){
request.in_reply_to=in_reply_to;
}
request.message_text=message_text;
this.aq_.send_message(request,'send_message',true);
};
YTInbox.prototype.message_sent=function(response){
if(response.data&&response.data!=""){
if(!response.data.success){
this.handle_error(200,response.data.message);
inbox.composition.handle_error();
}else{
this.display_error(response.data.message,true);
inbox.close_composition();
}
}
};
var inbox={};
window.inbox=inbox;
inbox.MESSAGE_ANIMATE_SPEED=1000;
inbox.setup_autocomplete=function(){
inbox.actb=actb(_gel('compose_to'),friends_array);
inbox.actb.actb_delimiter=new Array()
inbox.actb.actb_startcheck=1;
window.update_addresses=function(addresses){
inbox.actb.actb_keywords=addresses;
}
};
inbox.initialize=function(session_param,read_only_mode,message_pane_id,tab_sent_id,checkbox_all_id,error_box_id,opt_compose_mode,opt_compose_users,opt_message_all_subscribers){
yt.pubsub.subscribe('init',function(){
inbox.read_only_mode_=read_only_mode;
inbox.message_pane_=_gel(message_pane_id);
inbox.tab_sent_id_=tab_sent_id;
inbox.checkbox_all_=_gel(checkbox_all_id);
inbox.error_pane_=_gel(error_box_id);
inbox.compose_pane=_gel("message_composing");
inbox.yt_inbox=new YTInbox(session_param,read_only_mode,inbox.message_pane_,inbox.error_pane_);
inbox.loaded_first_time=false;
History.initialize();
inbox.load_folder_from_url();
if(opt_compose_mode){
inbox.compose();
if(opt_compose_users){
inbox.composition.set_to_address(opt_compose_users);
}
if(opt_message_all_subscribers){
inbox.select_all_subscribers();
}
}
inbox.setup_autocomplete();
});
};
inbox.handleHistory=function(hash,data){
if(!inbox.loaded_first_time){
inbox.preload_folder=hash;
return;
}
if(hash==""){
hash="inbox";
}
inbox.open_folder(_gel("tab-"+hash),false,true);
};
var cur_open_message=null;
inbox.open_message=function(id,is_unread){
if(id==cur_open_message){
inbox.close_message(id);
return;
}else if(cur_open_message){
inbox.close_message(cur_open_message);
}
var message=_gel('msg-'+id);
var closedSubject=_gel('msg-'+id+'-subject-closed');
var openSubject=_gel('msg-'+id+'-subject-open');
var openSubjectLine=_gel('msg-'+id+'-subject-line-open');
var closedFrom=_gel('msg-'+id+'-from-closed');
var openFrom=_gel('msg-'+id+'-from-open');
endAnimations(message);
_addclass(message,'open');
_removeclass(message,'closed');
function onAnimationComplete(){
if(!inbox.read_only_mode_){
_removeclass(message,'unread');
}
}
var data=ani.crossfadeReveal(closedSubject,openSubjectLine,openSubject,
inbox.MESSAGE_ANIMATE_SPEED,null,onAnimationComplete);
ani.crossfadeReveal(closedFrom,null,openFrom,inbox.MESSAGE_ANIMATE_SPEED,data.height);
cur_open_message=id;
if(is_unread&&!inbox.is_sent_messages){
inbox.yt_inbox.mark_as_read(id);
}
window.setTimeout(function(){
if(document.selection){
document.selection.empty();
}else if(window.getSelection){
window.getSelection().removeAllRanges();
}
},0);
var data=History.getSecretData()||{};
data['message_id']=id
History.setSecretData(data);
};
inbox.close_message=function(id){
var message=_gel('msg-'+id);
var closedSubject=_gel('msg-'+id+'-subject-closed');
var openSubject=_gel('msg-'+id+'-subject-open');
var openSubjectLine=_gel('msg-'+id+'-subject-line-open');
var closedFrom=_gel('msg-'+id+'-from-closed');
var openFrom=_gel('msg-'+id+'-from-open');
endAnimations(message);
function onAnimationComplete(){
_removeclass(message,'open');
_addclass(message,'closed');
}
var data=ani.crossfadeRevealUndo(closedSubject,openSubjectLine,
openSubject,inbox.MESSAGE_ANIMATE_SPEED,null,onAnimationComplete);
ani.crossfadeRevealUndo(closedFrom,null,openFrom,inbox.MESSAGE_ANIMATE_SPEED,data.height);
cur_open_message=null;
var data=History.getSecretData()||{};
data['message_id']=null;
History.setSecretData(data);
};
inbox.delete_message=function(id){
inbox.yt_inbox.delete_message(id);
return false;
};
inbox.mark_as_spam=function(id){
inbox.yt_inbox.mark_as_spam(id);
return false;
};
inbox.accept_message=function(id){
inbox.yt_inbox.accept_message(id);
return false;
};
inbox.ignore_message=function(id){
inbox.yt_inbox.ignore_message(id);
return false;
};
inbox.block_user=function(nemesis_id,message_id){
inbox.yt_inbox.block_user(nemesis_id);
inbox.yt_inbox.delete_message(message_id);
return false;
};
inbox.delete_selected=function(){
inbox.yt_inbox.delete_messages(inbox.get_checked_message_ids());
};
inbox.accept_selected=function(){
inbox.yt_inbox.accept_messages(inbox.get_checked_message_ids());
};
inbox.ignore_selected=function(){
inbox.yt_inbox.ignore_messages(inbox.get_checked_message_ids());
};
var start=0;
var current_folder=null;
var current_folder_name="inbox";
inbox.next_page=function(){
start=start+DEFAULT_NUM;
inbox.yt_inbox.display_messages(current_folder_name,start);
var data=History.getSecretData()||{};
data['start']=start
History.setSecretData(data);
return false;
};
inbox.prev_page=function(){
start=Math.max(start-DEFAULT_NUM,0);
inbox.yt_inbox.display_messages(current_folder_name,start);
var data=History.getSecretData()||{};
data['start']=start
History.setSecretData(data);
return false;
};
function is_approvable_folder(folder_name){
return folder_name=="invites"||folder_name=="responses";
}
inbox.update_buttons=function(){
var boxes=inbox.get_message_checkboxes();
var check_main_checkbox=boxes.length>0;
var show_approve_button=is_approvable_folder(current_folder_name);
for(var idx=0;idx<boxes.length;idx++){
var box=boxes[idx];
if(!box.checked){
check_main_checkbox=false;
}else if(!is_approvable_folder(box.id.substring(4,box.id.indexOf('.',4)))){
show_approve_button=false;
}
}
if(show_approve_button){
_gel("inbox_approve_button").style.display="";
_gel("inbox_ignore_button").style.display="";
_gel("inbox_delete_button").style.display="none";
}else{
_gel("inbox_approve_button").style.display="none";
_gel("inbox_ignore_button").style.display="none";
_gel("inbox_delete_button").style.display="";
}
};
inbox.compose=function(opt_reply){
_gel("message_reading").style.display="none";
inbox.yt_inbox.display_pagination(false);
inbox.compose_pane.style.display="";
inbox.composition=new Compose(inbox.compose_pane,inbox.yt_inbox);
if(!opt_reply){
inbox.set_folder_title(yt.getMsg('COMPOSE'));
inbox.composition.is_reply=false;
}
if(current_folder){
_removeclass(current_folder,'selected');
}
};
inbox.reply=function(message_id){
inbox.compose(true);
inbox.set_folder_title(yt.getMsg('REPLY'));
inbox.composition.set_reply_fields(message_id);
};
inbox.reply_all=function(message_id){
inbox.compose(true);
inbox.set_folder_title(yt.getMsg('REPLY'));
inbox.composition.set_reply_fields(message_id,true);
};
inbox.select_all_subscribers=function(){
inbox.composition.set_to_address("All subscribers",true);
inbox.composition.set_to_all_subscribers(true);
};
inbox.send_message=function(){
inbox.composition.send();
};
inbox.close_composition=function(){
inbox.composition.close();
inbox.yt_inbox.display_pagination(true);
_gel("message_reading").style.display="";
inbox.compose_pane.style.display="none";
inbox.composition=null;
inbox.set_folder_title();
if(current_folder){
_addclass(current_folder,'selected');
}
};
inbox.get_checked_message_ids=function(){
var boxes=inbox.get_message_checkboxes();
var ids=new Array();
for(var idx=0;idx<boxes.length;idx++){
if(boxes[idx].checked){
ids.push(boxes[idx].id.substring(4));
}
}
return ids;
};
inbox.get_message_checkboxes=function(){
return goog.dom.getElementsByTagNameAndClass("input","message-checkbox");
};
inbox.select_all=function(checkbox){
var boxes=inbox.get_message_checkboxes();
for(var idx=0;idx<boxes.length;idx++){
boxes[idx].checked=checkbox.checked;
}
inbox.update_buttons();
};
inbox.prevent_bubbling=function(event){
if(!event)
var event=window.event;
event.cancelBubble=true;
if(event.stopPropagation)
event.stopPropagation();
};
inbox.select=function(checkbox,event){
inbox.prevent_bubbling(event);
inbox.update_buttons();
};
inbox.uncheck=function(checkbox){
if(checkbox.checked)
checkbox.checked=false;
};
inbox.set_folder_title=function(opt_title){
if(inbox.composition&&!opt_title){
return;
}
if(!opt_title){
opt_title=_gel("tab-"+current_folder_name+"-title").innerHTML;
}
_gel("folder_title").innerHTML=opt_title;
};
var LOADING_GRAPHIC='<table width="100%"><tr><td align="center" valign="middle" colspan="5"><img src="http://s.ytimg.com/yt/img/icn_loading_animated-vfl24663.gif" style="padding-top:150px;"></td></tr></table>';
inbox.open_folder=function(folderlink,opt_suppress_server_call,opt_dont_update_history,opt_start){
if(inbox.composition){
inbox.close_composition();
}
cur_open_message=null;
var cacheable=false;
if(current_folder!=folderlink){
cacheable=true;
if(current_folder){
_removeclass(current_folder,'selected');
}
var id=folderlink.id;
var foldername=id.substring(id.indexOf('-')+1);
current_folder_name=foldername;
current_folder=folderlink;
_addclass(folderlink,'selected');
inbox.set_folder_title();
}
if(!opt_suppress_server_call){
if(!opt_start){
start=0;
}else{
start=opt_start;
}
inbox.yt_inbox.display_messages(current_folder_name,start,null,cacheable);
}
if(!opt_dont_update_history){
var hash=current_folder_name=="inbox"?"":current_folder_name;
var data=History.getSecretData()||{};
data['folder']=current_folder_name;
History.setSecretData(data);
}
return false;
};
inbox.check_history_secrets=function(){
var secret=History.getSecretData();
if(!secret){
return;
}
if(secret.folder){
inbox.preload_folder=secret.folder;
}
if(secret.start){
start=secret.start;
}
if(secret.message_id){
if(!inbox.preload_folder){
inbox.preload_folder="inbox";
}
inbox.preload_message_id=secret.message_id;
}
};
inbox.load_folder_from_url=function(){
inbox.check_history_secrets();
var folder="inbox";
if(inbox.preload_folder){
folder=inbox.preload_folder;
}
if(!_gel("tab-"+folder)){
folder="inbox";
}
if(inbox.preload_folder&&inbox.preload_message_id){
inbox.yt_inbox.display_message(inbox.preload_folder,inbox.preload_message_id);
inbox.open_folder(_gel("tab-"+folder),true,true);
}else{
inbox.open_folder(_gel("tab-"+folder),false,true,start);
}
inbox.loaded_first_time=true;
};
var Compose=function(element,yt_inbox){
this.el_=element;
this.inbox_=yt_inbox;
this.clear();
};
Compose.prototype.update_send_button=function(currently_sending){
if(currently_sending){
_addclass(_gel("inbox_send_message"),"yt-button-disabled");
_gel("inbox_send_message").childNodes[0].nodeValue=yt.getMsg('SENDING');
this.sending_message_=true;
}else{
_removeclass(_gel("inbox_send_message"),"yt-button-disabled");
_gel("inbox_send_message").childNodes[0].nodeValue=yt.getMsg('SEND_MESSAGE');
this.sending_message_=false;
}
};
Compose.prototype.close=function(){
this.clear();
this.update_send_button(false);
};
Compose.prototype.clear=function(){
_hidediv('reply_subject');
_showdiv('compose_subject');
_gel("reply_rows").style.display="none";
var profilepic=_gel("reply-profilepic-td");
profilepic.style.display="none";
this.set_to_address("");
this.set_subject("");
this.set_message("");
};
Compose.prototype.send=function(){
if(this.sending_message_){
return;
}
var recipient=_gel("compose_to").value;
var all_subscribers=_gel("compose_to_all_subscribers").value;
var message_text=_gel("compose_message").value;
var subject=_gel("compose_subject").value;
var video_id=_gel("field_reference_video").value;
this.inbox_.send_message(recipient,all_subscribers,subject,video_id,message_text,this.in_reply_to);
this.update_send_button(true);
};
Compose.prototype.set_to_address=function(recipient,opt_disable){
var to_field=_gel("compose_to");
to_field.value=recipient;
to_field.disabled=opt_disable;
};
Compose.prototype.set_to_all_subscribers=function(enable){
var to_all_subscribers_field=_gel("compose_to_all_subscribers");
to_all_subscribers_field.value=enable;
};
Compose.prototype.set_subject=function(subject){
_gel("compose_subject").value=subject;
};
Compose.prototype.set_message=function(message){
_gel("compose_message").value=message;
};
Compose.prototype.set_reply_fields=function(message_id,opt_reply_all){
_gel("reply_rows").style.display="";
var subject=_gel(message_id+"-subject").value;
_gel("reply_subj").childNodes[0].nodeValue=subject;
if(top.goog.i18n.bidi.isRtlText(subject)){
_gel("reply_subj").innerHTML='<span dir="rtl">'+subject+'</span>';
_gel("reply_subject_display").setAttribute("dir","rtl");
_gel("compose_subject").setAttribute("dir","rtl");
}
subject=subject.indexOf(yt.getMsg('REPLY_PREFIX'))!=0?yt.getMsg('REPLY_PREFIX')+subject:subject;
_gel("reply_subject_display").childNodes[0].nodeValue=subject.length<50?subject:subject.substring(0,50)+'...';
_showdiv('reply_subject');
_hidediv('compose_subject');
inbox.composition.set_subject(subject);
inbox.composition.is_reply=true;
_gel("reply_body").innerHTML=_gel(message_id+"-body").innerHTML;
_gel("reply_date").innerHTML=_gel(message_id+"-date").innerHTML;
_gel("reply-profilepic-td").style.display="";
_gel("reply-profilepic-div").innerHTML=_gel(message_id+"-profilepic").innerHTML;
var sender=_gel(message_id+"-sender").value;
var to_field=_gel(message_id+"-to");
if(to_field){
_gel("reply_to").innerHTML=to_field.innerHTML;
_gel("reply_to_row").style.display="";
if(opt_reply_all){
inbox.composition.set_to_address(_gel(message_id+"-to_field").value);
}else{
inbox.composition.set_to_address(sender);
}
}else{
_gel("reply_to_row").style.display="none";
inbox.composition.set_to_address(sender);
}
this.in_reply_to=sender;
};
Compose.prototype.handle_error=function(){
this.update_send_button(false);
};
function remove_from_dom(el){
el.parentNode.removeChild(el);
}
})();
(function(){
YT_single_tabpane=function(tab,content,opt_url,opt_loading_page){
this.tab_=tab;
this.content_=content;
if(opt_url){
this.url_=opt_url;
}
if(opt_loading_page){
this.loading_page_=opt_loading_page;
}
this.retrieved_url_=false;
this.selected_=false;
};
YT_tabpane=function(element,class_name_base){
this.element_=_gel(element);
this.tabpanes_=new Array();
this.class_name_base_=class_name_base;
this.num_retries_=0
this.max_retries_=4
this.retry_interval_=5
};
YT_tabpane.prototype.addPage=function(tab,contents,opt_url,opt_left){
var single_tabpane=new YT_single_tabpane(tab,contents,opt_url);
this.tabpanes_[tab]=single_tabpane;
var tab_element=_gel(tab);
tab_element.onclick=function(){this.handleClick(tab);}.bind(this);
if(opt_left){
this.left_=tab;
}
return single_tabpane;
};
YT_tabpane.prototype.getNewContent=function(tab_id,new_url){
var tab=this.tabpanes_[tab_id];
var url=tab.url_+new_url;
this.retrieveUrl(tab,url);
};
YT_tabpane.prototype.retrieveUrl=function(dest,opt_override_url){
var url=dest.url_;
if(opt_override_url){
url=opt_override_url;
}
_hidediv(dest.content_);
_hidediv(this.retry_msg_);
_showdiv(this.loading_page_);
var callback=function(xmlHttpRequest){
this.handleAjaxResponse(xmlHttpRequest,dest,url);
}.bind(this);
yt.net.ajax.sendRequest(url,{method:"GET",onComplete:callback});
};
YT_tabpane.prototype.handleAjaxResponse=function(xmlHttpRequest,dest,url){
if(dest.selected_==false)
return;
if(xmlHttpRequest.readyState==4){
if(xmlHttpRequest.status==200){
var content=_gel(dest.content_);
content.innerHTML=xmlHttpRequest.responseText;
dest.retrieved_url_=true;
this.num_retries_=0;
_hidediv(this.loading_page_);
_hidediv(this.error_page_);
_showdiv(dest.content_);
}else{
dest.retrieved_url_=false;
this.retryRequest(xmlHttpRequest,dest,url);
}
}
};
YT_tabpane.prototype.retryRequest=function(xmlHttpRequest,dest,url){
if(this.num_retries_<this.max_retries_){
this.retry_timer_=setTimeout(function(){this.retrieveUrl(dest,url);}.bind(this),this.retry_interval_*1000);
this.num_retries_++;
if(this.num_retries_>1){
_showdiv(this.retry_msg_);
}
}else{
_hidediv(this.loading_page_);
_showdiv(this.error_page_);
}
};
YT_tabpane.prototype.setRetrieved=function(target,true_or_false){
for(var i in this.tabpanes_){
var tab=_gel(i);
var dest=this.tabpanes_[i];
if(i==target){
dest.retrieved_url_=true_or_false;
break;
}
}
};
YT_tabpane.prototype.handleClick=function(target,opt_new_url){
_hidediv(this.loading_page_);
_hidediv(this.retry_msg_);
_hidediv(this.error_page_);
clearTimeout(this.retry_timer_);
this.num_retries_=0;
for(var i in this.tabpanes_){
var tab=_gel(i);
var dest=this.tabpanes_[i];
var content=_gel(dest.content_);
if(i==target){
content.style.display="block";
_removeclass(tab,this.class_name_base_+"-unsel");
_addclass(tab,this.class_name_base_+"-sel");
dest.selected_=true;
if(dest.url_&&!dest.retrieved_url_){
if(opt_new_url){
this.retrieveUrl(dest,dest.url_+opt_new_url);
}else{
this.retrieveUrl(dest);
}
}
}else{
content.style.display="none";
_removeclass(tab,this.class_name_base_+"-sel");
_addclass(tab,this.class_name_base_+"-unsel");
dest.selected_=false;
}
}
if(this.left_){
var tab=_gel(this.left_);
_addclass(tab,this.class_name_base_+"-left");
}
};
YT_tabpane.prototype.clearPanes=function(target){
_hidediv(this.loading_page_);
_hidediv(this.retry_msg_);
_hidediv(this.error_page_);
clearTimeout(this.retry_timer_);
for(var i in this.tabpanes_){
var tab=_gel(i);
var dest=this.tabpanes_[i];
var content=_gel(dest.content_);
content.style.display="none";
_removeclass(tab,this.class_name_base_+"-sel");
_addclass(tab,this.class_name_base_+"-unsel");
dest.selected_=false;
}
};
YT_tabpane.prototype.setSelected=function(tab,opt_new_url){
this.handleClick(tab,opt_new_url);
};
YT_tabpane.prototype.setLoadingPage=function(page){
this.loading_page_=page;
};
YT_tabpane.prototype.setErrorPage=function(error_page){
this.error_page_=error_page;
};
YT_tabpane.prototype.setRetryMsg=function(retry_msg){
this.retry_msg_=retry_msg;
};
})();
(function(){
function bgrnd(el,clr){
el.style.background=clr;
}
window.bgrnd=bgrnd;
fixupElementId=function(re,id,proto_id){
element=_gel(proto_id);
element.id=proto_id.replace(re,id);
return element;
}
fixupElementData=function(element,re,data){
element.innerHTML=element.innerHTML.replace(re,data);
}
YT_address_book_details=function(the_addy){
this.the_addy_=the_addy;
this.detail_pane_el_=_gel('ab-mulsel');
this.proto_div_el_=_gel('ab-zippy-_FID_');
this.proto_div_el_.parentNode.removeChild(this.proto_div_el_);
this.num_selected_=0;
this.selection_=new Object();
this.is_focused_=false;
this.unfocus_fn_=null;
this.entries_=new Object();;
}
window.YT_address_book_details=YT_address_book_details;
var zippyFidRe=/_FID_/;
var zippyTitleRe=/_TITLE_/;
var zippyUsernameRe=/_USERNAME_/;
YT_address_book_details.prototype.addContact=function(contact){
var entry=this.entries_[contact.fid];
if(!entry){
var fid=contact.fid;
var fname_lower=contact.fname.toLowerCase();
div_el=this.proto_div_el_.cloneNode(true);
div_el.fname_lower=fname_lower;
var div_after_el=null;
var children=this.detail_pane_el_.childNodes;
for(i=0;i<children.length;++i){
var tmp_el=children[i];
if(tmp_el&&tmp_el.fname_lower&&fname_lower.localeCompare(tmp_el.fname_lower)<0){
div_after_el=tmp_el;
break;
}
}
this.detail_pane_el_.insertBefore(div_el,div_after_el);
fixupElementId(zippyFidRe,fid,'ab-zippy-_FID_');
fixupElementId(zippyFidRe,fid,'ab-zippy-_FID_-arrowRight');
fixupElementId(zippyFidRe,fid,'ab-zippy-_FID_-arrowDown');
var title_el=fixupElementId(zippyFidRe,fid,'ab-zippy-_FID_-titleText');
fixupElementData(title_el,zippyTitleRe,contact.fname);
var user_el=fixupElementId(zippyFidRe,fid,'ab-zippy-_FID_-userStuff');
var profile_el=fixupElementId(zippyFidRe,fid,'ab-zippy-_FID_-profileLink');
profile_el.href='/user/'+contact.username;
fixupElementData(profile_el,zippyUsernameRe,contact.username);
fixupElementId(zippyFidRe,fid,'ab-zippy-_FID_-content');
fixupElementId(zippyFidRe,fid,'ab-zippy-_FID_-content-closed');
fixupElementId(zippyFidRe,fid,'ab-zippy-_FID_-bcap-open');
fixupElementId(zippyFidRe,fid,'ab-zippy-_FID_-bcap-closed');
fixupElementId(zippyFidRe,fid,'ab-zippy-_FID_-title');
fixupElementId(zippyFidRe,fid,'ab-zippy-_FID_-titleBtmOpen');
fixupElementId(zippyFidRe,fid,'ab-zippy-_FID_-titleBtmClose');
_showdiv(div_el.id);
if(contact.username){
_showdiv(user_el.id);
}
entry=new Object();
entry.fid=fid;
entry.fname_lower=fname_lower;
entry.contact=contact;
entry.is_selected=false;
entry.div_el=div_el;
function getOnExpandClosure(){
return function(zippy){
var zippy_list=new Array();
for(fid in this.entries_){
var entry=this.entries_[fid];
zippy_list.push(entry.zippy);
}
zippy.minimizeForeignZippies(zippy_list);
this.the_addy_.onSelectionChange();
}
}
function getOnMinimizeClosure(){
return function(zippy){
this.the_addy_.onSelectionChange();
}
}
var url='/address_book?action_display_contact_details=1&fid='+fid;
var login_url='/signup_login?next=address_book';
entry.zippy=new YT_stats_zippy(div_el.id,url,login_url,null,
getOnExpandClosure().bind(this),getOnMinimizeClosure().bind(this));
this.entries_[fid]=entry;
}
return entry;
}
YT_address_book_details.prototype.removeContacts=function(fids){
for(i in fids){
var fid=fids[i];
var entry=this.entries_[fid];
if(entry){
if(entry.is_selected){
--this.num_selected_;
delete this.selection_[fid];
}
delete entry.zippy;
entry.div_el.parentNode.removeChild(entry.div_el);
delete this.entries_[fid];
}
}
this.the_addy_.onSelectionChange();
}
YT_address_book_details.prototype.invalidateAllContacts=function(){
var add_list=new Array();
var delete_list=new Array();
var fid_to_expand=null;
for(fid in this.entries_){
var entry=this.entries_[fid];
if(entry.is_selected){
var contact=entry.contact;
if(entry.zippy.isExpanded()){
fid_to_expand=fid;
}
add_list.push(contact);
}
delete_list.push(fid);
}
this.removeContacts(delete_list);
this.addContactsToSelection(add_list);
var entry=this.entries_[fid_to_expand];
if(entry){
entry.zippy.expand();
}
}
YT_address_book_details.prototype.focusOnContact=function(fid,unfocus_fn){
this.unfocus();
for(var i in this.entries_){
var entry=this.entries_[i];
if(entry.fid==fid){
if(!entry.zippy.isExpanded()){
entry.zippy.expand();
}
_showdiv(entry.div_el.id);
}else{
_hidediv(entry.div_el.id);
}
}
this.unfocus_fn_=unfocus_fn;
this.is_focused_=true;
}
YT_address_book_details.prototype.unfocus=function(){
if(this.is_focused_){
for(var i in this.entries_){
var entry=this.entries_[i];
if(entry.is_selected){
_showdiv(entry.div_el.id);
}
}
if(typeof this.unfocus_fn_=='function'){
this.unfocus_fn_();
}
this.unfocus_fn_=null;
this.is_focused_=false
}
}
YT_address_book_details.prototype.addContactToSelection=function(contact,opt_expand_zippy,opt_minimize_all){
var contacts=[contact];
this.addContactsToSelection(contacts);
if(opt_expand_zippy){
var entry=this.entries_[contact.fid];
if(entry&&!entry.zippy.isExpanded()){
entry.zippy.expand();
}
}
if(opt_minimize_all){
for(fid in this.entries_){
var entry=this.entries_[fid];
if(entry.zippy.isExpanded()){
entry.zippy.minimize();
break;
}
}
}
}
YT_address_book_details.prototype.addContactsToSelection=function(contacts){
for(i in contacts){
var contact=contacts[i];
var entry=this.addContact(contact);
if(entry){
if(!entry.is_selected){
entry.is_selected=true;
++this.num_selected_;
this.selection_[contact.fid]=1;
_showdiv(entry.div_el.id);
}
}
}
this.the_addy_.onSelectionChange();
}
YT_address_book_details.prototype.unselectContacts=function(fids){
for(i in fids){
var fid=fids[i];
var entry=this.entries_[fid];
if(entry&&entry.is_selected){
entry.is_selected=false;
--this.num_selected_;
delete this.selection_[fid];
_hidediv(entry.div_el.id);
if(entry.zippy.isExpanded()){
entry.zippy.minimize();
}
}
}
this.the_addy_.onSelectionChange();
}
YT_address_book_details.prototype.unselectContact=function(fid){
var fids=[fid];
this.unselectContacts(fids);
}
YT_address_book_details.prototype.unselectAllContacts=function(){
var fids=new Array();
for(fid in this.entries_){
fids.push(fid);
}
this.unselectContacts(fids);
}
YT_address_book_details.prototype.getNumSelected=function(){
return this.num_selected_;
}
YT_address_book_details.prototype.getSelection=function(){
return this.selection_;
}
YT_address_book_details.prototype.getContact=function(fid){
var entry=this.entries_[fid];
if(entry){
return entry.contact;
}
return null;
}
YT_address_book_details.prototype.isExpanded=function(fid){
var entry=this.entries_[fid];
if(entry){
return entry.zippy.isExpanded();
}
return false;
}
YT_address_book_contacts=function(the_addy,gid,pagination,contacts,html){
this.the_addy_=the_addy;
this.details_=the_addy.details_;
this.gid_=gid;
this.pagination_=pagination;
this.entries_=new Object();
var div_id='ab-contactpane-'+gid;
var div_el=_gel(div_id);
if(!div_el){
div_el=document.createElement('div');
div_el.id=div_id;
var parent_el=_gel('ab-contactpane');
parent_el.appendChild(div_el);
}
this.div_el_=div_el;
div_el.innerHTML=html;
for(i in contacts){
var contact=contacts[i];
this.addContact(contact);
}
this.checkall_el_=_gel('checkall-'+gid);
this.checkall_el_.onclick=function(){
if(this.checkall_el_.checked){
var contact_list=new Array();
for(fid in this.entries_){
var entry=this.entries_[fid];
contact_list.push(entry);
}
this.details_.addContactsToSelection(contact_list);
}else{
var fid_list=new Array();
for(fid in this.entries_){
fid_list.push(fid);
}
this.details_.unselectContacts(fid_list);
}
}.bind(this);
}
window.YT_address_book_contacts=YT_address_book_contacts;
YT_address_book_contacts.prototype.addContact=function(contact){
var fid=contact.fid;
var id=this.gid_+'-'+fid;
var entry=new Object();
entry.fid=fid;
entry.fname=contact.fname;
entry.username=contact.username;
var row_el=_gel(id);
row_el.onclick=function(){this.handleClick(fid);}.bind(this);
entry.row_el=row_el;
var check_el=_gel('check-'+id);
check_el.onclick=function(){this.handleCheck(fid);}.bind(this);
entry.check_el=check_el;
this.entries_[fid]=entry;
}
YT_address_book_contacts.prototype.handleCheck=function(fid){
var entry=this.entries_[fid];
if(entry)
{
if(entry.check_el.checked){
this.details_.addContactToSelection(entry,false,true);
}else{
this.details_.unselectContact(fid);
}
}
}
YT_address_book_contacts.prototype.handleClick=function(fid){
var entry=this.entries_[fid];
if(entry){
entry.check_el.checked=true;
this.details_.unselectAllContacts();
this.details_.addContactToSelection(entry,true);
}
}
YT_address_book_contacts.prototype.show=function(){
_showdiv(this.div_el_.id);
initEllipsis();
}
YT_address_book_contacts.prototype.hide=function(){
_hidediv(this.div_el_.id);
}
YT_address_book_contacts.prototype.syncWithSelection=function(){
var num_selected=this.details_.getNumSelected();
var limit=this.details_.the_addy_.EN_MASSE_LIMIT*2;
var over_limit=num_selected>=limit;
var selection=this.details_.getSelection();
var all_checked=true;
var will_be_checked=0;
var entry_count=0;
for(fid in this.entries_){
var entry=this.entries_[fid];
++entry_count;
if(selection[fid]){
entry.check_el.disabled=false;
if(!entry.check_el.checked){
entry.check_el.checked=true;
}
}else{
entry.check_el.disabled=over_limit;
if(entry.check_el.checked){
entry.check_el.checked=false;
}
all_checked=false;
++will_be_checked;
}
var row_el=entry.check_el.parentNode.parentNode;
if(this.details_.isExpanded(entry.fid)){
_addclass(row_el,'ab-user-current');
}else{
_removeclass(row_el,'ab-user-current');
}
}
this.checkall_el_.checked=(entry_count!=0)&&all_checked;
this.checkall_el_.disabled=(will_be_checked+num_selected)>limit;
}
YT_address_book_groups=function(the_addy){
this.the_addy_=the_addy;
this.details_=the_addy.details;
this.proto_div_el_=_gel('ab-group-_GID_');
this.proto_div_el_.parentNode.removeChild(this.proto_div_el_);
this.chunk_div_els_=new Object();
this.max_chunks_=4;
for(chunk=0;chunk<=this.max_chunks_;++chunk){
this.chunk_div_els_[chunk]=_gel('ab-group-chunk-'+chunk);
}
this.loading_div_el_=_gel('ab-midpane-loading');
this.active_contacts_=null;
this.default_gid_=null;
this.entries_=new Object();
}
window.YT_address_book_groups=YT_address_book_groups;
var groupGidRe=/_GID_/;
var groupNameRe=/_NAME_/;
YT_address_book_groups.prototype.addGroup=function(group){
var entry=this.entries_[group.gid];
if(!entry){
var gid=group.gid;
var name_lower=group.name.toLowerCase();
div_el=this.proto_div_el_.cloneNode(true);
div_el.name_lower=name_lower;
var div_after_el=null;
var chunk_div_el=this.chunk_div_els_[group.chunk];
if(!chunk_div_el){
return;
}
var children=chunk_div_el.childNodes;
for(i=0;i<children.length;++i){
var tmp_el=children[i];
if(tmp_el&&tmp_el.name_lower&&name_lower.localeCompare(tmp_el.name_lower)<0){
div_after_el=tmp_el;
break;
}
}
chunk_div_el.insertBefore(div_el,div_after_el);
var short_name=group.name.length<=22?group.name:group.name.substring(0,22)+'...';
var group_el=fixupElementId(groupGidRe,gid,'ab-group-_GID_');
fixupElementData(group_el,groupNameRe,short_name);
group_el.onclick=function(){this.handleClick(gid);}.bind(this);
group_el.dir=group.is_bidi?'rtl':'';
var count_el=fixupElementId(groupGidRe,gid,'ab-group-_GID_-count');
count_el.innerHTML=group.link_count;
var delete_el=fixupElementId(groupGidRe,gid,'ab-group-_GID_-delete');
if(group.is_user_label){
delete_el.onclick=function(){this.handleDeleteGroup(gid);}.bind(this);
_showdiv(delete_el.id);
}
_showdiv(div_el.id);
var entry=new Object();
entry.contacts=null;
entry.name=group.name;
entry.short_name=short_name;
entry.is_bidi=group.is_bidi;
entry.is_user_label=group.is_user_label;
entry.name_lower=name_lower;
entry.link_count=group.link_count;
entry.chunk=group.chunk;
entry.div_el=div_el;
this.entries_[gid]=entry;
}
}
YT_address_book_groups.prototype.removeGroup=function(gid){
var entry=this.entries_[gid];
if(entry){
if(this.active_contacts_==entry.contacts){
this.selectGroup(this.default_gid_);
}
delete entry.contacts;
entry.contacts=null;
entry.div_el.parentNode.removeChild(entry.div_el);
delete this.entries_[gid];
}
}
YT_address_book_groups.prototype.invalidateAllContacts=function(){
var active_gid=this.default_gid_;
var active_page=1;
if(this.active_contacts_){
this.active_contacts_.hide();
active_gid=this.active_contacts_.gid_;
active_page=this.active_contacts_.pagination_.page;
}
for(i in this.entries_){
var entry=this.entries_[i];
if(entry.contacts){
delete entry.contacts;
entry.contacts=null;
}
}
this.fetchContacts(active_gid,active_page);
}
YT_address_book_groups.prototype.adjustLinkCount=function(gid,offset){
var contacts_invalid=false;
var entry=this.entries_[gid];
if(entry){
entry.link_count+=offset;
if(entry.link_count<0){
entry.link_count=0;
}
span_el=_gel('ab-group-'+gid+'-count');
span_el.innerHTML=entry.link_count;
if(this.active_contacts_==entry.contacts){
contacts_invalid=true;
}
}
return contacts_invalid;
}
YT_address_book_groups.prototype.handleClick=function(gid){
this.selectGroup(gid);
}
YT_address_book_groups.prototype.handleDeleteGroup=function(gid){
if(confirm(yt.getMsg('CONFIRM_DELETE_GROUP'))){
this.the_addy_.handleDeleteLabel(gid);
}
return false;
}
YT_address_book_groups.prototype.selectGroup=function(gid,opt_set_default){
if(opt_set_default){
this.default_gid_=gid;
}
this.active_contacts_=null;
var pagination=null;
var title='';
for(i in this.entries_){
var entry=this.entries_[i];
if(i!=gid){
_addclass(entry.div_el,'ab-leftpane-unsel');
_removeclass(entry.div_el,'ab-leftpane-sel');
var contacts=entry.contacts;
if(contacts){
contacts.hide();
}
}
}
for(i in this.entries_){
var entry=this.entries_[i];
if(i==gid){
_removeclass(entry.div_el,'ab-leftpane-unsel');
_addclass(entry.div_el,'ab-leftpane-sel');
var contacts=entry.contacts;
if(contacts){
_hidediv(this.loading_div_el_.id);
contacts.show();
contacts.syncWithSelection();
pagination=contacts.pagination_
title=entry.is_bidi?'<span dir="rtl">'+entry.name+'</span>':entry.name;
}else{
this.fetchContacts(gid,1);
}
this.active_contacts_=contacts;
}
}
this.refreshPagination(pagination);
this.the_addy_.onContactsChange();
this.the_addy_.refreshGroupTitle(title);
}
YT_address_book_groups.prototype.showFirstPage=function(){
var contacts=this.active_contacts_;
if(contacts){
this.fetchContacts(contacts.gid_,1);
}
}
YT_address_book_groups.prototype.showNextPage=function(){
var contacts=this.active_contacts_;
if(contacts){
var page=Math.min(contacts.pagination_.num_pages,contacts.pagination_.page+1);
this.fetchContacts(contacts.gid_,page);
}
}
YT_address_book_groups.prototype.showPrevPage=function(){
var contacts=this.active_contacts_;
if(contacts){
var page=Math.max(1,contacts.pagination_.page-1);
this.fetchContacts(contacts.gid_,page);
}
}
YT_address_book_groups.prototype.showLastPage=function(){
var contacts=this.active_contacts_;
if(contacts){
var page=contacts.pagination_.num_pages;
this.fetchContacts(contacts.gid_,page);
}
}
YT_address_book_groups.prototype.refreshPagination=function(pagination){
for(var idx=0;idx<2;idx++){
if(pagination&&pagination.start<=pagination.end){
_gel("ab-page-start-"+idx).innerHTML=pagination.start+1;
_gel("ab-page-end-"+idx).innerHTML=pagination.end;
_gel("ab-page-total-"+idx).innerHTML=pagination.total;
_gel("ab-page-first-"+idx).style.display=pagination.has_first?"":"none";
_gel("ab-page-next-"+idx).style.display=pagination.has_next?"":"none";
_gel("ab-page-prev-"+idx).style.display=pagination.has_prev?"":"none";
_gel("ab-page-last-"+idx).style.display=pagination.has_last?"":"none";
}else{
_gel("ab-page-start-"+idx).innerHTML="0";
_gel("ab-page-end-"+idx).innerHTML="0";
_gel("ab-page-total-"+idx).innerHTML="0";
_gel("ab-page-first-"+idx).style.display="none";
_gel("ab-page-next-"+idx).style.display="none";
_gel("ab-page-prev-"+idx).style.display="none";
_gel("ab-page-last-"+idx).style.display="none";
}
}
}
YT_address_book_groups.prototype.fetchContacts=function(gid,page){
var entry=this.entries_[gid];
if(entry){
var args={'gid':gid,'link_count':entry.link_count,'page':page};
this.the_addy_.aq_.send_message(args,'ajax_fetch_contacts',true);
_showdiv(this.loading_div_el_.id);
if(this.active_contacts_){
this.active_contacts_.hide();
}
}
}
YT_address_book_groups.prototype.ajaxFetchContacts=function(response){
var gid=response.request.gid;
var entry=this.entries_[gid];
if(entry){
entry.contacts=new YT_address_book_contacts(this.the_addy_,gid,
response.data.pagination,response.data.contacts,response.data.html);
this.selectGroup(gid);
}
}
YT_address_book_groups.prototype.onSelectionChange=function(){
if(this.active_contacts_){
this.active_contacts_.syncWithSelection();
}
}
YT_address_book=function(session_param){
this.cover_el_list_=new Array();
this.current_detail_div_=null;
this.details_=new YT_address_book_details(this);
this.groups_=new YT_address_book_groups(this);
this.resetDetails();
this.aq_=new AjaxQueue("/address_book?action_ajax=1",session_param);
this.aq_.register_error_handler((function(http_code,message){this.ajaxError(http_code,message)}).bind(this));
this.aq_.register_handler("ajax_fetch_contacts",(function(response){this.ajaxFetchContacts(response)}).bind(this));
this.aq_.register_handler("ajax_block_contacts",(function(response){this.ajaxDefault(response)}).bind(this));
this.aq_.register_handler("ajax_unblock_contacts",(function(response){this.ajaxDefault(response)}).bind(this));
this.aq_.register_handler("ajax_delete_contacts",(function(response){this.ajaxDefault(response)}).bind(this));
this.aq_.register_handler("ajax_friend_contacts",(function(response){this.ajaxDefault(response)}).bind(this));
this.aq_.register_handler("ajax_unfriend_contacts",(function(response){this.ajaxDefault(response)}).bind(this));
this.aq_.register_handler("ajax_update_contact",(function(response){this.ajaxDefault(response)}).bind(this));
this.aq_.register_handler("ajax_subscribe_contacts",(function(response){this.ajaxDefault(response)}).bind(this));
this.aq_.register_handler("ajax_unsubscribe_contacts",(function(response){this.ajaxDefault(response)}).bind(this));
this.aq_.register_handler("ajax_label_contacts",(function(response){this.ajaxDefault(response)}).bind(this));
this.aq_.register_handler("ajax_delete_labels",(function(response){this.ajaxLabelCreateOrDelete(response)}).bind(this));
this.aq_.register_handler("ajax_create_and_apply_labels",(function(response){this.ajaxLabelCreateOrDelete(response)}).bind(this));
};
window.YT_address_book=YT_address_book;
YT_address_book.prototype.makeAjaxCallOnSelected=function(ajax_action,opt_args,opt_contacts){
var num_selected=this.details_.getNumSelected();
if(num_selected>this.EN_MASSE_LIMIT){
this.showErrorMessage(this.EN_MASSE_LIMIT_MSG);
}else if(num_selected>0){
this.showStatusMessage(yt.getMsg('APPLYING_CHANGES'));
if(opt_args){
var args=opt_args;
}else{
var args=new Object();
}
if(opt_contacts){
args['contacts']=opt_contacts;
}else{
args['contacts']=this.details_.getSelection();
}
this.aq_.send_message(args,ajax_action,true);
}
return false;
}
YT_address_book.prototype.handleBlock=function(opt_contacts){
return this.makeAjaxCallOnSelected('ajax_block_contacts',null,opt_contacts);
}
YT_address_book.prototype.handleUnblock=function(opt_contacts){
return this.makeAjaxCallOnSelected('ajax_unblock_contacts',null,opt_contacts);
}
YT_address_book.prototype.handleDelete=function(opt_contacts){
return this.makeAjaxCallOnSelected('ajax_delete_contacts',null,opt_contacts);
}
YT_address_book.prototype.handleFriend=function(opt_contacts){
return this.makeAjaxCallOnSelected('ajax_friend_contacts',null,opt_contacts);
}
YT_address_book.prototype.handleUnfriend=function(opt_contacts){
return this.makeAjaxCallOnSelected('ajax_unfriend_contacts',null,opt_contacts);
}
YT_address_book.prototype.handleComposeAll=function(){
var usernames=new Array();
var selection=this.details_.getSelection();
var count=0;
for(fid in selection){
var contact=this.details_.getContact(fid);
if(contact.username){
usernames.push(contact.username);
++count;
}
}
if(count>this.EN_MASSE_LIMIT){
this.showErrorMessage(this.EN_MASSE_LIMIT_MSG);
}else if(count>0){
var url='/inbox?action_compose=1&to_users='+encodeURIComponent(usernames.join(","));
window.location.href=url;
}else{
var url='/inbox?action_compose=1';
window.location.href=url;
}
return false;
}
YT_address_book.prototype.handleUpdateContact=function(contact,name,email,labelsToAdd,labelsToDelete){
this.showStatusMessage(yt.getMsg('APPLYING_CHANGES'));
var args={'fid':contact,'name':name,'email':email,'add_label_ids':labelsToAdd,'delete_label_ids':labelsToDelete};
this.aq_.send_message(args,'ajax_update_contact',true);
return false;
}
YT_address_book.prototype.handleNewContact=function(username,name,email,labelsToAdd){
this.showStatusMessage(yt.getMsg('APPLYING_CHANGES'));
var args={'username':username,'name':name,'email':email,'add_label_ids':labelsToAdd,'delete_label_ids':[]};
this.aq_.send_message(args,'ajax_update_contact',true);
return false;
}
YT_address_book.prototype.handleSubscribe=function(opt_contacts){
return this.makeAjaxCallOnSelected('ajax_subscribe_contacts',null,opt_contacts);
}
YT_address_book.prototype.handleUnsubscribe=function(opt_contacts){
return this.makeAjaxCallOnSelected('ajax_unsubscribe_contacts',null,opt_contacts);
}
YT_address_book.prototype.handleUnselectAll=function(){
this.details_.unselectAllContacts();
}
YT_address_book.prototype.unselectContact=function(fid){
this.details_.unselectContact(fid);
}
YT_address_book.prototype.editContact=function(fid,formElement){
cleanup_fn=function(){
this.resetDetails(true);
_hidediv("editdetail-"+fid);
_showdiv("detail-"+fid);
var form_el=_gel(formElement);
if(form_el){
form_el.reset();
}
}.bind(this);
this.details_.focusOnContact(fid,cleanup_fn);
this.hideAllDetailHeaders();
_showdiv("ab-mulsel-edit-header");
_showdiv("editdetail-"+fid);
_hidediv("detail-"+fid);
}
YT_address_book.prototype.cancelEditContact=function(){
this.details_.unfocus();
}
YT_address_book.prototype.processEditForm=function(formElement){
var form=_gel(formElement);
var labelsToAdd=new Array();
var labelsToDelete=new Array();
for(gid in this.groups_.entries_){
var entry=this.groups_.entries_[gid];
if(!entry.is_user_label){
continue;
}
var id=form.fid.value+"-"+gid;
var el=_gel(id);
var state_el=_gel("state-"+id);
if(el&&state_el){
if(el.checked&&(state_el.value!="checked")){
labelsToAdd.push(gid);
}else if(!el.checked&&(state_el.value=="checked")){
labelsToDelete.push(gid);
}
}
}
this.handleUpdateContact(form.fid.value,form.name.value,form.email.value,labelsToAdd,labelsToDelete);
}
YT_address_book.prototype.newContact=function(formElement){
cleanup_fn=function(){
this.resetDetails(true);
var form_el=_gel(formElement);
if(form_el){
form_el.reset();
}
}.bind(this);
this.details_.focusOnContact(null,cleanup_fn);
this.hideAllDetailHeaders();
_showdiv("ab-mulsel-new-header");
this.setDetailPane(_gel("ab-newcontact"));
}
YT_address_book.prototype.cancelNewContact=function(){
this.details_.unfocus();
}
YT_address_book.prototype.processNewForm=function(formElement){
form=_gel(formElement);
var labelsToAdd=new Array();
var fid="_newcontact_";
for(gid in this.groups_.entries_){
var entry=this.groups_.entries_[gid];
if(!entry.is_user_label){
continue;
}
var id=fid+"-"+gid;
var el=_gel(id);
if(el&&el.checked){
labelsToAdd.push(gid);
}
}
this.handleNewContact(form.username.value,form.name.value,form.email.value,labelsToAdd);
}
YT_address_book.prototype.handleSubmitLabel=function(dialogId,apply){
var label=_gel(dialogId+'-input');
if(label.value!=""){
this.handleCreateAndApplyLabel(label.value,apply);
_hidediv(dialogId);
}
}
YT_address_book.prototype.handleLabel=function(label_id,add){
var add_label_ids=new Array();
var delete_label_ids=new Array();
if(add){
add_label_ids.push(label_id)
}else{
delete_label_ids.push(label_id);
}
var args={'add_label_ids':add_label_ids,'delete_label_ids':delete_label_ids};
return this.makeAjaxCallOnSelected('ajax_label_contacts',args);
}
YT_address_book.prototype.handleCreateAndApplyLabel=function(label,apply){
var args={'labels':[label]};
var num_selected=this.details_.getNumSelected();
if(num_selected>this.EN_MASSE_LIMIT){
this.showErrorMessage(this.EN_MASSE_LIMIT_MSG);
}else{
this.showStatusMessage(yt.getMsg('APPLYING_CHANGES'));
if(apply&apply!='false'){
args['contacts']=this.details_.getSelection();
}
this.aq_.send_message(args,'ajax_create_and_apply_labels',true);
}
return false;
}
YT_address_book.prototype.handleDeleteLabel=function(label_id){
var args={'label_ids':[label_id]};
this.showStatusMessage(yt.getMsg('APPLYING_CHANGES'));
this.aq_.send_message(args,'ajax_delete_labels',true);
return false;
}
YT_address_book.prototype.ajaxError=function(http_code,message){
this.showErrorMessage(message);
}
YT_address_book.prototype.processResponseMessages=function(response){
if(response.data.errors.length>0){
var errors="";
for(error in response.data.errors){
errors+=response.data.errors[error]+"<br>";
}
this.showErrorMessage(errors);
}else if(response.data.messages.length>0){
var messages="";
for(message in response.data.messages){
messages+=response.data.messages[message]+"<br>";
}
this.showSuccessMessage(messages);
}
}
YT_address_book.prototype.processStateUpdates=function(response){
var details_valid=true;
var groups_valid=true;
for(i in response.data.state_updates){
var pair=response.data.state_updates[i];
var action=pair[0];
var details=pair[1];
if(action=='contact_created'){
var contact=details;
this.details_.addContactToSelection(contact,true);
groups_valid=false;
}else if(action=='contact_updated'){
var contact=details;
this.details_.removeContacts([contact.fid]);
this.details_.addContactToSelection(contact,true);
groups_valid=false;
}else if(action=='contact_deleted'){
var fid=details;
this.details_.removeContacts([fid]);
groups_valid=false;
}else if(action=='group_created'){
var group=details;
this.groups_.addGroup(group);
details_valid=false;
}else if(action=='group_deleted'){
var gid=details;
this.groups_.removeGroup(gid);
details_valid=false;
}else if(action=='group_link_count_adjusted'){
var entry=details;
if(this.groups_.adjustLinkCount(entry.gid,entry.offset)){
groups_valid=false;
}
details_valid=false;
}
}
if(!details_valid){
this.details_.invalidateAllContacts();
}
if(!groups_valid){
this.groups_.invalidateAllContacts();
}
}
YT_address_book.prototype.ajaxFetchContacts=function(response){
if(response.data.errors.length==0){
this.groups_.ajaxFetchContacts(response);
}
this.processResponseMessages(response);
this.processStateUpdates(response);
}
replace_div=function(el,new_html){
if(el.outerHTML){
el.outerHTML=new_html;
return;
}
var next_sibling=el.nextSibling;
var parent_node=el.parentNode;
parent_node.removeChild(el);
var replacement=document.createElement('div');
replacement.innerHTML=new_html;
if(replacement.firstChild){
if(next_sibling){
parent_node.insertBefore(replacement.firstChild,next_sibling);
}else{
parent_node.appendChild(replacement.firstChild);
}
}
}
YT_address_book.prototype.ajaxLabelCreateOrDelete=function(response){
if(response.data.errors.length==0){
var new_contact_el=_gel('ab-newcontact-labels');
new_contact_el.innerHTML=response.data.new_contact_html;
var label_menu_el=_gel('ab-button-label');
replace_div(label_menu_el,response.data.label_menu_html);
}
this.processResponseMessages(response);
this.processStateUpdates(response);
}
YT_address_book.prototype.ajaxDefault=function(response){
if(response.data.errors.length==0){
this.details_.unfocus();
}
this.processResponseMessages(response);
this.processStateUpdates(response);
}
YT_address_book.prototype.hideMessage=function(pane_id){
endAllAnimations();
_gel(pane_id).style.display='none';
};
YT_address_book.prototype.showMessage=function(message,msg_class,pane_id,opt_fade){
var pane_el=_gel(pane_id);
pane_el.innerHTML=message;
_removeclass(pane_el,'status-msg');
_removeclass(pane_el,'success-msg');
_removeclass(pane_el,'error-msg');
_addclass(pane_el,msg_class);
_showdiv(pane_id);
if(opt_fade){
ani.fadeAndSlideUp(pane_el,ani.DEFAULT_MESSAGE_DELAY,
ani.DEFAULT_MESSAGE_FADEOUT,ani.DEFAULT_MESSAGE_SLIDE);
}
}
YT_address_book.prototype.showStatusMessage=function(message,opt_pane_id){
if(!opt_pane_id){
opt_pane_id='ab-msg';
}
this.showMessage(message,'status-msg',opt_pane_id);
};
YT_address_book.prototype.showSuccessMessage=function(message,opt_pane_id){
if(!opt_pane_id){
opt_pane_id='ab-msg';
}
this.showMessage(message,'success-msg',opt_pane_id,true);
};
YT_address_book.prototype.showErrorMessage=function(message,opt_pane_id){
if(!opt_pane_id){
opt_pane_id='ab-msg';
}
this.showMessage(message,'error-msg',opt_pane_id,true);
};
YT_address_book.prototype.showTopStatusMessage=function(message,opt_pane_id){
if(!opt_pane_id){
opt_pane_id='ab-onload-msg';
}
this.showMessage(message,'onload-msg',opt_pane_id,true);
};
YT_address_book.prototype.onSelectionChange=function(){
this.resetDetails();
this.groups_.onSelectionChange();
}
YT_address_book.prototype.onContactsChange=function(){
this.resetDetails();
}
YT_address_book.prototype.hideAllDetailHeaders=function(){
_hidediv('ab-mulsel-browse-header');
_hidediv('ab-mulsel-edit-header');
_hidediv('ab-mulsel-new-header');
};
YT_address_book.prototype.resetDetails=function(opt_inside_unfocus){
if(!opt_inside_unfocus){
this.details_.unfocus();
}
this.hideAllDetailHeaders();
_showdiv("ab-mulsel-browse-header");
var num_selected=this.details_.getNumSelected();
if(num_selected==0){
_gel("ab-mulsel-num").innerHTML="0";
this.setDetailPane(_gel("ab-mulsel-nothing"));
}else{
_gel("ab-mulsel-num").innerHTML=num_selected;
this.setDetailPane(_gel("ab-mulsel"));
}
if(num_selected>0){
_gel('ab-unselect-all').style.display="block";
}else{
_gel('ab-unselect-all').style.display="none";
}
}
YT_address_book.prototype.refreshGroupTitle=function(title){
_gel("ab-current-group-title").innerHTML=title;
}
YT_address_book.prototype.addGroup=function(group){
this.groups_.addGroup(group);
}
YT_address_book.prototype.selectGroup=function(gid,opt_set_default){
this.groups_.selectGroup(gid,opt_set_default);
}
YT_address_book.prototype.setDetailPane=function(new_content){
if(this.current_detail_div_!=new_content){
if(this.current_detail_div_!=null){
this.current_detail_div_.style.display="none";
}
this.current_detail_div_=new_content;
this.current_detail_div_.style.display="block";
}
}
YT_address_book.prototype.showFirstPage=function(){
this.groups_.showFirstPage();
}
YT_address_book.prototype.showNextPage=function(){
this.groups_.showNextPage();
}
YT_address_book.prototype.showPrevPage=function(){
this.groups_.showPrevPage();
}
YT_address_book.prototype.showLastPage=function(){
this.groups_.showLastPage();
}
YT_address_book.prototype.closeAllDialogs=function(){
_hidediv('ab-newstuff-addlabel');
_hidediv('ab-label-addlabel');
}
YT_address_book.prototype.openNewLabelDialog=function(divId){
var el=_gel(divId);
_gel(divId+'-input').value="";
_showdiv(divId);
animateProperty(el.style,'opacity','0.0','1.0',0,0.5,'number','sine',false);
animateProperty(el.style,'-moz-opacity','0.0','1.0',0,0.5,'number','sine',false);
animateProperty(el.style,'filter','0.0','1.0',0,0.5,'filter','sine',false);
_gel(divId+'-input').focus();
}
YT_address_book.prototype.handleSubmitLabelInput=function(e,apply,id){
var key;
if(window.event){
key=e.keyCode;
}else if(e.which){
key=e.which;
}
if(key==13){
this.handleSubmitLabel(id,apply);
}
if(key==27){
_hidediv(id);
}
}
YT_address_book.prototype.coverElement=function(el){
}
YT_address_book.prototype.uncoverEverything=function(){
}
})();
window.History={};
(function(){
var self=this.History;
var iframeURL="/blank.html?";
var once=true;
self.initialize=function(){
if(!isIE_)return;
firstLoad_=false;
fireOnNewListener_=PageLoaded();
};
self.addListener=function(callback){
listener_=callback;
if(fireOnNewListener_){
FireHistoryEvent(currentLocation_);
fireOnNewListener_=false;
}
};
self.add=function(newLocation,historyData){
var addImpl=function(){
if(currentWaitTime_>0)currentWaitTime_-=waitTime_;
newLocation=RemoveHash(newLocation);
var idCheck=_gel(newLocation);
if(idCheck==undefined||idCheck==null){
self.historyStorage_.put(newLocation,historyData);
ignoreLocationChange_=true;
ieAtomicLocationChange_=true;
currentLocation_=newLocation;
window.location.hash=newLocation||'#';
if(isIE_)iframe_.src=iframeURL+newLocation;
ieAtomicLocationChange_=false;
}
};
window.setTimeout(addImpl,currentWaitTime_);
currentWaitTime_+=waitTime_;
};
self.isFirstLoad=function(){
return firstLoad_==true;
};
var SECRET_DATA_KEY='_secret_data';
self.setSecretData=function(data){
self.historyStorage_.put(SECRET_DATA_KEY,data);
};
self.getSecretData=function(){
return self.historyStorage_.get(SECRET_DATA_KEY);
};
function GetCurrentLocation(){
return RemoveHash(window.location.hash);
};
var currentLocation_=null;
var listener_=null;
var iframe_=null;
var ignoreLocationChange_=null;
var waitTime_=200;
var currentWaitTime_=0;
var fireOnNewListener_=null;
var firstLoad_=null;
var ieAtomicLocationChange_=null;
var isIE_;
function Create(){
isIE_=document.all&&
navigator.userAgent.toLowerCase().indexOf('msie')!=-1;
var initialHash=GetCurrentLocation();
currentLocation_=initialHash;
simpleBindEvent(window,"unload",function(){
firstLoad_=null;
});
if(!isIE_){
if(!(ignoreLocationChange_=!PageLoaded()))
fireOnNewListener_=true;
}else{
document.write(
"<iframe style='border:0px;width:1px;"+
"height:1px;position:absolute;bottom:0px;"+
"right:0px;visibility:visible' "+
"name=HistoryFrame id=HistoryFrame "+
"src=\""+iframeURL+encodeURIComponent(initialHash)+"\"></iframe>");
waitTime_=400;
ignoreLocationChange_=true;
iframe_=_gel("HistoryFrame");
}
setInterval(function(){self.CheckLocation();},100);
};
function PageLoaded(){
var result=true;
var FLAG="History_pageLoaded";
if(!self.historyStorage_.hasKey(FLAG)){
self.historyStorage_.put(FLAG,true);
firstLoad_=true;
result=false;
}
return result;
};
function FireHistoryEvent(newHash){
var historyData=self.historyStorage_.get(newHash);
listener_.call(null,newHash,historyData);
};
self.CheckLocation=function(){
if(!isIE_&&ignoreLocationChange_==true){
ignoreLocationChange_=false;
return;
}
if(!isIE_&&ieAtomicLocationChange_==true){
return;
}
var hash=GetCurrentLocation();
if(hash==currentLocation_)return;
ieAtomicLocationChange_=true;
if(isIE_){
var doc=iframe_.contentDocument||iframe_.contentWindow.document;
var frHash=new String(doc.location.search);
var qAt0=frHash.charAt(0)=="?";
if(frHash.length==1&&qAt0)
frHash="";
else if(frHash.length>=2&&qAt0)
frHash=frHash.substring(1);
if(frHash!=hash){
iframe_.src=iframeURL+hash;
}else{
return;
}
}
currentLocation_=hash;
ieAtomicLocationChange_=false;
FireHistoryEvent(hash);
};
function RemoveHash(hashValue){
var result=hashValue;
if(hashValue==null||hashValue==undefined)
result="";
else{
var c0h=hashValue.charAt(0)=="#";
if(hashValue==""||(hashValue.length==1&&c0h))
result="";
else if(hashValue.length>1&&c0h)
result=hashValue.substring(1);
}
return result;
};
self.iframeLoaded=function(newLocation){
if(ignoreLocationChange_==true){
ignoreLocationChange_=false;
return;
}
var hash=new String(newLocation.search);
if(hash.charAt(0)=="?"&&hash.length>0)
hash=hash.substring(1);
window.location.hash=hash;
FireHistoryEvent(hash);
};
(function(){
var hsSelf={};
self.historyStorage_=hsSelf;
var storageHash_={};
var hashLoaded_=false;
hsSelf.put=function(key,value){
if(hsSelf.isValidKey(key)){
storageHash_[key]=value;
SaveHashTable();
}
};
hsSelf.get=function(key){
var result=null;
if(hsSelf.isValidKey(key)){
LoadHashTable();
var value=storageHash_[key];
if(value!=undefined)result=value;
}
return result;
};
hsSelf.hasKey=function(key){
var result=false;
if(hsSelf.isValidKey(key)){
LoadHashTable();
if(typeof storageHash_[key]!="undefined")result=true;
}
return result;
};
hsSelf.isValidKey=function(key){
return typeof key=="string";
};
var storageField_=null;
hsSelf.init=function(){
if(hsSelf.initialized_)return;
var fieldName="historyStorageField";
storageField_=_gel(fieldName);
if(!storageField_){
var styleValue=" style='position:absolute;top:-1000px;left:-1000px'";
document.write(
"<form id=historyStorageForm method=GET"+styleValue+
"><textarea id="+fieldName+" name="+fieldName+
styleValue+" left=-1000px></textarea></form>");
storageField_=_gel(fieldName);
}
hsSelf.initialized_=true;
};
function LoadHashTable(){
if(!hashLoaded_){
hsSelf.init();
var serializedHashTable=storageField_.value;
if(serializedHashTable!=""&&
serializedHashTable!=null){
storageHash_=eval('('+serializedHashTable+')');
}
hashLoaded_=true;
}
};
hsSelf.stringify=function(arg){
var c,i,l,s='',v;
switch(typeof arg){
case 'object':
if(arg){
if(arg instanceof Array||
(typeof arg.join=="function"&&
typeof arg.reverse=="function")){
for(i=0;i<arg.length;++i){
v=hsSelf.stringify(arg[i]);
if(s){
s+=',';
}
s+=v;
}
return '['+s+']';
}else if(typeof arg.toString!='undefined'){
for(i in arg){
v=arg[i];
if(typeof v!='undefined'&&typeof v!='function'){
v=hsSelf.stringify(v);
if(s){
s+=',';
}
s+=hsSelf.stringify(i)+':'+v;
}
}
return '{'+s+'}';
}
}
return 'null';
case 'number':
return isFinite(arg)?String(arg):'null';
case 'string':
l=arg.length;
s='"';
for(i=0;i<l;i+=1){
c=arg.charAt(i);
if(c>=' '){
if(c=='\\' || c == '"') {
s+='\\';
}
s+=c;
}else{
switch(c){
case '\b':
s+='\\b';
break;
case '\f':
s+='\\f';
break;
case '\n':
s+='\\n';
break;
case '\r':
s+='\\r';
break;
case '\t':
s+='\\t';
break;
default:
c=c.charCodeAt();
s+='\\u00'+Math.floor(c/ 16).toString(16)+
(c%16).toString(16);
break;
}
}
}
return s+'"';
case 'boolean':
return String(arg);
default:
return 'null';
}
};
function SaveHashTable(){
LoadHashTable();
storageField_.value=hsSelf.stringify(storageHash_);
};
})();
self.getStorage=function(){
return self.historyStorage_;
};
Create();
function simpleBindEvent(element,event,listener){
var onevent='on'+event;
if(element.addEventListener){
element.addEventListener(event,listener,false);
}else if(element.attachEvent){
element.attachEvent(onevent,listener);
}else{
var old=element[onevent];
element[onevent]=function(){
var rv1=old.apply(this,arguments);
var rv2=listener.apply(this,arguments);
return rv1==undefined?rv2:
(rv2==undefined?rv1:rv2&&rv1);
}
}
};
})();
(function(){
var ANIMATION_SLICE_MS=10;
var animations=[];
var timerId;
var sorted;
function animationSorter(a,b){
if(a.startTime==b.startTime){
return a.property?0:1;
}
return(a.startTime-b.startTime);
}
function defragmentAnimations(){
var old=animations;
animations=[];
for(var i=0;i<old.length;++i){
if(old[i]!=null){
animations.push(old[i]);
}
}
}
function animate(){
sorted=false;
if(timerId){
window.clearTimeout(timerId);
timerId=null;
}
timerId=window.setTimeout(animationLoop,0);
}
function animateNow(){
sorted=false;
if(timerId){
window.clearTimeout(timerId);
timerId=null;
}
animationLoop();
}
function animationLoop(){
var now=(new Date()).valueOf();
var active=false;
var defrag=false;
if(!sorted){
animations.sort(animationSorter);
sorted=true;
}
for(var i=0;i<animations.length;++i){
var ani=animations[i];
try{
if(ani.startTime>now){
break;
}
if(ani.endTime<=now){
if(ani.property){
ani.object[ani.property]=ani.interpolator?ani.interpolator(
ani.startValue,
ani.targetValue,
1,
ani.timeline
):ani.targetValue;
}else if(typeof(ani.targetValue)=='function'){
ani.targetValue(ani.object,now);
}
animations[i]=null;
defrag=true;
continue;
}
var duration=ani.endTime-ani.startTime;
if(ani.property){
ani.object[ani.property]=ani.interpolator(
ani.startValue,
ani.targetValue,
(now-ani.startTime)/ duration,
ani.timeline
);
active=true;
}
}catch(e){
animations[i]=null;
defrag=true;
}
}
if(defrag){
defragmentAnimations();
}
if(active){
timerId=window.setTimeout(animationLoop,ANIMATION_SLICE_MS);
}else if(animations.length>0){
timerId=window.setTimeout(animationLoop,animations[0].startTime-now);
}
}
function animateProperty(
element,object,property,startValue,targetValue,delay,duration,
interpolator,timeline,opt_restore,opt_hold){
var startTime=(new Date()).valueOf()+delay*1000;
var endTime=startTime+duration*1000;
var animationProperties={
element:element,
object:object,
property:property,
startValue:startValue,
targetValue:targetValue,
startTime:startTime,
endTime:endTime,
interpolator:((typeof interpolator=='function')?
interpolator:interpolators[interpolator]),
timeline:timelines[timeline]
};
animations.push(animationProperties);
if(opt_restore){
opt_hold=opt_hold||0;
animations.push({
element:element,
object:object,
property:property,
startValue:null,
targetValue:object[property],
startTime:opt_hold*1000+endTime+1,
endTime:opt_hold*1000+endTime+1
});
}
animate();
return animationProperties;
};
function animatePropertyDiscrete(element,object,property,values,delay,duration,opt_restore,opt_hold){
function interpolator(start,end,position,timeline){
var pos=timeline(start,end,position);
return values[Math.round(pos*(values.length-1))];
}
animateProperty(element,object,property,0,1,delay,duration,
interpolator,'linear',opt_restore,opt_hold);
}
function delaySetProperty(element,object,property,targetValue,delay,opt_restore,opt_hold){
animateProperty(element,object,property,targetValue,
targetValue,delay,0,null,null,opt_restore,opt_hold);
}
function pad2(str){
if(str.length<2){
return '0'+str;
}
return str;
}
function scheduleAction(element,object,callback,delay,opt_callback_cleanup,opt_hold){
animateProperty(element,object,null,null,callback,delay,0);
if(opt_hold){
var runTime=(new Date()).valueOf()+delay*1000;
var cleanupTime=runTime+opt_hold*1000;
animations.push({
element:element,
object:object,
targetValue:opt_callback_cleanup,
startTime:cleanupTime,
endTime:cleanupTime
});
}
animate();
}
function repeatAction(element,object,callback,delay,interval,times){
var nextTime=(new Date()).valueOf()+delay*1000;
var i=0;
(function eachTime(object,now){
if(i>0){
callback(i-1,now<nextTime);
}
if(i<times){
animations.push({
element:element,
object:object,
startTime:nextTime,
endTime:nextTime,
targetValue:eachTime
});
nextTime=nextTime+interval*1000;
animate();
}
i++;
})();
}
function isAncestorOrSelf(old,young){
try{
var cur=young;
do{
if(cur==old){
return true;
}
}while(cur=cur.parentNode);
return false;
}catch(e){
return false;
}
}
function endAllAnimations(){
var now=(new Date()).valueOf();
for(var i=0;i<animations.length;++i){
var cur=animations[i];
cur.startTime=now-1;
cur.endTime=now;
}
animateNow();
}
function endAnimations(element){
animateNow();
var now=(new Date()).valueOf();
for(var i=0;i<animations.length;++i){
var cur=animations[i];
if(isAncestorOrSelf(element,cur.element)){
cur.startTime=now;
cur.endTime=now;
}
}
animateNow();
}
function parseRgb(rgb){
if(rgb.indexOf('rgb')==0){
segs=rgb.split(/[^0-9]+/);
return '#'+
pad2(parseInt(segs[1]).toString(16))+
pad2(parseInt(segs[2]).toString(16))+
pad2(parseInt(segs[3]).toString(16));
}else if(rgb.length==4){
return '#'+
rgb.charAt(1)+'0'+rgb.charAt(2)+'0'+rgb.charAt(3)+'0';
}else{
return rgb;
}
}
function parsePx(px){
if(!px)return 0;
if(typeof(px)=='number')return px;
return parseInt(px.replace('px',''));
}
var timelines={
linear:function(v0,v1,pos){
return v0*(1-pos)+v1*pos;
},
decelerate:function(v0,v1,pos){
pos=1-(pos-1)*(pos-1);
return v0*(1-pos)+v1*pos;
},
sine:function(v0,v1,pos){
var rads=Math.PI/2;
var scomp=Math.sin(pos*rads);
var ccomp=1-Math.sin(rads+pos*rads);
var pos=ccomp*(1-pos)+scomp*pos;
return v0*(1-pos)+v1*pos;
}
};
var interpolators={
rgb3:function(color0,color1,position,timeline){
var i,result='',digit0,digit1,newvalue,newdigit;
for(i=1;i<4;++i){
digit0=parseInt(color0.charAt(i),16);
digit1=parseInt(color1.charAt(i),16);
newvalue=Math.round(timeline(digit0*16,digit1*16,position));
result+=pad2(newvalue.toString(16));
}
return '#'+result;
},
rgb6:function(color0,color1,position,timeline){
var i,result='',digit0,digit1,newvalue,newdigit;
for(i=0;i<3;++i){
digit0=parseInt(color0.substr(i*2+1,2),16);
digit1=parseInt(color1.substr(i*2+1,2),16);
newvalue=Math.round(timeline(digit0,digit1,position));
result+=pad2(newvalue.toString(16));
}
return '#'+result;
},
number:function(num0,num1,position,timeline){
return timeline(num0,num1,position);
},
integer:function(num0,num1,position,timeline){
return Math.round(timeline(num0,num1,position));
},
px:function(px0,px1,position,timeline){
return Math.round(timeline(parsePx(px0),parsePx(px1),position))+'px';
},
filter:function(num0,num1,position,timeline){
return 'alpha(opacity='+timeline(num0*100,num1*100,position)+')';
}
};
window.scheduleAction=scheduleAction;
window.repeatAction=repeatAction;
window.animateProperty=animateProperty;
window.animatePropertyDiscrete=animatePropertyDiscrete;
window.endAnimations=endAnimations;
window.endAllAnimations=endAllAnimations;
window.delaySetProperty=delaySetProperty;
window.parseRgb=parseRgb;
window.parsePx=parsePx;
window.animateProperty.interpolators=interpolators;
window.animateProperty.timelines=timelines;
})();
function ani(){}
ani.DEFAULT_MESSAGE_DELAY=10;
ani.DEFAULT_MESSAGE_FADEOUT=2;
ani.DEFAULT_MESSAGE_SLIDE=0.5;
ani.USE_OPACITY=0;
ani.USE_FILTER=1;
ani.TRANSPARENCY_METHOD=null;
function poller(interval,limit,callback){
if(limit>0){
try{
callback();
}catch(e){
setTimeout(function(){
poller(interval,limit-interval,callback);
},interval);
}
}
}
ani.isIE=!!eval('/*@cc_on!@*/false');
if(ani.isIE){
ani.TRANSPARENCY_METHOD=ani.USE_FILTER;
}else{
ani.TRANSPARENCY_METHOD=ani.USE_OPACITY;
}
ani.fade=function(el,start,end,delay,duration,opt_restore,opt_restore_delay){
if(ani.TRANSPARENCY_METHOD==ani.USE_OPACITY){
animateProperty(el,el.style,'opacity',start,end,delay,duration,
'number','linear',opt_restore,opt_restore_delay);
}else if(ani.TRANSPARENCY_METHOD==ani.USE_FILTER){
animateProperty(el,el.style,'filter',start,end,delay,duration,
'filter','linear',opt_restore,opt_restore_delay);
}
}
ani.fadeDuringSlideUp=function(el,delay,duration){
ani.wrap(el,function(wrapper){
endAnimations(wrapper);
animateProperty(wrapper,wrapper.style,'height',wrapper.offsetHeight+'px',
'1px',delay,duration,'px','sine',true);
animateProperty(wrapper,wrapper.style,'opacity','1.0','0.0',delay,duration,
'number','sine',true);
animateProperty(wrapper,wrapper.style,'filter','1.0','0.0',delay,duration,
'filter','sine',true);
delaySetProperty(el,el.style,'display','none',delay+duration);
},delay,duration);
};
ani.fadeAndSlideUp=function(el,delay,fadeDuration,slideDuration){
var wrapper=ani.insertWrapper(el);
wrapper.style.height=wrapper.offsetHeight+10+'px';
wrapper.style.overflow='hidden';
wrapper.style.position='relative';
animateProperty(wrapper,wrapper.style,'height',wrapper.offsetHeight+'px',
wrapper.offsetHeight+'px',delay,fadeDuration,'px','linear');
ani.fade(wrapper,'1.0','0.0',delay,fadeDuration);
animateProperty(wrapper,wrapper.style,'height',wrapper.offsetHeight+'px',
'1px',delay+fadeDuration,slideDuration,'px','sine');
delaySetProperty(el,el.style,'display','none',delay+fadeDuration+
slideDuration);
scheduleAction(wrapper,wrapper,ani.removeWrapper,delay+fadeDuration+
slideDuration+1);
};
ani.slideDownAndFadeIn=function(el,delay,fadeDuration,slideDuration){
ani.wrap(el,function(wrapper){
wrapper.style.visibility="hidden";
var height=ani.getDimensions(wrapper).height;
animateProperty(wrapper,wrapper.style,'height','1px',height+'px',
delay,slideDuration,'px','sine');
animateProperty(wrapper,wrapper.style,'height',height+'px',
height+'px',delay+slideDuration,fadeDuration,'px','linear');
ani.fade(wrapper,0,1,delay+slideDuration,fadeDuration);
wrapper.style.height="1px";
delaySetProperty(wrapper,wrapper.style,'visibility','visible',delay+slideDuration);
scheduleAction(wrapper,wrapper,ani.exciseNode,delay+fadeDuration+slideDuration);
},delay,-1,10);
};
ani.ajaxSlideOpen=function(el,delay,duration,opt_start_height,opt_end_height){
var height=ani.getDimensions(el).height;
if(!opt_end_height){
opt_end_height=height;
}
if(!opt_start_height){
opt_start_height=1;
}
if(el.animation_property_margin){
var prop=el.animation_property_margin;
prop.startTime=(new Date()).valueOf();
prop.endTime=(new Date()).valueOf()+duration*1000;
prop.startValue=el.wrapper.style.marginTop;
prop.targetValue=(opt_end_height-height)+'px';
prop.timeline=window.animateProperty.timelines.decelerate;
var prop_h=el.animation_property_height;
prop_h.startTime=(new Date()).valueOf();
prop_h.endTime=(new Date()).valueOf()+duration*1000;
prop_h.startValue=el.style.height;
prop_h.targetValue=opt_end_height+'px';
prop_h.timeline=window.animateProperty.timelines.decelerate;
}else{
ani.wrap(el,function(wrapper){
wrapper.style.height=opt_start_height+'px';
el.wrapper=wrapper;
el.animation_property_margin=animateProperty(el,el.style,
'marginTop',(opt_start_height-height)+'px',(opt_end_height-height)+'px',delay,
duration,'px','sine');
el.animation_property_height=animateProperty(wrapper,wrapper.style,
'height',opt_start_height+'px',opt_end_height+'px',delay,
duration,'px','sine');
delaySetProperty(el,el,'animation_property_margin',null,delay+duration);
delaySetProperty(el,el.style,'marginTop','0',delay+duration);
delaySetProperty(el,el.style,'display','block',delay);
},delay,duration,0);
}
};
ani.ajaxSlideSideways=function(el,delay,duration,opt_only_reveal,opt_start_width,opt_end_width){
var width=ani.getDimensions(el).width;
if(!opt_end_width){
opt_end_width=width;
}
if(!opt_start_width){
opt_start_width=1;
}
if(el.animation_property_margin){
var prop=el.animation_property_margin;
prop.startTime=(new Date()).valueOf();
prop.endTime=(new Date()).valueOf()+duration*1000;
prop.startValue=el.wrapper.style.marginTop;
prop.targetValue=(opt_end_width-width)+'px';
prop.timeline=window.animateProperty.timelines.decelerate;
var prop_h=el.animation_property_width;
prop_h.startTime=(new Date()).valueOf();
prop_h.endTime=(new Date()).valueOf()+duration*1000;
prop_h.startValue=el.style.width;
prop_h.targetValue=opt_end_width+'px';
prop_h.timeline=window.animateProperty.timelines.decelerate;
}else{
ani.wrap(el,function(wrapper){
wrapper.style.width=opt_start_width+'px';
el.wrapper=wrapper;
if(!opt_only_reveal){
el.animation_property_margin=animateProperty(el,el.style,
'marginLeft',(opt_start_width-width)+'px',(opt_end_width-width)+'px',delay,duration,'px','sine');
}
el.animation_property_width=animateProperty(wrapper,wrapper.style,
'width',opt_start_width+'px',opt_end_width+'px',delay,duration,'px','sine');
delaySetProperty(el,el,'animation_property_margin',null,delay+duration);
delaySetProperty(el,el.style,'marginLeft','0',delay+duration);
delaySetProperty(el,el.style,'display','block',delay);
},delay,duration,0);
}
};
ani.slideClosedBySpeed=function(el,pxPerSecond,callback){
var duration=el.offsetHeight/ pxPerSecond;
ani.wrap(el,function(wrapper){
var start_height=wrapper.offsetHeight;
animateProperty(el,el.style,
'marginTop','0px',(1-start_height)+'px',0,
duration,'px','linear',true,0);
animateProperty(wrapper,wrapper.style,'height',start_height+'px','1px',
0,duration,'px','linear');
},0,duration);
scheduleAction(el,el,callback,duration);
};
ani.measureHeight=function(el){
var oldPosition=el.style.position;
el.style.position='absolute';
el.style.visibility='hidden';
el.style.display='block';
var height=el.offsetHeight;
el.style.display='none';
el.style.visibility='visible';
el.style.position=oldPosition;
return height;
}
ani.slideOpenBySpeed=function(el,pxPerSecond,callback){
var end_height=ani.measureHeight(el);
var duration=end_height/ pxPerSecond;
ani.wrap(el,function(wrapper){
wrapper.style.height='0px';
el.style.display='block';
animateProperty(el,el.style,
'marginTop',-end_height+'px','0px',0,duration,
'px','linear',true,0);
animateProperty(wrapper,wrapper.style,
'height','0px',end_height+'px',0,duration,
'px','linear');
},0,duration);
if(callback)scheduleAction(el,el,callback,duration);
};
ani.slideClosed=function(el,delay,duration){
ani.wrap(el,function(wrapper){
var start_height=wrapper.offsetHeight;
animateProperty(el,el.style,
'marginTop','0px',(1-start_height)+'px',delay,
duration,'px','sine',true);
animateProperty(wrapper,wrapper.style,'height',start_height+'px','1px',
delay,duration,'px','sine');
delaySetProperty(el,el.style,'display','none',delay+duration,true);
scheduleAction(wrapper,wrapper,function(div){
div.parentNode.removeChild(div);},delay+duration);
},delay,-1,0);
};
ani.wrap=function(el,callback,delay,duration,opt_extra_height){
var wrapper=ani.insertWrapper(el);
opt_extra_height=opt_extra_height||0;
wrapper.style.height=wrapper.offsetHeight+opt_extra_height+'px';
wrapper.style.overflow='hidden';
wrapper.style.position='relative';
callback(wrapper);
function teardown(el){
ani.removeWrapper(wrapper);
}
if(duration>0){
scheduleAction(el,el,null,delay,teardown,duration);
}
};
ani.insertWrapper=function(el){
var wrapper=document.createElement('div');
wrapper.style.margin='0px';
wrapper.style.padding='0px';
el.parentNode.insertBefore(wrapper,el);
el.parentNode.removeChild(el);
wrapper.appendChild(el);
return wrapper;
};
ani.removeWrapper=function(wrapper){
var el=wrapper.firstChild;
wrapper.removeChild(el);
wrapper.parentNode.insertBefore(el,wrapper);
wrapper.parentNode.removeChild(wrapper);
};
ani.exciseNode=function(el){
var par=el.parentNode;
var node=el.firstChild;
while(node=el.firstChild){
el.removeChild(node);
par.insertBefore(node,el);
}
par.removeChild(el);
}
ani.getPosition=function(target){
var left=0;
var top=0;
do{
left+=target.offsetLeft;
top+=target.offsetTop;
}while(target=target.offsetParent);
return{x:left,y:top};
}
ani.getDimensions=function(el){
var dimensions={};
ani.wrap(el,function(wrapper){
dimensions.width=wrapper.offsetWidth;
dimensions.height=wrapper.offsetHeight;
dimensions.top=wrapper.offsetTop;
dimensions.left=wrapper.offsetLeft;
ani.exciseNode(wrapper);
});
return dimensions;
};
ani.hideAndFloatClone=function(el,opt_duration){
var clone;
ani.wrap(el,function(wrapper){
clone=wrapper.cloneNode(true);
clone.style.left=wrapper.offsetLeft+"px";
clone.style.top=wrapper.offsetTop+"px";
clone.style.width=wrapper.offsetWidth+'px';
clone.style.height=wrapper.offsetHeight+'px';
ani.exciseNode(wrapper);
});
clone.firstChild.id=el.id+"-clone";
clone.style.position="absolute";
el.style.visibility="hidden";
el.offsetParent.insertBefore(clone,el.offsetParent.firstChild);
clone.style.zIndex=el.style.zIndex?el.style.zIndex+1:"100";
clone.style.clear="both";
if(opt_duration){
function teardown(el){
el.style.visibility="visible";
setTimeout(function(){removeNode(clone);},0);
}
scheduleAction(el,el,null,0,teardown,opt_duration);
}
return clone;
};
ani.slideTo=function(el,start_top,start_left,end_top,end_left,duration,opt_use_clone){
var ani_obj=opt_use_clone?ani.hideAndFloatClone(el,duration):el;
ani_obj.style.visibility="visible";
animateProperty(ani_obj,ani_obj.style,'top',start_top,end_top,0,duration,
'px','decelerate');
animateProperty(ani_obj,ani_obj.style,'left',start_left,end_left,0,duration,
'px','decelerate');
};
ani.swapDivs=function(a,b,duration){
var a_clone=ani.hideAndFloatClone(a,duration+0.25);
var b_clone=ani.hideAndFloatClone(b,duration+0.25);
ani.fade(a_clone,1,0.5,0,duration/ 4);
ani.fade(b_clone,1,0.5,0,duration/ 4);
ani.fade(a_clone,0.5,1,3*duration/ 4,duration/ 4);
ani.fade(b_clone,0.5,1,3*duration/ 4,duration/ 4);
var b_next=b.nextSibling;
a.parentNode.insertBefore(b,a.nextSibling);
b.parentNode.insertBefore(a,b_next);
var a_dim=ani.getDimensions(a);
var b_dim=ani.getDimensions(b);
if(a.offsetTop!=b.offsetTop){
animateProperty(a_clone,a_clone.style,'top',a_clone.style.top,a_dim.top+'px',0,duration,'px','sine');
animateProperty(b_clone,b_clone.style,'top',b_clone.style.top,b_dim.top+'px',0,duration,'px','sine');
}
if(a.offsetLeft!=b.offsetLeft){
animateProperty(a_clone,a_clone.style,'left',a_clone.style.left,a_dim.left+'px',0,duration,'px','sine');
animateProperty(b_clone,b_clone.style,'left',b_clone.style.left,b_dim.left+'px',0,duration,'px','sine');
}
};
ani.crossfadeReveal=function(hide,show,reveal,speed,opt_height,opt_oncompleteCallback){
var w=hide.offsetWidth;
var h=hide.offsetHeight;
hide.style.position='absolute';
hide.style.width=w+'px';
hide.style.height=h+'px';
var origHeight=h;
hide._origHeight=origHeight;
var duration;
var targetHeight;
function animateWrapper(wrapper){
reveal.style.display='block';
targetHeight=opt_height?opt_height:ani.getDimensions(reveal).height;
duration=Math.min((Math.abs(targetHeight-origHeight))/ speed,2.0);
ani.fade(hide,'1.0','0.0',0,duration);
if(show){
ani.fade(show,'0.0','1.0',0,duration);
}
wrapper.style.overflow='hidden';
wrapper.style.height=origHeight;
animateProperty(wrapper,wrapper.style,'height',origHeight+'px',targetHeight+'px',0,duration,'px','decelerate');
scheduleAction(wrapper,wrapper,ani.exciseNode,duration);
if(opt_oncompleteCallback){
scheduleAction(reveal,reveal,opt_oncompleteCallback,duration);
}
}
ani.wrap(reveal,animateWrapper,0,-1);
return{height:targetHeight,duration:duration};
};
ani.crossfadeRevealUndo=function(hide,show,reveal,speed,opt_height,opt_oncompleteCallback){
var duration;
var origHeight;
var targetHeight;
function animateWrapper(wrapper){
origHeight=hide._origHeight;
targetHeight=opt_height?opt_height:ani.getDimensions(reveal).height;
wrapper.style.overflow='hidden';
wrapper.style.height=targetHeight;
duration=Math.min((Math.abs(targetHeight-origHeight))/ speed,2.0);
ani.fade(hide,'0.0','1.0',0,duration);
if(show){
ani.fade(show,'1.0','0.0',0,duration);
}
delaySetProperty(reveal,reveal.style,'display','none',duration-0.1);
delaySetProperty(hide,hide.style,'position','static',duration);
animateProperty(wrapper,wrapper.style,'height',targetHeight+'px',origHeight+'px',0,duration,'px','decelerate');
scheduleAction(wrapper,wrapper,ani.exciseNode,duration);
if(opt_oncompleteCallback){
scheduleAction(reveal,reveal,opt_oncompleteCallback,duration);
}
}
ani.wrap(reveal,animateWrapper,0,-1);
return{height:targetHeight,duration:duration};
};
function removeNode(el){
el=_gel(el);
if(el&&el.parentNode)el.parentNode.removeChild(el);
}
ani.fadeAndMakeUnclickable=function(el,opt_opacity,opt_background){
var opacity=opt_opacity||0.3;
var background=opt_background||'white';
var pos=ani.getPosition(el);
var curtain=document.createElement('iframe');
curtain.frameBorder="0";
curtain.scrolling="no";
curtain.style.position="absolute";
var border_size=el.clientLeft||0;
curtain.style.top=(pos.y-border_size)+"px";
curtain.style.left=(pos.x-border_size)+"px";
curtain.style.width=(el.offsetWidth+border_size*2)+"px";
curtain.style.height=(el.offsetHeight+border_size*2)+"px";
curtain.style.background=background;
curtain.style.opacity=opacity;
curtain.style.filter="alpha(opacity="+Math.round(opacity*100)+")";
curtain.style.zIndex=el.style.zIndex?el.style.zIndex+1:101;
curtain.style.border="0";
curtain.style.margin="0";
curtain.style.overflow="hidden";
return curtain;
};
ani.scrollUntilVisible=function(el,opt_duration){
if(!opt_duration){
opt_duration=0.75;
}
var top=ani.getPosition(el).y;
var bottom=top+ani.getDimensions(el).height;
var docEl=document.body.scrollTop>=document.documentElement.scrollTop?
document.body:document.documentElement;
var browserHeight=window.innerHeight?window.innerHeight:docEl.clientHeight;
if(self.pageYOffset){
var scrollTop=Math.max(self.pageYOffset,docEl.scrollTop);
}else{
var scrollTop=docEl.scrollTop;
}
var scrollBottom=scrollTop+browserHeight;
var targetTop=-1;
var FRIENDLY_PADDING=10;
if(top<scrollTop){
targetTop=top-FRIENDLY_PADDING;
}else if(bottom>scrollBottom){
targetTop=bottom-browserHeight+FRIENDLY_PADDING;
}
if(targetTop>0){
animateProperty(docEl,docEl,'scrollTop',scrollTop,targetTop,0,opt_duration,'number','decelerate');
return true;
}
return false;
};
var ZIPPY_ANIMATION_DURATION=0.05;
var ZIPPY_ANIMATION_OFFSETS=[
'0 0','-13px 0','-26px 0','-39px 0','-52px 0','-65px 0','-78px 0'
];
var ZIPPY_ANIMATION_OFFSETS_REVERSED=
ZIPPY_ANIMATION_OFFSETS.slice().reverse();
function animateZippyOpen(element){
animatePropertyDiscrete(
element,element.style,'backgroundPosition',ZIPPY_ANIMATION_OFFSETS,0,
ZIPPY_ANIMATION_DURATION);
}
function animateZippyClosed(element){
animatePropertyDiscrete(
element,element.style,'backgroundPosition',
ZIPPY_ANIMATION_OFFSETS_REVERSED,0,ZIPPY_ANIMATION_DURATION);
}
var YT=YT||{};
var _shortTitlePattern=/(.{1,32})\W/;
function VideoContainer(){
this.videos=[];
this.addVideo=function(encrypted_id,title,link,thumbnail,avg_rating,length_seconds){
var video={};
video.encrypted_id=encrypted_id;
video.title=title;
video.link=link;
video.thumbnail=thumbnail;
video.avg_rating=avg_rating;
video.length_seconds=length_seconds;
video.shortTitle=function(){
if(title.length>=35){
var match=title.match(_shortTitlePattern)
if(match){
return match[1]+"...";
}else{
return title.substr(0,32)+"...";
}
}
return title;
}
this.videos[this.videos.length]=video;
};
this.getVideo=function(index){
return this.videos[index];
};
this.size=function(){
return this.videos.length;
};
this.empty=function(){
return this.videos.length==0;
};
};
function VideoResultRenderer(noVideoResultText,videoViewText,pagerText){
var rating_widgets={};
this.formatDuration=function(lengthSeconds){
var hours=Math.floor(lengthSeconds/ 3600);
var minutes=Math.floor((lengthSeconds%3600)/ 60);
var seconds=lengthSeconds%60;
var result=[];
if(hours>0){
result[result.length]=(hours<10?"0":"")+hours;
}
result[result.length]=(minutes<10?"0":"")+minutes;
result[result.length]=(seconds<10?"0":"")+seconds;
return result.join(":");
};
this.addVideo=function(content,video){
content.push('<div class="vlcell" style="width: 125px; height: 135px; margin: 0px 2px 15px 2px; zoom: 1; overflow: hidden;">');
content.push('  <div id="'+video.encrypted_id+'" class="vlentry">');
content.push('    <div class="vlcontainer">');
content.push('      <div class="v120WideEntry" id="video-thumb">');
content.push('	<div class="v120WrapperOuter">');
content.push('	  <div class="v120WrapperInner" onclick="GreetingCard.showVideoPlayer(\''+video.link+'\', \''+video.encrypted_id+'\');">');
content.push('	    <img alt="" class="vimg120" src="'+video.thumbnail+'" title="'+video.title+'"/>');
content.push('	  </div>');
content.push('	</div>');
content.push('      </div>');
content.push('      <div class="vldescbox">');
content.push('	<div class="vltitle">');
content.push('	  <div class="vlshortTitle">');
content.push('	    <a  onclick="GreetingCard.showVideoPlayer(\''+video.link+'\', \''+video.encrypted_id+'\');" title="'+video.title+'">'+video.shortTitle()+'</a>');
content.push('	  </div>');
content.push('	</div>');
content.push('      </div>');
content.push('    </div>');
content.push('    <div class="vlfacets">');
content.push('      <div class="video-thumb-duration-rating">');
content.push(rating_widgets[this.getInternalRating(video.avg_rating)]);
content.push('	<div class="runtime">'+this.formatDuration(video.length_seconds)+'</div>');
content.push('      </div>');
content.push('    </div>');
content.push('  </div>');
content.push('</div>');
};
this.render=function(videos,page,maxVideosPerPage,totalVideos,dynamicSearch,pagingFunction){
var content=[];
if(videos.empty()){
content.push(noVideoResultText);
}else{
content.push('<div class="grid-view videoResultEntry">');
var videoOffset=dynamicSearch?0:(page-1)*maxVideosPerPage;
for(i=videoOffset;(i<videoOffset+maxVideosPerPage)&&(i<videos.size());++i){
var video=videos.getVideo(i);
this.addVideo(content,video);
}
content.push('</div>');
content.push('<div class="pagingDiv pager">');
var expected_pages=Math.ceil(totalVideos/ maxVideosPerPage);
content.push(pagerText);
if(page>1){
content.push('<span class="pagerNotCurrent" onclick="'+pagingFunction+'('+(page-1)+');">&lt;&lt;</span>');
if(page>3){
content.push('...');
}
}
for(i=Math.max(1,page-2);i<=Math.min(expected_pages,page+2);++i){
if(i===page){
content.push('<span class="pagerCurrent">'+i+'</span>');
}else{
content.push('<span class="pagerNotCurrent" onclick="'+pagingFunction+'('+i+');">'+i+'</span>');
}
}
if(page<expected_pages){
if((page+2)<expected_pages){
content.push('...');
}
content.push('<span class="pagerNotCurrent" onclick="'+pagingFunction+'('+(page+1)+');">&gt;&gt;</span>');
}
content.push('</div>');
}
return content.join("");
};
this.getInternalRating=function(avg_rating){
return Math.round((Number(avg_rating)+0.25)*2);
};
this.addStarRatingWidget=function(avg_rating,widget){
var rating=this.getInternalRating(avg_rating);
rating_widgets[rating]=widget;
};
};
var GreetingCard=function(){
var preselectedVideos;
var ownedVideos;
var renderer;
return{
insertScript:function(query){
var script=document.createElement('script');
script.type='text/javascript';
script.src=query;
document.body.appendChild(script);
},
getTotalResultsJSON:function(feed){
if(!feed.openSearch$totalResults||!feed.openSearch$totalResults.$t){
return 0;
}
return feed.openSearch$totalResults.$t;
},
getPageJSON:function(feed){
if(!feed.openSearch$startIndex||!feed.openSearch$startIndex.$t){
return 1;
}
return 1+Math.floor(feed.openSearch$startIndex.$t/ 4);
},
getVideoLinkJSON:function(video){
if(!video.media$group||!video.media$group.media$content||!video.media$group.media$content[0]||!video.media$group.media$content[0].url){
return "";
}
return video.media$group.media$content[0].url;
},
getVideoThumbnailJSON:function(video){
if(!video.media$group||!video.media$group.media$thumbnail||!video.media$group.media$thumbnail[0]||!video.media$group.media$thumbnail[0].url){
return "";
}
return video.media$group.media$thumbnail[0].url;
},
getVideoTitleJSON:function(video){
if(!video.title||!video.title.$t){
return "";
}
return video.title.$t;
},
getVideoAverageRatingJSON:function(video){
if(!video.gd$rating||!video.gd$rating.average){
return 0;
}
return video.gd$rating.average;
},
getVideoLengthSecondsJSON:function(video){
if(!video.media$group||!video.media$group.yt$duration||!video.media$group.yt$duration.seconds){
return 0;
}
return video.media$group.yt$duration.seconds;
},
renderVideoResultsJSON:function(root){
var feed=root.feed;
var videos=feed.entry||[];
var video_container=new VideoContainer();
var total_results=this.getTotalResultsJSON(feed);
var page=this.getPageJSON(feed);
var pattern=/.*\/v\/([^&]+).*/;
for(i=0;i<videos.length;++i){
var link=this.getVideoLinkJSON(videos[i]);
var matching_result=link.match(pattern);
if(matching_result){
encrypted_id=matching_result[1];
}else{
continue;
}
var thumbnail=this.getVideoThumbnailJSON(videos[i]);
var title=this.getVideoTitleJSON(videos[i]);
var avg_rating=this.getVideoAverageRatingJSON(videos[i]);
var length_seconds=this.getVideoLengthSecondsJSON(videos[i]);
video_container.addVideo(encrypted_id,title,link,thumbnail,avg_rating,length_seconds);
}
return renderer.render(video_container,page,4,total_results,true,"GreetingCard.performVideoSearch");
},
updateSearchResults:function(req){
var watchSearchButton=_gel("searchbox_submit");
if(watchSearchButton){
watchSearchButton.disabled=false;
}
var searchResults=_gel("search_results");
searchResults.innerHTML=GreetingCard.renderVideoResultsJSON(req);
searchResults.style.textAlign="left";
},
performVideoSearch:function(page){
var searchResults=_gel("search_results");
searchResults.style.textAlign="center";
searchResults.style.display="block";
searchResults.innerHTML="<img src='http://s.ytimg.com/yt/img/LoadingGraphic-vfl3869.gif'>";
var watchSearchButton=_gel("searchbox_submit");
if(watchSearchButton){
watchSearchButton.disabled=true;
}
var query=_gel("searchbox").value;
GreetingCard.insertScript("http://gdata.youtube.com/feeds/api/videos?q="+encodeURIComponent(query)+"&max-results=4&start-index="+(((page-1)*4)+1)+"&client=ytapi-youtube-greetingcard&alt=json-in-script&callback=GreetingCard.updateSearchResults");
},
showPreselection:function(page){
var videoProposals=_gel("videoProposals");
videoProposals.innerHTML=renderer.render(preselectedVideos,page,12,preselectedVideos.size(),false,"GreetingCard.showPreselection");
},
showOwned:function(page){
if(ownedVideos.size()>0){
var videoOwned=_gel("videoOwned");
videoOwned.innerHTML=renderer.render(ownedVideos,page,6,ownedVideos.size(),false,"GreetingCard.showOwned");
}
},
showVideoPlayer:function(embedUrl,videoId){
yt.overlay.getPlayer(videoId,embedUrl);
},
chooseVideo:function(videoId){
_gel("video_id").value=videoId;
document.getElementById("video_select").submit();
},
hideVideoPlayer:function(){
yt.overlay.hide();
_gel("video_id").value="";
},
showQuickCapture:function(vidcapData){
yt.overlay.getCapture(vidcapData);
},
hideQuickCapture:function(){
yt.overlay.hide();
},
init:function(document,videoRenderer,preselection,owned,selectVideoText,closeVideoText){
preselectedVideos=preselection;
ownedVideos=owned;
renderer=videoRenderer;
yt.overlay.install(425,344,closeVideoText,selectVideoText,function(video_id){GreetingCard.chooseVideo(video_id);});
GreetingCard.showPreselection(1);
GreetingCard.showOwned(1);
GreetingCard.hideVideoPlayer();
GreetingCard.hideQuickCapture();
}
}
}();
