/*
---
MooTools: the javascript framework

web build:
 - http://mootools.net/core/7c56cfef9dddcf170a5d68e3fb61cfd7

packager build:
 - packager build Core/Core Core/Array Core/String Core/Number Core/Function Core/Object Core/Event Core/Browser Core/Class Core/Class.Extras Core/Slick.Parser Core/Slick.Finder Core/Element Core/Element.Style Core/Element.Event Core/Element.Dimensions Core/Fx Core/Fx.CSS Core/Fx.Tween Core/Fx.Morph Core/Fx.Transitions Core/Request Core/Request.HTML Core/Request.JSON Core/Cookie Core/JSON Core/DOMReady Core/Swiff

copyrights:
  - [MooTools](http://mootools.net)

licenses:
  - [MIT License](http://mootools.net/license.txt)
...
*/
(function(){this.MooTools={version:"1.3.1",build:"af48c8d589f43f32212f9bb8ff68a127e6a3ba6c"};var e=this.typeOf=function(i){if(i==null){return"null";}if(i.$family){return i.$family();
}if(i.nodeName){if(i.nodeType==1){return"element";}if(i.nodeType==3){return(/\S/).test(i.nodeValue)?"textnode":"whitespace";}}else{if(typeof i.length=="number"){if(i.callee){return"arguments";
}if("item" in i){return"collection";}}}return typeof i;};var u=this.instanceOf=function(w,i){if(w==null){return false;}var v=w.$constructor||w.constructor;
while(v){if(v===i){return true;}v=v.parent;}return w instanceof i;};var f=this.Function;var r=true;for(var q in {toString:1}){r=null;}if(r){r=["hasOwnProperty","valueOf","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","constructor"];
}f.prototype.overloadSetter=function(v){var i=this;return function(x,w){if(x==null){return this;}if(v||typeof x!="string"){for(var y in x){i.call(this,y,x[y]);
}if(r){for(var z=r.length;z--;){y=r[z];if(x.hasOwnProperty(y)){i.call(this,y,x[y]);}}}}else{i.call(this,x,w);}return this;};};f.prototype.overloadGetter=function(v){var i=this;
return function(x){var y,w;if(v||typeof x!="string"){y=x;}else{if(arguments.length>1){y=arguments;}}if(y){w={};for(var z=0;z<y.length;z++){w[y[z]]=i.call(this,y[z]);
}}else{w=i.call(this,x);}return w;};};f.prototype.extend=function(i,v){this[i]=v;}.overloadSetter();f.prototype.implement=function(i,v){this.prototype[i]=v;
}.overloadSetter();var o=Array.prototype.slice;f.from=function(i){return(e(i)=="function")?i:function(){return i;};};Array.from=function(i){if(i==null){return[];
}return(k.isEnumerable(i)&&typeof i!="string")?(e(i)=="array")?i:o.call(i):[i];};Number.from=function(v){var i=parseFloat(v);return isFinite(i)?i:null;
};String.from=function(i){return i+"";};f.implement({hide:function(){this.$hidden=true;return this;},protect:function(){this.$protected=true;return this;
}});var k=this.Type=function(x,w){if(x){var v=x.toLowerCase();var i=function(y){return(e(y)==v);};k["is"+x]=i;if(w!=null){w.prototype.$family=(function(){return v;
}).hide();w.type=i;}}if(w==null){return null;}w.extend(this);w.$constructor=k;w.prototype.$constructor=w;return w;};var p=Object.prototype.toString;k.isEnumerable=function(i){return(i!=null&&typeof i.length=="number"&&p.call(i)!="[object Function]");
};var b={};var d=function(i){var v=e(i.prototype);return b[v]||(b[v]=[]);};var h=function(w,A){if(A&&A.$hidden){return;}var v=d(this);for(var x=0;x<v.length;
x++){var z=v[x];if(e(z)=="type"){h.call(z,w,A);}else{z.call(this,w,A);}}var y=this.prototype[w];if(y==null||!y.$protected){this.prototype[w]=A;}if(this[w]==null&&e(A)=="function"){t.call(this,w,function(i){return A.apply(i,o.call(arguments,1));
});}};var t=function(i,w){if(w&&w.$hidden){return;}var v=this[i];if(v==null||!v.$protected){this[i]=w;}};k.implement({implement:h.overloadSetter(),extend:t.overloadSetter(),alias:function(i,v){h.call(this,i,this.prototype[v]);
}.overloadSetter(),mirror:function(i){d(this).push(i);return this;}});new k("Type",k);var c=function(v,z,x){var w=(z!=Object),D=z.prototype;if(w){z=new k(v,z);
}for(var A=0,y=x.length;A<y;A++){var E=x[A],C=z[E],B=D[E];if(C){C.protect();}if(w&&B){delete D[E];D[E]=B.protect();}}if(w){z.implement(D);}return c;};c("String",String,["charAt","charCodeAt","concat","indexOf","lastIndexOf","match","quote","replace","search","slice","split","substr","substring","toLowerCase","toUpperCase"])("Array",Array,["pop","push","reverse","shift","sort","splice","unshift","concat","join","slice","indexOf","lastIndexOf","filter","forEach","every","map","some","reduce","reduceRight"])("Number",Number,["toExponential","toFixed","toLocaleString","toPrecision"])("Function",f,["apply","call","bind"])("RegExp",RegExp,["exec","test"])("Object",Object,["create","defineProperty","defineProperties","keys","getPrototypeOf","getOwnPropertyDescriptor","getOwnPropertyNames","preventExtensions","isExtensible","seal","isSealed","freeze","isFrozen"])("Date",Date,["now"]);
Object.extend=t.overloadSetter();Date.extend("now",function(){return +(new Date);});new k("Boolean",Boolean);Number.prototype.$family=function(){return isFinite(this)?"number":"null";
}.hide();Number.extend("random",function(v,i){return Math.floor(Math.random()*(i-v+1)+v);});var l=Object.prototype.hasOwnProperty;Object.extend("forEach",function(i,w,x){for(var v in i){if(l.call(i,v)){w.call(x,i[v],v,i);
}}});Object.each=Object.forEach;Array.implement({forEach:function(x,y){for(var w=0,v=this.length;w<v;w++){if(w in this){x.call(y,this[w],w,this);}}},each:function(i,v){Array.forEach(this,i,v);
return this;}});var s=function(i){switch(e(i)){case"array":return i.clone();case"object":return Object.clone(i);default:return i;}};Array.implement("clone",function(){var v=this.length,w=new Array(v);
while(v--){w[v]=s(this[v]);}return w;});var a=function(v,i,w){switch(e(w)){case"object":if(e(v[i])=="object"){Object.merge(v[i],w);}else{v[i]=Object.clone(w);
}break;case"array":v[i]=w.clone();break;default:v[i]=w;}return v;};Object.extend({merge:function(C,y,x){if(e(y)=="string"){return a(C,y,x);}for(var B=1,w=arguments.length;
B<w;B++){var z=arguments[B];for(var A in z){a(C,A,z[A]);}}return C;},clone:function(i){var w={};for(var v in i){w[v]=s(i[v]);}return w;},append:function(z){for(var y=1,w=arguments.length;
y<w;y++){var v=arguments[y]||{};for(var x in v){z[x]=v[x];}}return z;}});["Object","WhiteSpace","TextNode","Collection","Arguments"].each(function(i){new k(i);
});var j=Date.now();String.extend("uniqueID",function(){return(j++).toString(36);});var g=this.Hash=new k("Hash",function(i){if(e(i)=="hash"){i=Object.clone(i.getClean());
}for(var v in i){this[v]=i[v];}return this;});g.implement({forEach:function(i,v){Object.forEach(this,i,v);},getClean:function(){var v={};for(var i in this){if(this.hasOwnProperty(i)){v[i]=this[i];
}}return v;},getLength:function(){var v=0;for(var i in this){if(this.hasOwnProperty(i)){v++;}}return v;}});g.alias("each","forEach");Object.type=k.isObject;
var n=this.Native=function(i){return new k(i.name,i.initialize);};n.type=k.type;n.implement=function(x,v){for(var w=0;w<x.length;w++){x[w].implement(v);
}return n;};var m=Array.type;Array.type=function(i){return u(i,Array)||m(i);};this.$A=function(i){return Array.from(i).slice();};this.$arguments=function(v){return function(){return arguments[v];
};};this.$chk=function(i){return !!(i||i===0);};this.$clear=function(i){clearTimeout(i);clearInterval(i);return null;};this.$defined=function(i){return(i!=null);
};this.$each=function(w,v,x){var i=e(w);((i=="arguments"||i=="collection"||i=="array"||i=="elements")?Array:Object).each(w,v,x);};this.$empty=function(){};
this.$extend=function(v,i){return Object.append(v,i);};this.$H=function(i){return new g(i);};this.$merge=function(){var i=Array.slice(arguments);i.unshift({});
return Object.merge.apply(null,i);};this.$lambda=f.from;this.$mixin=Object.merge;this.$random=Number.random;this.$splat=Array.from;this.$time=Date.now;
this.$type=function(i){var v=e(i);if(v=="elements"){return"array";}return(v=="null")?false:v;};this.$unlink=function(i){switch(e(i)){case"object":return Object.clone(i);
case"array":return Array.clone(i);case"hash":return new g(i);default:return i;}};}).call(this);Array.implement({invoke:function(a){var b=Array.slice(arguments,1);
return this.map(function(c){return c[a].apply(c,b);});},every:function(c,d){for(var b=0,a=this.length;b<a;b++){if((b in this)&&!c.call(d,this[b],b,this)){return false;
}}return true;},filter:function(d,e){var c=[];for(var b=0,a=this.length;b<a;b++){if((b in this)&&d.call(e,this[b],b,this)){c.push(this[b]);}}return c;},clean:function(){return this.filter(function(a){return a!=null;
});},indexOf:function(c,d){var a=this.length;for(var b=(d<0)?Math.max(0,a+d):d||0;b<a;b++){if(this[b]===c){return b;}}return -1;},map:function(d,e){var c=[];
for(var b=0,a=this.length;b<a;b++){if(b in this){c[b]=d.call(e,this[b],b,this);}}return c;},some:function(c,d){for(var b=0,a=this.length;b<a;b++){if((b in this)&&c.call(d,this[b],b,this)){return true;
}}return false;},associate:function(c){var d={},b=Math.min(this.length,c.length);for(var a=0;a<b;a++){d[c[a]]=this[a];}return d;},link:function(c){var a={};
for(var e=0,b=this.length;e<b;e++){for(var d in c){if(c[d](this[e])){a[d]=this[e];delete c[d];break;}}}return a;},contains:function(a,b){return this.indexOf(a,b)!=-1;
},append:function(a){this.push.apply(this,a);return this;},getLast:function(){return(this.length)?this[this.length-1]:null;},getRandom:function(){return(this.length)?this[Number.random(0,this.length-1)]:null;
},include:function(a){if(!this.contains(a)){this.push(a);}return this;},combine:function(c){for(var b=0,a=c.length;b<a;b++){this.include(c[b]);}return this;
},erase:function(b){for(var a=this.length;a--;){if(this[a]===b){this.splice(a,1);}}return this;},empty:function(){this.length=0;return this;},flatten:function(){var d=[];
for(var b=0,a=this.length;b<a;b++){var c=typeOf(this[b]);if(c=="null"){continue;}d=d.concat((c=="array"||c=="collection"||c=="arguments"||instanceOf(this[b],Array))?Array.flatten(this[b]):this[b]);
}return d;},pick:function(){for(var b=0,a=this.length;b<a;b++){if(this[b]!=null){return this[b];}}return null;},hexToRgb:function(b){if(this.length!=3){return null;
}var a=this.map(function(c){if(c.length==1){c+=c;}return c.toInt(16);});return(b)?a:"rgb("+a+")";},rgbToHex:function(d){if(this.length<3){return null;}if(this.length==4&&this[3]==0&&!d){return"transparent";
}var b=[];for(var a=0;a<3;a++){var c=(this[a]-0).toString(16);b.push((c.length==1)?"0"+c:c);}return(d)?b:"#"+b.join("");}});Array.alias("extend","append");
var $pick=function(){return Array.from(arguments).pick();};String.implement({test:function(a,b){return((typeOf(a)=="regexp")?a:new RegExp(""+a,b)).test(this);
},contains:function(a,b){return(b)?(b+this+b).indexOf(b+a+b)>-1:this.indexOf(a)>-1;},trim:function(){return this.replace(/^\s+|\s+$/g,"");},clean:function(){return this.replace(/\s+/g," ").trim();
},camelCase:function(){return this.replace(/-\D/g,function(a){return a.charAt(1).toUpperCase();});},hyphenate:function(){return this.replace(/[A-Z]/g,function(a){return("-"+a.charAt(0).toLowerCase());
});},capitalize:function(){return this.replace(/\b[a-z]/g,function(a){return a.toUpperCase();});},escapeRegExp:function(){return this.replace(/([-.*+?^${}()|[\]\/\\])/g,"\\$1");
},toInt:function(a){return parseInt(this,a||10);},toFloat:function(){return parseFloat(this);},hexToRgb:function(b){var a=this.match(/^#?(\w{1,2})(\w{1,2})(\w{1,2})$/);
return(a)?a.slice(1).hexToRgb(b):null;},rgbToHex:function(b){var a=this.match(/\d{1,3}/g);return(a)?a.rgbToHex(b):null;},substitute:function(a,b){return this.replace(b||(/\\?\{([^{}]+)\}/g),function(d,c){if(d.charAt(0)=="\\"){return d.slice(1);
}return(a[c]!=null)?a[c]:"";});}});Number.implement({limit:function(b,a){return Math.min(a,Math.max(b,this));},round:function(a){a=Math.pow(10,a||0).toFixed(a<0?-a:0);
return Math.round(this*a)/a;},times:function(b,c){for(var a=0;a<this;a++){b.call(c,a,this);}},toFloat:function(){return parseFloat(this);},toInt:function(a){return parseInt(this,a||10);
}});Number.alias("each","times");(function(b){var a={};b.each(function(c){if(!Number[c]){a[c]=function(){return Math[c].apply(null,[this].concat(Array.from(arguments)));
};}});Number.implement(a);})(["abs","acos","asin","atan","atan2","ceil","cos","exp","floor","log","max","min","pow","sin","sqrt","tan"]);Function.extend({attempt:function(){for(var b=0,a=arguments.length;
b<a;b++){try{return arguments[b]();}catch(c){}}return null;}});Function.implement({attempt:function(a,c){try{return this.apply(c,Array.from(a));}catch(b){}return null;
},bind:function(c){var a=this,b=(arguments.length>1)?Array.slice(arguments,1):null;return function(){if(!b&&!arguments.length){return a.call(c);}if(b&&arguments.length){return a.apply(c,b.concat(Array.from(arguments)));
}return a.apply(c,b||arguments);};},pass:function(b,c){var a=this;if(b!=null){b=Array.from(b);}return function(){return a.apply(c,b||arguments);};},delay:function(b,c,a){return setTimeout(this.pass((a==null?[]:a),c),b);
},periodical:function(c,b,a){return setInterval(this.pass((a==null?[]:a),b),c);}});delete Function.prototype.bind;Function.implement({create:function(b){var a=this;
b=b||{};return function(d){var c=b.arguments;c=(c!=null)?Array.from(c):Array.slice(arguments,(b.event)?1:0);if(b.event){c=[d||window.event].extend(c);}var e=function(){return a.apply(b.bind||null,c);
};if(b.delay){return setTimeout(e,b.delay);}if(b.periodical){return setInterval(e,b.periodical);}if(b.attempt){return Function.attempt(e);}return e();};
},bind:function(c,b){var a=this;if(b!=null){b=Array.from(b);}return function(){return a.apply(c,b||arguments);};},bindWithEvent:function(c,b){var a=this;
if(b!=null){b=Array.from(b);}return function(d){return a.apply(c,(b==null)?arguments:[d].concat(b));};},run:function(a,b){return this.apply(b,Array.from(a));
}});var $try=Function.attempt;(function(){var a=Object.prototype.hasOwnProperty;Object.extend({subset:function(d,g){var f={};for(var e=0,b=g.length;e<b;
e++){var c=g[e];f[c]=d[c];}return f;},map:function(b,e,f){var d={};for(var c in b){if(a.call(b,c)){d[c]=e.call(f,b[c],c,b);}}return d;},filter:function(b,d,e){var c={};
Object.each(b,function(g,f){if(d.call(e,g,f,b)){c[f]=g;}});return c;},every:function(b,d,e){for(var c in b){if(a.call(b,c)&&!d.call(e,b[c],c)){return false;
}}return true;},some:function(b,d,e){for(var c in b){if(a.call(b,c)&&d.call(e,b[c],c)){return true;}}return false;},keys:function(b){var d=[];for(var c in b){if(a.call(b,c)){d.push(c);
}}return d;},values:function(c){var b=[];for(var d in c){if(a.call(c,d)){b.push(c[d]);}}return b;},getLength:function(b){return Object.keys(b).length;},keyOf:function(b,d){for(var c in b){if(a.call(b,c)&&b[c]===d){return c;
}}return null;},contains:function(b,c){return Object.keyOf(b,c)!=null;},toQueryString:function(b,c){var d=[];Object.each(b,function(h,g){if(c){g=c+"["+g+"]";
}var f;switch(typeOf(h)){case"object":f=Object.toQueryString(h,g);break;case"array":var e={};h.each(function(k,j){e[j]=k;});f=Object.toQueryString(e,g);
break;default:f=g+"="+encodeURIComponent(h);}if(h!=null){d.push(f);}});return d.join("&");}});})();Hash.implement({has:Object.prototype.hasOwnProperty,keyOf:function(a){return Object.keyOf(this,a);
},hasValue:function(a){return Object.contains(this,a);},extend:function(a){Hash.each(a||{},function(c,b){Hash.set(this,b,c);},this);return this;},combine:function(a){Hash.each(a||{},function(c,b){Hash.include(this,b,c);
},this);return this;},erase:function(a){if(this.hasOwnProperty(a)){delete this[a];}return this;},get:function(a){return(this.hasOwnProperty(a))?this[a]:null;
},set:function(a,b){if(!this[a]||this.hasOwnProperty(a)){this[a]=b;}return this;},empty:function(){Hash.each(this,function(b,a){delete this[a];},this);
return this;},include:function(a,b){if(this[a]==null){this[a]=b;}return this;},map:function(a,b){return new Hash(Object.map(this,a,b));},filter:function(a,b){return new Hash(Object.filter(this,a,b));
},every:function(a,b){return Object.every(this,a,b);},some:function(a,b){return Object.some(this,a,b);},getKeys:function(){return Object.keys(this);},getValues:function(){return Object.values(this);
},toQueryString:function(a){return Object.toQueryString(this,a);}});Hash.extend=Object.append;Hash.alias({indexOf:"keyOf",contains:"hasValue"});(function(){var l=this.document;
var j=l.window=this;var b=1;this.$uid=(j.ActiveXObject)?function(e){return(e.uid||(e.uid=[b++]))[0];}:function(e){return e.uid||(e.uid=b++);};$uid(j);$uid(l);
var a=navigator.userAgent.toLowerCase(),c=navigator.platform.toLowerCase(),k=a.match(/(opera|ie|firefox|chrome|version)[\s\/:]([\w\d\.]+)?.*?(safari|version[\s\/:]([\w\d\.]+)|$)/)||[null,"unknown",0],g=k[1]=="ie"&&l.documentMode;
var p=this.Browser={extend:Function.prototype.extend,name:(k[1]=="version")?k[3]:k[1],version:g||parseFloat((k[1]=="opera"&&k[4])?k[4]:k[2]),Platform:{name:a.match(/ip(?:ad|od|hone)/)?"ios":(a.match(/(?:webos|android)/)||c.match(/mac|win|linux/)||["other"])[0]},Features:{xpath:!!(l.evaluate),air:!!(j.runtime),query:!!(l.querySelector),json:!!(j.JSON)},Plugins:{}};
p[p.name]=true;p[p.name+parseInt(p.version,10)]=true;p.Platform[p.Platform.name]=true;p.Request=(function(){var r=function(){return new XMLHttpRequest();
};var q=function(){return new ActiveXObject("MSXML2.XMLHTTP");};var e=function(){return new ActiveXObject("Microsoft.XMLHTTP");};return Function.attempt(function(){r();
return r;},function(){q();return q;},function(){e();return e;});})();p.Features.xhr=!!(p.Request);var i=(Function.attempt(function(){return navigator.plugins["Shockwave Flash"].description;
},function(){return new ActiveXObject("ShockwaveFlash.ShockwaveFlash").GetVariable("$version");})||"0 r0").match(/\d+/g);p.Plugins.Flash={version:Number(i[0]||"0."+i[1])||0,build:Number(i[2])||0};
p.exec=function(q){if(!q){return q;}if(j.execScript){j.execScript(q);}else{var e=l.createElement("script");e.setAttribute("type","text/javascript");e.text=q;
l.head.appendChild(e);l.head.removeChild(e);}return q;};String.implement("stripScripts",function(q){var e="";var r=this.replace(/<script[^>]*>([\s\S]*?)<\/script>/gi,function(s,t){e+=t+"\n";
return"";});if(q===true){p.exec(e);}else{if(typeOf(q)=="function"){q(e,r);}}return r;});p.extend({Document:this.Document,Window:this.Window,Element:this.Element,Event:this.Event});
this.Window=this.$constructor=new Type("Window",function(){});this.$family=Function.from("window").hide();Window.mirror(function(e,q){j[e]=q;});this.Document=l.$constructor=new Type("Document",function(){});
l.$family=Function.from("document").hide();Document.mirror(function(e,q){l[e]=q;});l.html=l.documentElement;l.head=l.getElementsByTagName("head")[0];if(l.execCommand){try{l.execCommand("BackgroundImageCache",false,true);
}catch(h){}}if(this.attachEvent&&!this.addEventListener){var d=function(){this.detachEvent("onunload",d);l.head=l.html=l.window=null;};this.attachEvent("onunload",d);
}var n=Array.from;try{n(l.html.childNodes);}catch(h){Array.from=function(q){if(typeof q!="string"&&Type.isEnumerable(q)&&typeOf(q)!="array"){var e=q.length,r=new Array(e);
while(e--){r[e]=q[e];}return r;}return n(q);};var m=Array.prototype,o=m.slice;["pop","push","reverse","shift","sort","splice","unshift","concat","join","slice"].each(function(e){var q=m[e];
Array[e]=function(r){return q.apply(Array.from(r),o.call(arguments,1));};});}if(p.Platform.ios){p.Platform.ipod=true;}p.Engine={};var f=function(q,e){p.Engine.name=q;
p.Engine[q+e]=true;p.Engine.version=e;};if(p.ie){p.Engine.trident=true;switch(p.version){case 6:f("trident",4);break;case 7:f("trident",5);break;case 8:f("trident",6);
}}if(p.firefox){p.Engine.gecko=true;if(p.version>=3){f("gecko",19);}else{f("gecko",18);}}if(p.safari||p.chrome){p.Engine.webkit=true;switch(p.version){case 2:f("webkit",419);
break;case 3:f("webkit",420);break;case 4:f("webkit",525);}}if(p.opera){p.Engine.presto=true;if(p.version>=9.6){f("presto",960);}else{if(p.version>=9.5){f("presto",950);
}else{f("presto",925);}}}if(p.name=="unknown"){switch((a.match(/(?:webkit|khtml|gecko)/)||[])[0]){case"webkit":case"khtml":p.Engine.webkit=true;break;case"gecko":p.Engine.gecko=true;
}}this.$exec=p.exec;}).call(this);var Event=new Type("Event",function(a,i){if(!i){i=window;}var o=i.document;a=a||i.event;if(a.$extended){return a;}this.$extended=true;
var n=a.type,k=a.target||a.srcElement,m={},c={},q=null,h,l,b,p;while(k&&k.nodeType==3){k=k.parentNode;}if(n.indexOf("key")!=-1){b=a.which||a.keyCode;p=Object.keyOf(Event.Keys,b);
if(n=="keydown"){var d=b-111;if(d>0&&d<13){p="f"+d;}}if(!p){p=String.fromCharCode(b).toLowerCase();}}else{if((/click|mouse|menu/i).test(n)){o=(!o.compatMode||o.compatMode=="CSS1Compat")?o.html:o.body;
m={x:(a.pageX!=null)?a.pageX:a.clientX+o.scrollLeft,y:(a.pageY!=null)?a.pageY:a.clientY+o.scrollTop};c={x:(a.pageX!=null)?a.pageX-i.pageXOffset:a.clientX,y:(a.pageY!=null)?a.pageY-i.pageYOffset:a.clientY};
if((/DOMMouseScroll|mousewheel/).test(n)){l=(a.wheelDelta)?a.wheelDelta/120:-(a.detail||0)/3;}h=(a.which==3)||(a.button==2);if((/over|out/).test(n)){q=a.relatedTarget||a[(n=="mouseover"?"from":"to")+"Element"];
var j=function(){while(q&&q.nodeType==3){q=q.parentNode;}return true;};var g=(Browser.firefox2)?j.attempt():j();q=(g)?q:null;}}else{if((/gesture|touch/i).test(n)){this.rotation=a.rotation;
this.scale=a.scale;this.targetTouches=a.targetTouches;this.changedTouches=a.changedTouches;var f=this.touches=a.touches;if(f&&f[0]){var e=f[0];m={x:e.pageX,y:e.pageY};
c={x:e.clientX,y:e.clientY};}}}}return Object.append(this,{event:a,type:n,page:m,client:c,rightClick:h,wheel:l,relatedTarget:document.id(q),target:document.id(k),code:b,key:p,shift:a.shiftKey,control:a.ctrlKey,alt:a.altKey,meta:a.metaKey});
});Event.Keys={enter:13,up:38,down:40,left:37,right:39,esc:27,space:32,backspace:8,tab:9,"delete":46};Event.Keys=new Hash(Event.Keys);Event.implement({stop:function(){return this.stopPropagation().preventDefault();
},stopPropagation:function(){if(this.event.stopPropagation){this.event.stopPropagation();}else{this.event.cancelBubble=true;}return this;},preventDefault:function(){if(this.event.preventDefault){this.event.preventDefault();
}else{this.event.returnValue=false;}return this;}});(function(){var a=this.Class=new Type("Class",function(h){if(instanceOf(h,Function)){h={initialize:h};
}var g=function(){e(this);if(g.$prototyping){return this;}this.$caller=null;var i=(this.initialize)?this.initialize.apply(this,arguments):this;this.$caller=this.caller=null;
return i;}.extend(this).implement(h);g.$constructor=a;g.prototype.$constructor=g;g.prototype.parent=c;return g;});var c=function(){if(!this.$caller){throw new Error('The method "parent" cannot be called.');
}var g=this.$caller.$name,h=this.$caller.$owner.parent,i=(h)?h.prototype[g]:null;if(!i){throw new Error('The method "'+g+'" has no parent.');}return i.apply(this,arguments);
};var e=function(g){for(var h in g){var j=g[h];switch(typeOf(j)){case"object":var i=function(){};i.prototype=j;g[h]=e(new i);break;case"array":g[h]=j.clone();
break;}}return g;};var b=function(g,h,j){if(j.$origin){j=j.$origin;}var i=function(){if(j.$protected&&this.$caller==null){throw new Error('The method "'+h+'" cannot be called.');
}var l=this.caller,m=this.$caller;this.caller=m;this.$caller=i;var k=j.apply(this,arguments);this.$caller=m;this.caller=l;return k;}.extend({$owner:g,$origin:j,$name:h});
return i;};var f=function(h,i,g){if(a.Mutators.hasOwnProperty(h)){i=a.Mutators[h].call(this,i);if(i==null){return this;}}if(typeOf(i)=="function"){if(i.$hidden){return this;
}this.prototype[h]=(g)?i:b(this,h,i);}else{Object.merge(this.prototype,h,i);}return this;};var d=function(g){g.$prototyping=true;var h=new g;delete g.$prototyping;
return h;};a.implement("implement",f.overloadSetter());a.Mutators={Extends:function(g){this.parent=g;this.prototype=d(g);},Implements:function(g){Array.from(g).each(function(j){var h=new j;
for(var i in h){f.call(this,i,h[i],true);}},this);}};}).call(this);(function(){this.Chain=new Class({$chain:[],chain:function(){this.$chain.append(Array.flatten(arguments));
return this;},callChain:function(){return(this.$chain.length)?this.$chain.shift().apply(this,arguments):false;},clearChain:function(){this.$chain.empty();
return this;}});var a=function(b){return b.replace(/^on([A-Z])/,function(c,d){return d.toLowerCase();});};this.Events=new Class({$events:{},addEvent:function(d,c,b){d=a(d);
if(c==$empty){return this;}this.$events[d]=(this.$events[d]||[]).include(c);if(b){c.internal=true;}return this;},addEvents:function(b){for(var c in b){this.addEvent(c,b[c]);
}return this;},fireEvent:function(e,c,b){e=a(e);var d=this.$events[e];if(!d){return this;}c=Array.from(c);d.each(function(f){if(b){f.delay(b,this,c);}else{f.apply(this,c);
}},this);return this;},removeEvent:function(e,d){e=a(e);var c=this.$events[e];if(c&&!d.internal){var b=c.indexOf(d);if(b!=-1){delete c[b];}}return this;
},removeEvents:function(d){var e;if(typeOf(d)=="object"){for(e in d){this.removeEvent(e,d[e]);}return this;}if(d){d=a(d);}for(e in this.$events){if(d&&d!=e){continue;
}var c=this.$events[e];for(var b=c.length;b--;){if(b in c){this.removeEvent(e,c[b]);}}}return this;}});this.Options=new Class({setOptions:function(){var b=this.options=Object.merge.apply(null,[{},this.options].append(arguments));
if(this.addEvent){for(var c in b){if(typeOf(b[c])!="function"||!(/^on[A-Z]/).test(c)){continue;}this.addEvent(c,b[c]);delete b[c];}}return this;}});}).call(this);
(function(){var k,n,l,g,a={},c={},m=/\\/g;var e=function(q,p){if(q==null){return null;}if(q.Slick===true){return q;}q=(""+q).replace(/^\s+|\s+$/g,"");g=!!p;
var o=(g)?c:a;if(o[q]){return o[q];}k={Slick:true,expressions:[],raw:q,reverse:function(){return e(this.raw,true);}};n=-1;while(q!=(q=q.replace(j,b))){}k.length=k.expressions.length;
return o[k.raw]=(g)?h(k):k;};var i=function(o){if(o==="!"){return" ";}else{if(o===" "){return"!";}else{if((/^!/).test(o)){return o.replace(/^!/,"");}else{return"!"+o;
}}}};var h=function(u){var r=u.expressions;for(var p=0;p<r.length;p++){var t=r[p];var q={parts:[],tag:"*",combinator:i(t[0].combinator)};for(var o=0;o<t.length;
o++){var s=t[o];if(!s.reverseCombinator){s.reverseCombinator=" ";}s.combinator=s.reverseCombinator;delete s.reverseCombinator;}t.reverse().push(q);}return u;
};var f=function(o){return o.replace(/[-[\]{}()*+?.\\^$|,#\s]/g,function(p){return"\\"+p;});};var j=new RegExp("^(?:\\s*(,)\\s*|\\s*(<combinator>+)\\s*|(\\s+)|(<unicode>+|\\*)|\\#(<unicode>+)|\\.(<unicode>+)|\\[\\s*(<unicode1>+)(?:\\s*([*^$!~|]?=)(?:\\s*(?:([\"']?)(.*?)\\9)))?\\s*\\](?!\\])|(:+)(<unicode>+)(?:\\((?:(?:([\"'])([^\\13]*)\\13)|((?:\\([^)]+\\)|[^()]*)+))\\))?)".replace(/<combinator>/,"["+f(">+~`!@$%^&={}\\;</")+"]").replace(/<unicode>/g,"(?:[\\w\\u00a1-\\uFFFF-]|\\\\[^\\s0-9a-f])").replace(/<unicode1>/g,"(?:[:\\w\\u00a1-\\uFFFF-]|\\\\[^\\s0-9a-f])"));
function b(x,s,D,z,r,C,q,B,A,y,u,F,G,v,p,w){if(s||n===-1){k.expressions[++n]=[];l=-1;if(s){return"";}}if(D||z||l===-1){D=D||" ";var t=k.expressions[n];
if(g&&t[l]){t[l].reverseCombinator=i(D);}t[++l]={combinator:D,tag:"*"};}var o=k.expressions[n][l];if(r){o.tag=r.replace(m,"");}else{if(C){o.id=C.replace(m,"");
}else{if(q){q=q.replace(m,"");if(!o.classList){o.classList=[];}if(!o.classes){o.classes=[];}o.classList.push(q);o.classes.push({value:q,regexp:new RegExp("(^|\\s)"+f(q)+"(\\s|$)")});
}else{if(G){w=w||p;w=w?w.replace(m,""):null;if(!o.pseudos){o.pseudos=[];}o.pseudos.push({key:G.replace(m,""),value:w,type:F.length==1?"class":"element"});
}else{if(B){B=B.replace(m,"");u=(u||"").replace(m,"");var E,H;switch(A){case"^=":H=new RegExp("^"+f(u));break;case"$=":H=new RegExp(f(u)+"$");break;case"~=":H=new RegExp("(^|\\s)"+f(u)+"(\\s|$)");
break;case"|=":H=new RegExp("^"+f(u)+"(-|$)");break;case"=":E=function(I){return u==I;};break;case"*=":E=function(I){return I&&I.indexOf(u)>-1;};break;
case"!=":E=function(I){return u!=I;};break;default:E=function(I){return !!I;};}if(u==""&&(/^[*$^]=$/).test(A)){E=function(){return false;};}if(!E){E=function(I){return I&&H.test(I);
};}if(!o.attributes){o.attributes=[];}o.attributes.push({key:B,operator:A,value:u,test:E});}}}}}return"";}var d=(this.Slick||{});d.parse=function(o){return e(o);
};d.escapeRegExp=f;if(!this.Slick){this.Slick=d;}}).apply((typeof exports!="undefined")?exports:this);(function(){var j={},l={},b=Object.prototype.toString;
j.isNativeCode=function(c){return(/\{\s*\[native code\]\s*\}/).test(""+c);};j.isXML=function(c){return(!!c.xmlVersion)||(!!c.xml)||(b.call(c)=="[object XMLDocument]")||(c.nodeType==9&&c.documentElement.nodeName!="HTML");
};j.setDocument=function(w){var t=w.nodeType;if(t==9){}else{if(t){w=w.ownerDocument;}else{if(w.navigator){w=w.document;}else{return;}}}if(this.document===w){return;
}this.document=w;var y=w.documentElement,u=this.getUIDXML(y),o=l[u],A;if(o){for(A in o){this[A]=o[A];}return;}o=l[u]={};o.root=y;o.isXMLDocument=this.isXML(w);
o.brokenStarGEBTN=o.starSelectsClosedQSA=o.idGetsName=o.brokenMixedCaseQSA=o.brokenGEBCN=o.brokenCheckedQSA=o.brokenEmptyAttributeQSA=o.isHTMLDocument=o.nativeMatchesSelector=false;
var m,n,x,q,r;var s,c="slick_uniqueid";var z=w.createElement("div");var p=w.body||w.getElementsByTagName("body")[0]||y;p.appendChild(z);try{z.innerHTML='<a id="'+c+'"></a>';
o.isHTMLDocument=!!w.getElementById(c);}catch(v){}if(o.isHTMLDocument){z.style.display="none";z.appendChild(w.createComment(""));n=(z.getElementsByTagName("*").length>1);
try{z.innerHTML="foo</foo>";s=z.getElementsByTagName("*");m=(s&&!!s.length&&s[0].nodeName.charAt(0)=="/");}catch(v){}o.brokenStarGEBTN=n||m;try{z.innerHTML='<a name="'+c+'"></a><b id="'+c+'"></b>';
o.idGetsName=w.getElementById(c)===z.firstChild;}catch(v){}if(z.getElementsByClassName){try{z.innerHTML='<a class="f"></a><a class="b"></a>';z.getElementsByClassName("b").length;
z.firstChild.className="b";q=(z.getElementsByClassName("b").length!=2);}catch(v){}try{z.innerHTML='<a class="a"></a><a class="f b a"></a>';x=(z.getElementsByClassName("a").length!=2);
}catch(v){}o.brokenGEBCN=q||x;}if(z.querySelectorAll){try{z.innerHTML="foo</foo>";s=z.querySelectorAll("*");o.starSelectsClosedQSA=(s&&!!s.length&&s[0].nodeName.charAt(0)=="/");
}catch(v){}try{z.innerHTML='<a class="MiX"></a>';o.brokenMixedCaseQSA=!z.querySelectorAll(".MiX").length;}catch(v){}try{z.innerHTML='<select><option selected="selected">a</option></select>';
o.brokenCheckedQSA=(z.querySelectorAll(":checked").length==0);}catch(v){}try{z.innerHTML='<a class=""></a>';o.brokenEmptyAttributeQSA=(z.querySelectorAll('[class*=""]').length!=0);
}catch(v){}}try{z.innerHTML='<form action="s"><input id="action"/></form>';r=(z.firstChild.getAttribute("action")!="s");}catch(v){}o.nativeMatchesSelector=y.matchesSelector||y.mozMatchesSelector||y.webkitMatchesSelector;
if(o.nativeMatchesSelector){try{o.nativeMatchesSelector.call(y,":slick");o.nativeMatchesSelector=null;}catch(v){}}}try{y.slick_expando=1;delete y.slick_expando;
o.getUID=this.getUIDHTML;}catch(v){o.getUID=this.getUIDXML;}p.removeChild(z);z=s=p=null;o.getAttribute=(o.isHTMLDocument&&r)?function(D,B){var E=this.attributeGetters[B];
if(E){return E.call(D);}var C=D.getAttributeNode(B);return(C)?C.nodeValue:null;}:function(C,B){var D=this.attributeGetters[B];return(D)?D.call(C):C.getAttribute(B);
};o.hasAttribute=(y&&this.isNativeCode(y.hasAttribute))?function(C,B){return C.hasAttribute(B);}:function(C,B){C=C.getAttributeNode(B);return !!(C&&(C.specified||C.nodeValue));
};o.contains=(y&&this.isNativeCode(y.contains))?function(B,C){return B.contains(C);}:(y&&y.compareDocumentPosition)?function(B,C){return B===C||!!(B.compareDocumentPosition(C)&16);
}:function(B,C){if(C){do{if(C===B){return true;}}while((C=C.parentNode));}return false;};o.documentSorter=(y.compareDocumentPosition)?function(C,B){if(!C.compareDocumentPosition||!B.compareDocumentPosition){return 0;
}return C.compareDocumentPosition(B)&4?-1:C===B?0:1;}:("sourceIndex" in y)?function(C,B){if(!C.sourceIndex||!B.sourceIndex){return 0;}return C.sourceIndex-B.sourceIndex;
}:(w.createRange)?function(E,C){if(!E.ownerDocument||!C.ownerDocument){return 0;}var D=E.ownerDocument.createRange(),B=C.ownerDocument.createRange();D.setStart(E,0);
D.setEnd(E,0);B.setStart(C,0);B.setEnd(C,0);return D.compareBoundaryPoints(Range.START_TO_END,B);}:null;y=null;for(A in o){this[A]=o[A];}};var e=/^([#.]?)((?:[\w-]+|\*))$/,g=/\[.+[*$^]=(?:""|'')?\]/,f={};
j.search=function(q,D,O,v){var B=this.found=(v)?null:(O||[]);if(!q){return B;}else{if(q.navigator){q=q.document;}else{if(!q.nodeType){return B;}}}var z,N,s=this.uniques={},y=!!(O&&O.length),c=(q.nodeType==9);
if(this.document!==(c?q:q.ownerDocument)){this.setDocument(q);}if(y){for(N=B.length;N--;){s[this.getUID(B[N])]=true;}}if(typeof D=="string"){var C=D.match(e);
simpleSelectors:if(C){var K=C[1],V=C[2],I,G;if(!K){if(V=="*"&&this.brokenStarGEBTN){break simpleSelectors;}G=q.getElementsByTagName(V);if(v){return G[0]||null;
}for(N=0;I=G[N++];){if(!(y&&s[this.getUID(I)])){B.push(I);}}}else{if(K=="#"){if(!this.isHTMLDocument||!c){break simpleSelectors;}I=q.getElementById(V);
if(!I){return B;}if(this.idGetsName&&I.getAttributeNode("id").nodeValue!=V){break simpleSelectors;}if(v){return I||null;}if(!(y&&s[this.getUID(I)])){B.push(I);
}}else{if(K=="."){if(!this.isHTMLDocument||((!q.getElementsByClassName||this.brokenGEBCN)&&q.querySelectorAll)){break simpleSelectors;}if(q.getElementsByClassName&&!this.brokenGEBCN){G=q.getElementsByClassName(V);
if(v){return G[0]||null;}for(N=0;I=G[N++];){if(!(y&&s[this.getUID(I)])){B.push(I);}}}else{var u=new RegExp("(^|\\s)"+d.escapeRegExp(V)+"(\\s|$)");G=q.getElementsByTagName("*");
for(N=0;I=G[N++];){className=I.className;if(!(className&&u.test(className))){continue;}if(v){return I;}if(!(y&&s[this.getUID(I)])){B.push(I);}}}}}}if(y){this.sort(B);
}return(v)?null:B;}querySelector:if(q.querySelectorAll){if(!this.isHTMLDocument||this.brokenMixedCaseQSA||f[D]||(this.brokenCheckedQSA&&D.indexOf(":checked")>-1)||(this.brokenEmptyAttributeQSA&&g.test(D))||d.disableQSA){break querySelector;
}var A=D;if(!c){var M=q.getAttribute("id"),p="slickid__";q.setAttribute("id",p);A="#"+p+" "+A;}try{if(v){return q.querySelector(A)||null;}else{G=q.querySelectorAll(A);
}}catch(P){f[D]=1;break querySelector;}finally{if(!c){if(M){q.setAttribute("id",M);}else{q.removeAttribute("id");}}}if(this.starSelectsClosedQSA){for(N=0;
I=G[N++];){if(I.nodeName>"@"&&!(y&&s[this.getUID(I)])){B.push(I);}}}else{for(N=0;I=G[N++];){if(!(y&&s[this.getUID(I)])){B.push(I);}}}if(y){this.sort(B);
}return B;}z=this.Slick.parse(D);if(!z.length){return B;}}else{if(D==null){return B;}else{if(D.Slick){z=D;}else{if(this.contains(q.documentElement||q,D)){(B)?B.push(D):B=D;
return B;}else{return B;}}}}this.posNTH={};this.posNTHLast={};this.posNTHType={};this.posNTHTypeLast={};this.push=(!y&&(v||(z.length==1&&z.expressions[0].length==1)))?this.pushArray:this.pushUID;
if(B==null){B=[];}var L,H,F;var J,U,E,T,Q,x,t;var w,r,o,R,S=z.expressions;search:for(N=0;(r=S[N]);N++){for(L=0;(o=r[L]);L++){J="combinator:"+o.combinator;
if(!this[J]){continue search;}U=(this.isXMLDocument)?o.tag:o.tag.toUpperCase();E=o.id;T=o.classList;Q=o.classes;x=o.attributes;t=o.pseudos;R=(L===(r.length-1));
this.bitUniques={};if(R){this.uniques=s;this.found=B;}else{this.uniques={};this.found=[];}if(L===0){this[J](q,U,E,Q,x,t,T);if(v&&R&&B.length){break search;
}}else{if(v&&R){for(H=0,F=w.length;H<F;H++){this[J](w[H],U,E,Q,x,t,T);if(B.length){break search;}}}else{for(H=0,F=w.length;H<F;H++){this[J](w[H],U,E,Q,x,t,T);
}}}w=this.found;}}if(y||(z.expressions.length>1)){this.sort(B);}return(v)?(B[0]||null):B;};j.uidx=1;j.uidk="slick-uniqueid";j.getUIDXML=function(m){var c=m.getAttribute(this.uidk);
if(!c){c=this.uidx++;m.setAttribute(this.uidk,c);}return c;};j.getUIDHTML=function(c){return c.uniqueNumber||(c.uniqueNumber=this.uidx++);};j.sort=function(c){if(!this.documentSorter){return c;
}c.sort(this.documentSorter);return c;};j.cacheNTH={};j.matchNTH=/^([+-]?\d*)?([a-z]+)?([+-]\d+)?$/;j.parseNTHArgument=function(p){var n=p.match(this.matchNTH);
if(!n){return false;}var o=n[2]||false;var m=n[1]||1;if(m=="-"){m=-1;}var c=+n[3]||0;n=(o=="n")?{a:m,b:c}:(o=="odd")?{a:2,b:1}:(o=="even")?{a:2,b:0}:{a:0,b:m};
return(this.cacheNTH[p]=n);};j.createNTHPseudo=function(o,m,c,n){return function(r,p){var t=this.getUID(r);if(!this[c][t]){var z=r.parentNode;if(!z){return false;
}var q=z[o],s=1;if(n){var y=r.nodeName;do{if(q.nodeName!=y){continue;}this[c][this.getUID(q)]=s++;}while((q=q[m]));}else{do{if(q.nodeType!=1){continue;
}this[c][this.getUID(q)]=s++;}while((q=q[m]));}}p=p||"n";var u=this.cacheNTH[p]||this.parseNTHArgument(p);if(!u){return false;}var x=u.a,w=u.b,v=this[c][t];
if(x==0){return w==v;}if(x>0){if(v<w){return false;}}else{if(w<v){return false;}}return((v-w)%x)==0;};};j.pushArray=function(o,c,q,n,m,p){if(this.matchSelector(o,c,q,n,m,p)){this.found.push(o);
}};j.pushUID=function(p,c,r,o,m,q){var n=this.getUID(p);if(!this.uniques[n]&&this.matchSelector(p,c,r,o,m,q)){this.uniques[n]=true;this.found.push(p);}};
j.matchNode=function(m,n){if(this.isHTMLDocument&&this.nativeMatchesSelector){try{return this.nativeMatchesSelector.call(m,n.replace(/\[([^=]+)=\s*([^'"\]]+?)\s*\]/g,'[$1="$2"]'));
}catch(u){}}var t=this.Slick.parse(n);if(!t){return true;}var r=t.expressions,p,s=0,q;for(q=0;(currentExpression=r[q]);q++){if(currentExpression.length==1){var o=currentExpression[0];
if(this.matchSelector(m,(this.isXMLDocument)?o.tag:o.tag.toUpperCase(),o.id,o.classes,o.attributes,o.pseudos)){return true;}s++;}}if(s==t.length){return false;
}var c=this.search(this.document,t),v;for(q=0;v=c[q++];){if(v===m){return true;}}return false;};j.matchPseudo=function(p,c,o){var m="pseudo:"+c;if(this[m]){return this[m](p,o);
}var n=this.getAttribute(p,c);return(o)?o==n:!!n;};j.matchSelector=function(n,u,c,o,p,r){if(u){var s=(this.isXMLDocument)?n.nodeName:n.nodeName.toUpperCase();
if(u=="*"){if(s<"@"){return false;}}else{if(s!=u){return false;}}}if(c&&n.getAttribute("id")!=c){return false;}var q,m,t;if(o){for(q=o.length;q--;){t=n.getAttribute("class")||n.className;
if(!(t&&o[q].regexp.test(t))){return false;}}}if(p){for(q=p.length;q--;){m=p[q];if(m.operator?!m.test(this.getAttribute(n,m.key)):!this.hasAttribute(n,m.key)){return false;
}}}if(r){for(q=r.length;q--;){m=r[q];if(!this.matchPseudo(n,m.key,m.value)){return false;}}}return true;};var i={" ":function(p,v,m,q,r,t,o){var s,u,n;
if(this.isHTMLDocument){getById:if(m){u=this.document.getElementById(m);if((!u&&p.all)||(this.idGetsName&&u&&u.getAttributeNode("id").nodeValue!=m)){n=p.all[m];
if(!n){return;}if(!n[0]){n=[n];}for(s=0;u=n[s++];){var c=u.getAttributeNode("id");if(c&&c.nodeValue==m){this.push(u,v,null,q,r,t);break;}}return;}if(!u){if(this.contains(this.root,p)){return;
}else{break getById;}}else{if(this.document!==p&&!this.contains(p,u)){return;}}this.push(u,v,null,q,r,t);return;}getByClass:if(q&&p.getElementsByClassName&&!this.brokenGEBCN){n=p.getElementsByClassName(o.join(" "));
if(!(n&&n.length)){break getByClass;}for(s=0;u=n[s++];){this.push(u,v,m,null,r,t);}return;}}getByTag:{n=p.getElementsByTagName(v);if(!(n&&n.length)){break getByTag;
}if(!this.brokenStarGEBTN){v=null;}for(s=0;u=n[s++];){this.push(u,v,m,q,r,t);}}},">":function(o,c,q,n,m,p){if((o=o.firstChild)){do{if(o.nodeType==1){this.push(o,c,q,n,m,p);
}}while((o=o.nextSibling));}},"+":function(o,c,q,n,m,p){while((o=o.nextSibling)){if(o.nodeType==1){this.push(o,c,q,n,m,p);break;}}},"^":function(o,c,q,n,m,p){o=o.firstChild;
if(o){if(o.nodeType==1){this.push(o,c,q,n,m,p);}else{this["combinator:+"](o,c,q,n,m,p);}}},"~":function(p,c,r,o,m,q){while((p=p.nextSibling)){if(p.nodeType!=1){continue;
}var n=this.getUID(p);if(this.bitUniques[n]){break;}this.bitUniques[n]=true;this.push(p,c,r,o,m,q);}},"++":function(o,c,q,n,m,p){this["combinator:+"](o,c,q,n,m,p);
this["combinator:!+"](o,c,q,n,m,p);},"~~":function(o,c,q,n,m,p){this["combinator:~"](o,c,q,n,m,p);this["combinator:!~"](o,c,q,n,m,p);},"!":function(o,c,q,n,m,p){while((o=o.parentNode)){if(o!==this.document){this.push(o,c,q,n,m,p);
}}},"!>":function(o,c,q,n,m,p){o=o.parentNode;if(o!==this.document){this.push(o,c,q,n,m,p);}},"!+":function(o,c,q,n,m,p){while((o=o.previousSibling)){if(o.nodeType==1){this.push(o,c,q,n,m,p);
break;}}},"!^":function(o,c,q,n,m,p){o=o.lastChild;if(o){if(o.nodeType==1){this.push(o,c,q,n,m,p);}else{this["combinator:!+"](o,c,q,n,m,p);}}},"!~":function(p,c,r,o,m,q){while((p=p.previousSibling)){if(p.nodeType!=1){continue;
}var n=this.getUID(p);if(this.bitUniques[n]){break;}this.bitUniques[n]=true;this.push(p,c,r,o,m,q);}}};for(var h in i){j["combinator:"+h]=i[h];}var k={empty:function(c){var m=c.firstChild;
return !(m&&m.nodeType==1)&&!(c.innerText||c.textContent||"").length;},not:function(c,m){return !this.matchNode(c,m);},contains:function(c,m){return(c.innerText||c.textContent||"").indexOf(m)>-1;
},"first-child":function(c){while((c=c.previousSibling)){if(c.nodeType==1){return false;}}return true;},"last-child":function(c){while((c=c.nextSibling)){if(c.nodeType==1){return false;
}}return true;},"only-child":function(n){var m=n;while((m=m.previousSibling)){if(m.nodeType==1){return false;}}var c=n;while((c=c.nextSibling)){if(c.nodeType==1){return false;
}}return true;},"nth-child":j.createNTHPseudo("firstChild","nextSibling","posNTH"),"nth-last-child":j.createNTHPseudo("lastChild","previousSibling","posNTHLast"),"nth-of-type":j.createNTHPseudo("firstChild","nextSibling","posNTHType",true),"nth-last-of-type":j.createNTHPseudo("lastChild","previousSibling","posNTHTypeLast",true),index:function(m,c){return this["pseudo:nth-child"](m,""+c+1);
},even:function(c){return this["pseudo:nth-child"](c,"2n");},odd:function(c){return this["pseudo:nth-child"](c,"2n+1");},"first-of-type":function(c){var m=c.nodeName;
while((c=c.previousSibling)){if(c.nodeName==m){return false;}}return true;},"last-of-type":function(c){var m=c.nodeName;while((c=c.nextSibling)){if(c.nodeName==m){return false;
}}return true;},"only-of-type":function(n){var m=n,o=n.nodeName;while((m=m.previousSibling)){if(m.nodeName==o){return false;}}var c=n;while((c=c.nextSibling)){if(c.nodeName==o){return false;
}}return true;},enabled:function(c){return !c.disabled;},disabled:function(c){return c.disabled;},checked:function(c){return c.checked||c.selected;},focus:function(c){return this.isHTMLDocument&&this.document.activeElement===c&&(c.href||c.type||this.hasAttribute(c,"tabindex"));
},root:function(c){return(c===this.root);},selected:function(c){return c.selected;}};for(var a in k){j["pseudo:"+a]=k[a];}j.attributeGetters={"class":function(){return this.getAttribute("class")||this.className;
},"for":function(){return("htmlFor" in this)?this.htmlFor:this.getAttribute("for");},href:function(){return("href" in this)?this.getAttribute("href",2):this.getAttribute("href");
},style:function(){return(this.style)?this.style.cssText:this.getAttribute("style");},tabindex:function(){var c=this.getAttributeNode("tabindex");return(c&&c.specified)?c.nodeValue:null;
},type:function(){return this.getAttribute("type");}};var d=j.Slick=(this.Slick||{});d.version="1.1.5";d.search=function(m,n,c){return j.search(m,n,c);
};d.find=function(c,m){return j.search(c,m,null,true);};d.contains=function(c,m){j.setDocument(c);return j.contains(c,m);};d.getAttribute=function(m,c){return j.getAttribute(m,c);
};d.match=function(m,c){if(!(m&&c)){return false;}if(!c||c===m){return true;}j.setDocument(m);return j.matchNode(m,c);};d.defineAttributeGetter=function(c,m){j.attributeGetters[c]=m;
return this;};d.lookupAttributeGetter=function(c){return j.attributeGetters[c];};d.definePseudo=function(c,m){j["pseudo:"+c]=function(o,n){return m.call(o,n);
};return this;};d.lookupPseudo=function(c){var m=j["pseudo:"+c];if(m){return function(n){return m.call(this,n);};}return null;};d.override=function(m,c){j.override(m,c);
return this;};d.isXML=j.isXML;d.uidOf=function(c){return j.getUIDHTML(c);};if(!this.Slick){this.Slick=d;}}).apply((typeof exports!="undefined")?exports:this);
var Element=function(b,g){var h=Element.Constructors[b];if(h){return h(g);}if(typeof b!="string"){return document.id(b).set(g);}if(!g){g={};}if(!(/^[\w-]+$/).test(b)){var e=Slick.parse(b).expressions[0][0];
b=(e.tag=="*")?"div":e.tag;if(e.id&&g.id==null){g.id=e.id;}var d=e.attributes;if(d){for(var f=0,c=d.length;f<c;f++){var a=d[f];if(a.value!=null&&a.operator=="="&&g[a.key]==null){g[a.key]=a.value;
}}}if(e.classList&&g["class"]==null){g["class"]=e.classList.join(" ");}}return document.newElement(b,g);};if(Browser.Element){Element.prototype=Browser.Element.prototype;
}new Type("Element",Element).mirror(function(a){if(Array.prototype[a]){return;}var b={};b[a]=function(){var h=[],e=arguments,j=true;for(var g=0,d=this.length;
g<d;g++){var f=this[g],c=h[g]=f[a].apply(f,e);j=(j&&typeOf(c)=="element");}return(j)?new Elements(h):h;};Elements.implement(b);});if(!Browser.Element){Element.parent=Object;
Element.Prototype={"$family":Function.from("element").hide()};Element.mirror(function(a,b){Element.Prototype[a]=b;});}Element.Constructors={};Element.Constructors=new Hash;
var IFrame=new Type("IFrame",function(){var e=Array.link(arguments,{properties:Type.isObject,iframe:function(f){return(f!=null);}});var c=e.properties||{},b;
if(e.iframe){b=document.id(e.iframe);}var d=c.onload||function(){};delete c.onload;c.id=c.name=[c.id,c.name,b?(b.id||b.name):"IFrame_"+String.uniqueID()].pick();
b=new Element(b||"iframe",c);var a=function(){d.call(b.contentWindow);};if(window.frames[c.id]){a();}else{b.addListener("load",a);}return b;});var Elements=this.Elements=function(a){if(a&&a.length){var e={},d;
for(var c=0;d=a[c++];){var b=Slick.uidOf(d);if(!e[b]){e[b]=true;this.push(d);}}}};Elements.prototype={length:0};Elements.parent=Array;new Type("Elements",Elements).implement({filter:function(a,b){if(!a){return this;
}return new Elements(Array.filter(this,(typeOf(a)=="string")?function(c){return c.match(a);}:a,b));}.protect(),push:function(){var d=this.length;for(var b=0,a=arguments.length;
b<a;b++){var c=document.id(arguments[b]);if(c){this[d++]=c;}}return(this.length=d);}.protect(),unshift:function(){var b=[];for(var c=0,a=arguments.length;
c<a;c++){var d=document.id(arguments[c]);if(d){b.push(d);}}return Array.prototype.unshift.apply(this,b);}.protect(),concat:function(){var b=new Elements(this);
for(var c=0,a=arguments.length;c<a;c++){var d=arguments[c];if(Type.isEnumerable(d)){b.append(d);}else{b.push(d);}}return b;}.protect(),append:function(c){for(var b=0,a=c.length;
b<a;b++){this.push(c[b]);}return this;}.protect(),empty:function(){while(this.length){delete this[--this.length];}return this;}.protect()});Elements.alias("extend","append");
(function(){var g=Array.prototype.splice,b={"0":0,"1":1,length:2};g.call(b,1,1);if(b[1]==1){Elements.implement("splice",function(){var e=this.length;g.apply(this,arguments);
while(e>=this.length){delete this[e--];}return this;}.protect());}Elements.implement(Array.prototype);Array.mirror(Elements);var f;try{var a=document.createElement("<input name=x>");
f=(a.name=="x");}catch(c){}var d=function(e){return(""+e).replace(/&/g,"&amp;").replace(/"/g,"&quot;");};Document.implement({newElement:function(e,h){if(h&&h.checked!=null){h.defaultChecked=h.checked;
}if(f&&h){e="<"+e;if(h.name){e+=' name="'+d(h.name)+'"';}if(h.type){e+=' type="'+d(h.type)+'"';}e+=">";delete h.name;delete h.type;}return this.id(this.createElement(e)).set(h);
}});})();Document.implement({newTextNode:function(a){return this.createTextNode(a);},getDocument:function(){return this;},getWindow:function(){return this.window;
},id:(function(){var a={string:function(d,c,b){d=Slick.find(b,"#"+d.replace(/(\W)/g,"\\$1"));return(d)?a.element(d,c):null;},element:function(b,c){$uid(b);
if(!c&&!b.$family&&!(/^(?:object|embed)$/i).test(b.tagName)){Object.append(b,Element.Prototype);}return b;},object:function(c,d,b){if(c.toElement){return a.element(c.toElement(b),d);
}return null;}};a.textnode=a.whitespace=a.window=a.document=function(b){return b;};return function(c,e,d){if(c&&c.$family&&c.uid){return c;}var b=typeOf(c);
return(a[b])?a[b](c,e,d||document):null;};})()});if(window.$==null){Window.implement("$",function(a,b){return document.id(a,b,this.document);});}Window.implement({getDocument:function(){return this.document;
},getWindow:function(){return this;}});[Document,Element].invoke("implement",{getElements:function(a){return Slick.search(this,a,new Elements);},getElement:function(a){return document.id(Slick.find(this,a));
}});(function(b,d,a){this.Selectors={};var e=this.Selectors.Pseudo=new Hash();var c=function(){for(var f in e){if(e.hasOwnProperty(f)){Slick.definePseudo(f,e[f]);
delete e[f];}}};Slick.search=function(g,h,f){c();return b.call(this,g,h,f);};Slick.find=function(f,g){c();return d.call(this,f,g);};Slick.match=function(g,f){c();
return a.call(this,g,f);};})(Slick.search,Slick.find,Slick.match);if(window.$$==null){Window.implement("$$",function(a){var f=new Elements;if(arguments.length==1&&typeof a=="string"){return Slick.search(this.document,a,f);
}var c=Array.flatten(arguments);for(var d=0,b=c.length;d<b;d++){var e=c[d];switch(typeOf(e)){case"element":f.push(e);break;case"string":Slick.search(this.document,e,f);
}}return f;});}if(window.$$==null){Window.implement("$$",function(a){if(arguments.length==1){if(typeof a=="string"){return Slick.search(this.document,a,new Elements);
}else{if(Type.isEnumerable(a)){return new Elements(a);}}}return new Elements(arguments);});}(function(){var k={},i={};var n={input:"checked",option:"selected",textarea:"value"};
var e=function(p){return(i[p]||(i[p]={}));};var j=function(q){var p=q.uid;if(q.removeEvents){q.removeEvents();}if(q.clearAttributes){q.clearAttributes();
}if(p!=null){delete k[p];delete i[p];}return q;};var o=["defaultValue","accessKey","cellPadding","cellSpacing","colSpan","frameBorder","maxLength","readOnly","rowSpan","tabIndex","useMap"];
var d=["compact","nowrap","ismap","declare","noshade","checked","disabled","readOnly","multiple","selected","noresize","defer","defaultChecked"];var g={html:"innerHTML","class":"className","for":"htmlFor",text:(function(){var p=document.createElement("div");
return(p.textContent==null)?"innerText":"textContent";})()};var m=["type"];var h=["value","defaultValue"];var l=/^(?:href|src|usemap)$/i;d=d.associate(d);
o=o.associate(o.map(String.toLowerCase));m=m.associate(m);Object.append(g,h.associate(h));var c={before:function(q,p){var r=p.parentNode;if(r){r.insertBefore(q,p);
}},after:function(q,p){var r=p.parentNode;if(r){r.insertBefore(q,p.nextSibling);}},bottom:function(q,p){p.appendChild(q);},top:function(q,p){p.insertBefore(q,p.firstChild);
}};c.inside=c.bottom;Object.each(c,function(q,r){r=r.capitalize();var p={};p["inject"+r]=function(s){q(this,document.id(s,true));return this;};p["grab"+r]=function(s){q(document.id(s,true),this);
return this;};Element.implement(p);});var b=function(s,r){if(!s){return r;}s=Object.clone(Slick.parse(s));var q=s.expressions;for(var p=q.length;p--;){q[p][0].combinator=r;
}return s;};Element.implement({set:function(r,q){var p=Element.Properties[r];(p&&p.set)?p.set.call(this,q):this.setProperty(r,q);}.overloadSetter(),get:function(q){var p=Element.Properties[q];
return(p&&p.get)?p.get.apply(this):this.getProperty(q);}.overloadGetter(),erase:function(q){var p=Element.Properties[q];(p&&p.erase)?p.erase.apply(this):this.removeProperty(q);
return this;},setProperty:function(q,r){q=o[q]||q;if(r==null){return this.removeProperty(q);}var p=g[q];(p)?this[p]=r:(d[q])?this[q]=!!r:this.setAttribute(q,""+r);
return this;},setProperties:function(p){for(var q in p){this.setProperty(q,p[q]);}return this;},getProperty:function(q){q=o[q]||q;var p=g[q]||m[q];return(p)?this[p]:(d[q])?!!this[q]:(l.test(q)?this.getAttribute(q,2):(p=this.getAttributeNode(q))?p.nodeValue:null)||null;
},getProperties:function(){var p=Array.from(arguments);return p.map(this.getProperty,this).associate(p);},removeProperty:function(q){q=o[q]||q;var p=g[q];
(p)?this[p]="":(d[q])?this[q]=false:this.removeAttribute(q);return this;},removeProperties:function(){Array.each(arguments,this.removeProperty,this);return this;
},hasClass:function(p){return this.className.clean().contains(p," ");},addClass:function(p){if(!this.hasClass(p)){this.className=(this.className+" "+p).clean();
}return this;},removeClass:function(p){this.className=this.className.replace(new RegExp("(^|\\s)"+p+"(?:\\s|$)"),"$1");return this;},toggleClass:function(p,q){if(q==null){q=!this.hasClass(p);
}return(q)?this.addClass(p):this.removeClass(p);},adopt:function(){var s=this,p,u=Array.flatten(arguments),t=u.length;if(t>1){s=p=document.createDocumentFragment();
}for(var r=0;r<t;r++){var q=document.id(u[r],true);if(q){s.appendChild(q);}}if(p){this.appendChild(p);}return this;},appendText:function(q,p){return this.grab(this.getDocument().newTextNode(q),p);
},grab:function(q,p){c[p||"bottom"](document.id(q,true),this);return this;},inject:function(q,p){c[p||"bottom"](this,document.id(q,true));return this;},replaces:function(p){p=document.id(p,true);
p.parentNode.replaceChild(this,p);return this;},wraps:function(q,p){q=document.id(q,true);return this.replaces(q).grab(q,p);},getPrevious:function(p){return document.id(Slick.find(this,b(p,"!~")));
},getAllPrevious:function(p){return Slick.search(this,b(p,"!~"),new Elements);},getNext:function(p){return document.id(Slick.find(this,b(p,"~")));},getAllNext:function(p){return Slick.search(this,b(p,"~"),new Elements);
},getFirst:function(p){return document.id(Slick.search(this,b(p,">"))[0]);},getLast:function(p){return document.id(Slick.search(this,b(p,">")).getLast());
},getParent:function(p){return document.id(Slick.find(this,b(p,"!")));},getParents:function(p){return Slick.search(this,b(p,"!"),new Elements);},getSiblings:function(p){return Slick.search(this,b(p,"~~"),new Elements);
},getChildren:function(p){return Slick.search(this,b(p,">"),new Elements);},getWindow:function(){return this.ownerDocument.window;},getDocument:function(){return this.ownerDocument;
},getElementById:function(p){return document.id(Slick.find(this,"#"+(""+p).replace(/(\W)/g,"\\$1")));},getSelected:function(){this.selectedIndex;return new Elements(Array.from(this.options).filter(function(p){return p.selected;
}));},toQueryString:function(){var p=[];this.getElements("input, select, textarea").each(function(r){var q=r.type;if(!r.name||r.disabled||q=="submit"||q=="reset"||q=="file"||q=="image"){return;
}var s=(r.get("tag")=="select")?r.getSelected().map(function(t){return document.id(t).get("value");}):((q=="radio"||q=="checkbox")&&!r.checked)?null:r.get("value");
Array.from(s).each(function(t){if(typeof t!="undefined"){p.push(encodeURIComponent(r.name)+"="+encodeURIComponent(t));}});});return p.join("&");},destroy:function(){var p=j(this).getElementsByTagName("*");
Array.each(p,j);Element.dispose(this);return null;},empty:function(){Array.from(this.childNodes).each(Element.dispose);return this;},dispose:function(){return(this.parentNode)?this.parentNode.removeChild(this):this;
},match:function(p){return !p||Slick.match(this,p);}});var a=function(t,s,q){if(!q){t.setAttributeNode(document.createAttribute("id"));}if(t.clearAttributes){t.clearAttributes();
t.mergeAttributes(s);t.removeAttribute("uid");if(t.options){var u=t.options,p=s.options;for(var r=u.length;r--;){u[r].selected=p[r].selected;}}}var v=n[s.tagName.toLowerCase()];
if(v&&s[v]){t[v]=s[v];}};Element.implement("clone",function(r,p){r=r!==false;var w=this.cloneNode(r),q;if(r){var s=w.getElementsByTagName("*"),u=this.getElementsByTagName("*");
for(q=s.length;q--;){a(s[q],u[q],p);}}a(w,this,p);if(Browser.ie){var t=w.getElementsByTagName("object"),v=this.getElementsByTagName("object");for(q=t.length;
q--;){t[q].outerHTML=v[q].outerHTML;}}return document.id(w);});var f={contains:function(p){return Slick.contains(this,p);}};if(!document.contains){Document.implement(f);
}if(!document.createElement("div").contains){Element.implement(f);}Element.implement("hasChild",function(p){return this!==p&&this.contains(p);});[Element,Window,Document].invoke("implement",{addListener:function(s,r){if(s=="unload"){var p=r,q=this;
r=function(){q.removeListener("unload",r);p();};}else{k[$uid(this)]=this;}if(this.addEventListener){this.addEventListener(s,r,!!arguments[2]);}else{this.attachEvent("on"+s,r);
}return this;},removeListener:function(q,p){if(this.removeEventListener){this.removeEventListener(q,p,!!arguments[2]);}else{this.detachEvent("on"+q,p);
}return this;},retrieve:function(q,p){var s=e($uid(this)),r=s[q];if(p!=null&&r==null){r=s[q]=p;}return r!=null?r:null;},store:function(q,p){var r=e($uid(this));
r[q]=p;return this;},eliminate:function(p){var q=e($uid(this));delete q[p];return this;}});if(window.attachEvent&&!window.addEventListener){window.addListener("unload",function(){Object.each(k,j);
if(window.CollectGarbage){CollectGarbage();}});}})();Element.Properties={};Element.Properties=new Hash;Element.Properties.style={set:function(a){this.style.cssText=a;
},get:function(){return this.style.cssText;},erase:function(){this.style.cssText="";}};Element.Properties.tag={get:function(){return this.tagName.toLowerCase();
}};(function(a){if(a!=null){Element.Properties.maxlength=Element.Properties.maxLength={get:function(){var b=this.getAttribute("maxLength");return b==a?null:b;
}};}})(document.createElement("input").getAttribute("maxLength"));Element.Properties.html=(function(){var c=Function.attempt(function(){var e=document.createElement("table");
e.innerHTML="<tr><td></td></tr>";});var d=document.createElement("div");var a={table:[1,"<table>","</table>"],select:[1,"<select>","</select>"],tbody:[2,"<table><tbody>","</tbody></table>"],tr:[3,"<table><tbody><tr>","</tr></tbody></table>"]};
a.thead=a.tfoot=a.tbody;var b={set:function(){var f=Array.flatten(arguments).join("");var g=(!c&&a[this.get("tag")]);if(g){var h=d;h.innerHTML=g[1]+f+g[2];
for(var e=g[0];e--;){h=h.firstChild;}this.empty().adopt(h.childNodes);}else{this.innerHTML=f;}}};b.erase=b.set;return b;})();(function(){var c=document.html;
Element.Properties.styles={set:function(f){this.setStyles(f);}};var e=(c.style.opacity!=null);var d=/alpha\(opacity=([\d.]+)\)/i;var b=function(g,f){if(!g.currentStyle||!g.currentStyle.hasLayout){g.style.zoom=1;
}if(e){g.style.opacity=f;}else{f=(f==1)?"":"alpha(opacity="+f*100+")";var h=g.style.filter||g.getComputedStyle("filter")||"";g.style.filter=d.test(h)?h.replace(d,f):h+f;
}};Element.Properties.opacity={set:function(g){var f=this.style.visibility;if(g==0&&f!="hidden"){this.style.visibility="hidden";}else{if(g!=0&&f!="visible"){this.style.visibility="visible";
}}b(this,g);},get:(e)?function(){var f=this.style.opacity||this.getComputedStyle("opacity");return(f=="")?1:f;}:function(){var f,g=(this.style.filter||this.getComputedStyle("filter"));
if(g){f=g.match(d);}return(f==null||g==null)?1:(f[1]/100);}};var a=(c.style.cssFloat==null)?"styleFloat":"cssFloat";Element.implement({getComputedStyle:function(h){if(this.currentStyle){return this.currentStyle[h.camelCase()];
}var g=Element.getDocument(this).defaultView,f=g?g.getComputedStyle(this,null):null;return(f)?f.getPropertyValue((h==a)?"float":h.hyphenate()):null;},setOpacity:function(f){b(this,f);
return this;},getOpacity:function(){return this.get("opacity");},setStyle:function(g,f){switch(g){case"opacity":return this.set("opacity",parseFloat(f));
case"float":g=a;}g=g.camelCase();if(typeOf(f)!="string"){var h=(Element.Styles[g]||"@").split(" ");f=Array.from(f).map(function(k,j){if(!h[j]){return"";
}return(typeOf(k)=="number")?h[j].replace("@",Math.round(k)):k;}).join(" ");}else{if(f==String(Number(f))){f=Math.round(f);}}this.style[g]=f;return this;
},getStyle:function(l){switch(l){case"opacity":return this.get("opacity");case"float":l=a;}l=l.camelCase();var f=this.style[l];if(!f||l=="zIndex"){f=[];
for(var k in Element.ShortStyles){if(l!=k){continue;}for(var j in Element.ShortStyles[k]){f.push(this.getStyle(j));}return f.join(" ");}f=this.getComputedStyle(l);
}if(f){f=String(f);var h=f.match(/rgba?\([\d\s,]+\)/);if(h){f=f.replace(h[0],h[0].rgbToHex());}}if(Browser.opera||(Browser.ie&&isNaN(parseFloat(f)))){if((/^(height|width)$/).test(l)){var g=(l=="width")?["left","right"]:["top","bottom"],i=0;
g.each(function(m){i+=this.getStyle("border-"+m+"-width").toInt()+this.getStyle("padding-"+m).toInt();},this);return this["offset"+l.capitalize()]-i+"px";
}if(Browser.opera&&String(f).indexOf("px")!=-1){return f;}if((/^border(.+)Width|margin|padding/).test(l)){return"0px";}}return f;},setStyles:function(g){for(var f in g){this.setStyle(f,g[f]);
}return this;},getStyles:function(){var f={};Array.flatten(arguments).each(function(g){f[g]=this.getStyle(g);},this);return f;}});Element.Styles={left:"@px",top:"@px",bottom:"@px",right:"@px",width:"@px",height:"@px",maxWidth:"@px",maxHeight:"@px",minWidth:"@px",minHeight:"@px",backgroundColor:"rgb(@, @, @)",backgroundPosition:"@px @px",color:"rgb(@, @, @)",fontSize:"@px",letterSpacing:"@px",lineHeight:"@px",clip:"rect(@px @px @px @px)",margin:"@px @px @px @px",padding:"@px @px @px @px",border:"@px @ rgb(@, @, @) @px @ rgb(@, @, @) @px @ rgb(@, @, @)",borderWidth:"@px @px @px @px",borderStyle:"@ @ @ @",borderColor:"rgb(@, @, @) rgb(@, @, @) rgb(@, @, @) rgb(@, @, @)",zIndex:"@",zoom:"@",fontWeight:"@",textIndent:"@px",opacity:"@"};
Element.Styles=new Hash(Element.Styles);Element.ShortStyles={margin:{},padding:{},border:{},borderWidth:{},borderStyle:{},borderColor:{}};["Top","Right","Bottom","Left"].each(function(l){var k=Element.ShortStyles;
var g=Element.Styles;["margin","padding"].each(function(m){var n=m+l;k[m][n]=g[n]="@px";});var j="border"+l;k.border[j]=g[j]="@px @ rgb(@, @, @)";var i=j+"Width",f=j+"Style",h=j+"Color";
k[j]={};k.borderWidth[i]=k[j][i]=g[i]="@px";k.borderStyle[f]=k[j][f]=g[f]="@";k.borderColor[h]=k[j][h]=g[h]="rgb(@, @, @)";});}).call(this);(function(){Element.Properties.events={set:function(b){this.addEvents(b);
}};[Element,Window,Document].invoke("implement",{addEvent:function(f,h){var i=this.retrieve("events",{});if(!i[f]){i[f]={keys:[],values:[]};}if(i[f].keys.contains(h)){return this;
}i[f].keys.push(h);var g=f,b=Element.Events[f],d=h,j=this;if(b){if(b.onAdd){b.onAdd.call(this,h);}if(b.condition){d=function(k){if(b.condition.call(this,k)){return h.call(this,k);
}return true;};}g=b.base||g;}var e=function(){return h.call(j);};var c=Element.NativeEvents[g];if(c){if(c==2){e=function(k){k=new Event(k,j.getWindow());
if(d.call(j,k)===false){k.stop();}};}this.addListener(g,e,arguments[2]);}i[f].values.push(e);return this;},removeEvent:function(e,d){var c=this.retrieve("events");
if(!c||!c[e]){return this;}var h=c[e];var b=h.keys.indexOf(d);if(b==-1){return this;}var g=h.values[b];delete h.keys[b];delete h.values[b];var f=Element.Events[e];
if(f){if(f.onRemove){f.onRemove.call(this,d);}e=f.base||e;}return(Element.NativeEvents[e])?this.removeListener(e,g,arguments[2]):this;},addEvents:function(b){for(var c in b){this.addEvent(c,b[c]);
}return this;},removeEvents:function(b){var d;if(typeOf(b)=="object"){for(d in b){this.removeEvent(d,b[d]);}return this;}var c=this.retrieve("events");
if(!c){return this;}if(!b){for(d in c){this.removeEvents(d);}this.eliminate("events");}else{if(c[b]){c[b].keys.each(function(e){this.removeEvent(b,e);},this);
delete c[b];}}return this;},fireEvent:function(e,c,b){var d=this.retrieve("events");if(!d||!d[e]){return this;}c=Array.from(c);d[e].keys.each(function(f){if(b){f.delay(b,this,c);
}else{f.apply(this,c);}},this);return this;},cloneEvents:function(e,d){e=document.id(e);var c=e.retrieve("events");if(!c){return this;}if(!d){for(var b in c){this.cloneEvents(e,b);
}}else{if(c[d]){c[d].keys.each(function(f){this.addEvent(d,f);},this);}}return this;}});Element.NativeEvents={click:2,dblclick:2,mouseup:2,mousedown:2,contextmenu:2,mousewheel:2,DOMMouseScroll:2,mouseover:2,mouseout:2,mousemove:2,selectstart:2,selectend:2,keydown:2,keypress:2,keyup:2,orientationchange:2,touchstart:2,touchmove:2,touchend:2,touchcancel:2,gesturestart:2,gesturechange:2,gestureend:2,focus:2,blur:2,change:2,reset:2,select:2,submit:2,load:2,unload:1,beforeunload:2,resize:1,move:1,DOMContentLoaded:1,readystatechange:1,error:1,abort:1,scroll:1};
var a=function(b){var c=b.relatedTarget;if(c==null){return true;}if(!c){return false;}return(c!=this&&c.prefix!="xul"&&typeOf(this)!="document"&&!this.contains(c));
};Element.Events={mouseenter:{base:"mouseover",condition:a},mouseleave:{base:"mouseout",condition:a},mousewheel:{base:(Browser.firefox)?"DOMMouseScroll":"mousewheel"}};
Element.Events=new Hash(Element.Events);}).call(this);(function(){var h=document.createElement("div"),e=document.createElement("div");h.style.height="0";
h.appendChild(e);var d=(e.offsetParent===h);h=e=null;var l=function(m){return k(m,"position")!="static"||a(m);};var i=function(m){return l(m)||(/^(?:table|td|th)$/i).test(m.tagName);
};Element.implement({scrollTo:function(m,n){if(a(this)){this.getWindow().scrollTo(m,n);}else{this.scrollLeft=m;this.scrollTop=n;}return this;},getSize:function(){if(a(this)){return this.getWindow().getSize();
}return{x:this.offsetWidth,y:this.offsetHeight};},getScrollSize:function(){if(a(this)){return this.getWindow().getScrollSize();}return{x:this.scrollWidth,y:this.scrollHeight};
},getScroll:function(){if(a(this)){return this.getWindow().getScroll();}return{x:this.scrollLeft,y:this.scrollTop};},getScrolls:function(){var n=this.parentNode,m={x:0,y:0};
while(n&&!a(n)){m.x+=n.scrollLeft;m.y+=n.scrollTop;n=n.parentNode;}return m;},getOffsetParent:d?function(){var m=this;if(a(m)||k(m,"position")=="fixed"){return null;
}var n=(k(m,"position")=="static")?i:l;while((m=m.parentNode)){if(n(m)){return m;}}return null;}:function(){var m=this;if(a(m)||k(m,"position")=="fixed"){return null;
}try{return m.offsetParent;}catch(n){}return null;},getOffsets:function(){if(this.getBoundingClientRect&&!Browser.Platform.ios){var r=this.getBoundingClientRect(),o=document.id(this.getDocument().documentElement),q=o.getScroll(),t=this.getScrolls(),s=(k(this,"position")=="fixed");
return{x:r.left.toInt()+t.x+((s)?0:q.x)-o.clientLeft,y:r.top.toInt()+t.y+((s)?0:q.y)-o.clientTop};}var n=this,m={x:0,y:0};if(a(this)){return m;}while(n&&!a(n)){m.x+=n.offsetLeft;
m.y+=n.offsetTop;if(Browser.firefox){if(!c(n)){m.x+=b(n);m.y+=g(n);}var p=n.parentNode;if(p&&k(p,"overflow")!="visible"){m.x+=b(p);m.y+=g(p);}}else{if(n!=this&&Browser.safari){m.x+=b(n);
m.y+=g(n);}}n=n.offsetParent;}if(Browser.firefox&&!c(this)){m.x-=b(this);m.y-=g(this);}return m;},getPosition:function(p){if(a(this)){return{x:0,y:0};}var q=this.getOffsets(),n=this.getScrolls();
var m={x:q.x-n.x,y:q.y-n.y};if(p&&(p=document.id(p))){var o=p.getPosition();return{x:m.x-o.x-b(p),y:m.y-o.y-g(p)};}return m;},getCoordinates:function(o){if(a(this)){return this.getWindow().getCoordinates();
}var m=this.getPosition(o),n=this.getSize();var p={left:m.x,top:m.y,width:n.x,height:n.y};p.right=p.left+p.width;p.bottom=p.top+p.height;return p;},computePosition:function(m){return{left:m.x-j(this,"margin-left"),top:m.y-j(this,"margin-top")};
},setPosition:function(m){return this.setStyles(this.computePosition(m));}});[Document,Window].invoke("implement",{getSize:function(){var m=f(this);return{x:m.clientWidth,y:m.clientHeight};
},getScroll:function(){var n=this.getWindow(),m=f(this);return{x:n.pageXOffset||m.scrollLeft,y:n.pageYOffset||m.scrollTop};},getScrollSize:function(){var o=f(this),n=this.getSize(),m=this.getDocument().body;
return{x:Math.max(o.scrollWidth,m.scrollWidth,n.x),y:Math.max(o.scrollHeight,m.scrollHeight,n.y)};},getPosition:function(){return{x:0,y:0};},getCoordinates:function(){var m=this.getSize();
return{top:0,left:0,bottom:m.y,right:m.x,height:m.y,width:m.x};}});var k=Element.getComputedStyle;function j(m,n){return k(m,n).toInt()||0;}function c(m){return k(m,"-moz-box-sizing")=="border-box";
}function g(m){return j(m,"border-top-width");}function b(m){return j(m,"border-left-width");}function a(m){return(/^(?:body|html)$/i).test(m.tagName);
}function f(m){var n=m.getDocument();return(!n.compatMode||n.compatMode=="CSS1Compat")?n.html:n.body;}}).call(this);Element.alias({position:"setPosition"});
[Window,Document,Element].invoke("implement",{getHeight:function(){return this.getSize().y;},getWidth:function(){return this.getSize().x;},getScrollTop:function(){return this.getScroll().y;
},getScrollLeft:function(){return this.getScroll().x;},getScrollHeight:function(){return this.getScrollSize().y;},getScrollWidth:function(){return this.getScrollSize().x;
},getTop:function(){return this.getPosition().y;},getLeft:function(){return this.getPosition().x;}});(function(){var f=this.Fx=new Class({Implements:[Chain,Events,Options],options:{fps:60,unit:false,duration:500,frames:null,frameSkip:true,link:"ignore"},initialize:function(g){this.subject=this.subject||this;
this.setOptions(g);},getTransition:function(){return function(g){return -(Math.cos(Math.PI*g)-1)/2;};},step:function(g){if(this.options.frameSkip){var h=(this.time!=null)?(g-this.time):0,i=h/this.frameInterval;
this.time=g;this.frame+=i;}else{this.frame++;}if(this.frame<this.frames){var j=this.transition(this.frame/this.frames);this.set(this.compute(this.from,this.to,j));
}else{this.frame=this.frames;this.set(this.compute(this.from,this.to,1));this.stop();}},set:function(g){return g;},compute:function(i,h,g){return f.compute(i,h,g);
},check:function(){if(!this.isRunning()){return true;}switch(this.options.link){case"cancel":this.cancel();return true;case"chain":this.chain(this.caller.pass(arguments,this));
return false;}return false;},start:function(k,j){if(!this.check(k,j)){return this;}this.from=k;this.to=j;this.frame=(this.options.frameSkip)?0:-1;this.time=null;
this.transition=this.getTransition();var i=this.options.frames,h=this.options.fps,g=this.options.duration;this.duration=f.Durations[g]||g.toInt();this.frameInterval=1000/h;
this.frames=i||Math.round(this.duration/this.frameInterval);this.fireEvent("start",this.subject);b.call(this,h);return this;},stop:function(){if(this.isRunning()){this.time=null;
d.call(this,this.options.fps);if(this.frames==this.frame){this.fireEvent("complete",this.subject);if(!this.callChain()){this.fireEvent("chainComplete",this.subject);
}}else{this.fireEvent("stop",this.subject);}}return this;},cancel:function(){if(this.isRunning()){this.time=null;d.call(this,this.options.fps);this.frame=this.frames;
this.fireEvent("cancel",this.subject).clearChain();}return this;},pause:function(){if(this.isRunning()){this.time=null;d.call(this,this.options.fps);}return this;
},resume:function(){if((this.frame<this.frames)&&!this.isRunning()){b.call(this,this.options.fps);}return this;},isRunning:function(){var g=e[this.options.fps];
return g&&g.contains(this);}});f.compute=function(i,h,g){return(h-i)*g+i;};f.Durations={"short":250,normal:500,"long":1000};var e={},c={};var a=function(){var h=Date.now();
for(var j=this.length;j--;){var g=this[j];if(g){g.step(h);}}};var b=function(h){var g=e[h]||(e[h]=[]);g.push(this);if(!c[h]){c[h]=a.periodical(Math.round(1000/h),g);
}};var d=function(h){var g=e[h];if(g){g.erase(this);if(!g.length&&c[h]){delete e[h];c[h]=clearInterval(c[h]);}}};}).call(this);Fx.CSS=new Class({Extends:Fx,prepare:function(c,d,b){b=Array.from(b);
if(b[1]==null){b[1]=b[0];b[0]=c.getStyle(d);}var a=b.map(this.parse);return{from:a[0],to:a[1]};},parse:function(a){a=Function.from(a)();a=(typeof a=="string")?a.split(" "):Array.from(a);
return a.map(function(c){c=String(c);var b=false;Object.each(Fx.CSS.Parsers,function(f,e){if(b){return;}var d=f.parse(c);if(d||d===0){b={value:d,parser:f};
}});b=b||{value:c,parser:Fx.CSS.Parsers.String};return b;});},compute:function(d,c,b){var a=[];(Math.min(d.length,c.length)).times(function(e){a.push({value:d[e].parser.compute(d[e].value,c[e].value,b),parser:d[e].parser});
});a.$family=Function.from("fx:css:value");return a;},serve:function(c,b){if(typeOf(c)!="fx:css:value"){c=this.parse(c);}var a=[];c.each(function(d){a=a.concat(d.parser.serve(d.value,b));
});return a;},render:function(a,d,c,b){a.setStyle(d,this.serve(c,b));},search:function(a){if(Fx.CSS.Cache[a]){return Fx.CSS.Cache[a];}var c={},b=new RegExp("^"+a.escapeRegExp()+"$");
Array.each(document.styleSheets,function(f,e){var d=f.href;if(d&&d.contains("://")&&!d.contains(document.domain)){return;}var g=f.rules||f.cssRules;Array.each(g,function(k,h){if(!k.style){return;
}var j=(k.selectorText)?k.selectorText.replace(/^\w+/,function(i){return i.toLowerCase();}):null;if(!j||!b.test(j)){return;}Object.each(Element.Styles,function(l,i){if(!k.style[i]||Element.ShortStyles[i]){return;
}l=String(k.style[i]);c[i]=((/^rgb/).test(l))?l.rgbToHex():l;});});});return Fx.CSS.Cache[a]=c;}});Fx.CSS.Cache={};Fx.CSS.Parsers={Color:{parse:function(a){if(a.match(/^#[0-9a-f]{3,6}$/i)){return a.hexToRgb(true);
}return((a=a.match(/(\d+),\s*(\d+),\s*(\d+)/)))?[a[1],a[2],a[3]]:false;},compute:function(c,b,a){return c.map(function(e,d){return Math.round(Fx.compute(c[d],b[d],a));
});},serve:function(a){return a.map(Number);}},Number:{parse:parseFloat,compute:Fx.compute,serve:function(b,a){return(a)?b+a:b;}},String:{parse:Function.from(false),compute:function(b,a){return a;
},serve:function(a){return a;}}};Fx.CSS.Parsers=new Hash(Fx.CSS.Parsers);Fx.Tween=new Class({Extends:Fx.CSS,initialize:function(b,a){this.element=this.subject=document.id(b);
this.parent(a);},set:function(b,a){if(arguments.length==1){a=b;b=this.property||this.options.property;}this.render(this.element,b,a,this.options.unit);
return this;},start:function(c,e,d){if(!this.check(c,e,d)){return this;}var b=Array.flatten(arguments);this.property=this.options.property||b.shift();var a=this.prepare(this.element,this.property,b);
return this.parent(a.from,a.to);}});Element.Properties.tween={set:function(a){this.get("tween").cancel().setOptions(a);return this;},get:function(){var a=this.retrieve("tween");
if(!a){a=new Fx.Tween(this,{link:"cancel"});this.store("tween",a);}return a;}};Element.implement({tween:function(a,c,b){this.get("tween").start(arguments);
return this;},fade:function(c){var e=this.get("tween"),d="opacity",a;c=[c,"toggle"].pick();switch(c){case"in":e.start(d,1);break;case"out":e.start(d,0);
break;case"show":e.set(d,1);break;case"hide":e.set(d,0);break;case"toggle":var b=this.retrieve("fade:flag",this.get("opacity")==1);e.start(d,(b)?0:1);this.store("fade:flag",!b);
a=true;break;default:e.start(d,arguments);}if(!a){this.eliminate("fade:flag");}return this;},highlight:function(c,a){if(!a){a=this.retrieve("highlight:original",this.getStyle("background-color"));
a=(a=="transparent")?"#fff":a;}var b=this.get("tween");b.start("background-color",c||"#ffff88",a).chain(function(){this.setStyle("background-color",this.retrieve("highlight:original"));
b.callChain();}.bind(this));return this;}});Fx.Morph=new Class({Extends:Fx.CSS,initialize:function(b,a){this.element=this.subject=document.id(b);this.parent(a);
},set:function(a){if(typeof a=="string"){a=this.search(a);}for(var b in a){this.render(this.element,b,a[b],this.options.unit);}return this;},compute:function(e,d,c){var a={};
for(var b in e){a[b]=this.parent(e[b],d[b],c);}return a;},start:function(b){if(!this.check(b)){return this;}if(typeof b=="string"){b=this.search(b);}var e={},d={};
for(var c in b){var a=this.prepare(this.element,c,b[c]);e[c]=a.from;d[c]=a.to;}return this.parent(e,d);}});Element.Properties.morph={set:function(a){this.get("morph").cancel().setOptions(a);
return this;},get:function(){var a=this.retrieve("morph");if(!a){a=new Fx.Morph(this,{link:"cancel"});this.store("morph",a);}return a;}};Element.implement({morph:function(a){this.get("morph").start(a);
return this;}});Fx.implement({getTransition:function(){var a=this.options.transition||Fx.Transitions.Sine.easeInOut;if(typeof a=="string"){var b=a.split(":");
a=Fx.Transitions;a=a[b[0]]||a[b[0].capitalize()];if(b[1]){a=a["ease"+b[1].capitalize()+(b[2]?b[2].capitalize():"")];}}return a;}});Fx.Transition=function(c,b){b=Array.from(b);
var a=function(d){return c(d,b);};return Object.append(a,{easeIn:a,easeOut:function(d){return 1-c(1-d,b);},easeInOut:function(d){return(d<=0.5?c(2*d,b):(2-c(2*(1-d),b)))/2;
}});};Fx.Transitions={linear:function(a){return a;}};Fx.Transitions=new Hash(Fx.Transitions);Fx.Transitions.extend=function(a){for(var b in a){Fx.Transitions[b]=new Fx.Transition(a[b]);
}};Fx.Transitions.extend({Pow:function(b,a){return Math.pow(b,a&&a[0]||6);},Expo:function(a){return Math.pow(2,8*(a-1));},Circ:function(a){return 1-Math.sin(Math.acos(a));
},Sine:function(a){return 1-Math.cos(a*Math.PI/2);},Back:function(b,a){a=a&&a[0]||1.618;return Math.pow(b,2)*((a+1)*b-a);},Bounce:function(f){var e;for(var d=0,c=1;
1;d+=c,c/=2){if(f>=(7-4*d)/11){e=c*c-Math.pow((11-6*d-11*f)/4,2);break;}}return e;},Elastic:function(b,a){return Math.pow(2,10*--b)*Math.cos(20*b*Math.PI*(a&&a[0]||1)/3);
}});["Quad","Cubic","Quart","Quint"].each(function(b,a){Fx.Transitions[b]=new Fx.Transition(function(c){return Math.pow(c,a+2);});});(function(){var d=function(){},a=("onprogress" in new Browser.Request);
var c=this.Request=new Class({Implements:[Chain,Events,Options],options:{url:"",data:"",headers:{"X-Requested-With":"XMLHttpRequest",Accept:"text/javascript, text/html, application/xml, text/xml, */*"},async:true,format:false,method:"post",link:"ignore",isSuccess:null,emulation:true,urlEncoded:true,encoding:"utf-8",evalScripts:false,evalResponse:false,timeout:0,noCache:false},initialize:function(e){this.xhr=new Browser.Request();
this.setOptions(e);this.headers=this.options.headers;},onStateChange:function(){var e=this.xhr;if(e.readyState!=4||!this.running){return;}this.running=false;
this.status=0;Function.attempt(function(){var f=e.status;this.status=(f==1223)?204:f;}.bind(this));e.onreadystatechange=d;if(a){e.onprogress=e.onloadstart=d;
}clearTimeout(this.timer);this.response={text:this.xhr.responseText||"",xml:this.xhr.responseXML};if(this.options.isSuccess.call(this,this.status)){this.success(this.response.text,this.response.xml);
}else{this.failure();}},isSuccess:function(){var e=this.status;return(e>=200&&e<300);},isRunning:function(){return !!this.running;},processScripts:function(e){if(this.options.evalResponse||(/(ecma|java)script/).test(this.getHeader("Content-type"))){return Browser.exec(e);
}return e.stripScripts(this.options.evalScripts);},success:function(f,e){this.onSuccess(this.processScripts(f),e);},onSuccess:function(){this.fireEvent("complete",arguments).fireEvent("success",arguments).callChain();
},failure:function(){this.onFailure();},onFailure:function(){this.fireEvent("complete").fireEvent("failure",this.xhr);},loadstart:function(e){this.fireEvent("loadstart",[e,this.xhr]);
},progress:function(e){this.fireEvent("progress",[e,this.xhr]);},timeout:function(){this.fireEvent("timeout",this.xhr);},setHeader:function(e,f){this.headers[e]=f;
return this;},getHeader:function(e){return Function.attempt(function(){return this.xhr.getResponseHeader(e);}.bind(this));},check:function(){if(!this.running){return true;
}switch(this.options.link){case"cancel":this.cancel();return true;case"chain":this.chain(this.caller.pass(arguments,this));return false;}return false;},send:function(o){if(!this.check(o)){return this;
}this.options.isSuccess=this.options.isSuccess||this.isSuccess;this.running=true;var l=typeOf(o);if(l=="string"||l=="element"){o={data:o};}var h=this.options;
o=Object.append({data:h.data,url:h.url,method:h.method},o);var j=o.data,f=String(o.url),e=o.method.toLowerCase();switch(typeOf(j)){case"element":j=document.id(j).toQueryString();
break;case"object":case"hash":j=Object.toQueryString(j);}if(this.options.format){var m="format="+this.options.format;j=(j)?m+"&"+j:m;}if(this.options.emulation&&!["get","post"].contains(e)){var k="_method="+e;
j=(j)?k+"&"+j:k;e="post";}if(this.options.urlEncoded&&["post","put"].contains(e)){var g=(this.options.encoding)?"; charset="+this.options.encoding:"";this.headers["Content-type"]="application/x-www-form-urlencoded"+g;
}if(!f){f=document.location.pathname;}var i=f.lastIndexOf("/");if(i>-1&&(i=f.indexOf("#"))>-1){f=f.substr(0,i);}if(this.options.noCache){f+=(f.contains("?")?"&":"?")+String.uniqueID();
}if(j&&e=="get"){f+=(f.contains("?")?"&":"?")+j;j=null;}var n=this.xhr;if(a){n.onloadstart=this.loadstart.bind(this);n.onprogress=this.progress.bind(this);
}n.open(e.toUpperCase(),f,this.options.async,this.options.user,this.options.password);if(this.options.user&&"withCredentials" in n){n.withCredentials=true;
}n.onreadystatechange=this.onStateChange.bind(this);Object.each(this.headers,function(q,p){try{n.setRequestHeader(p,q);}catch(r){this.fireEvent("exception",[p,q]);
}},this);this.fireEvent("request");n.send(j);if(!this.options.async){this.onStateChange();}if(this.options.timeout){this.timer=this.timeout.delay(this.options.timeout,this);
}return this;},cancel:function(){if(!this.running){return this;}this.running=false;var e=this.xhr;e.abort();clearTimeout(this.timer);e.onreadystatechange=d;
if(a){e.onprogress=e.onloadstart=d;}this.xhr=new Browser.Request();this.fireEvent("cancel");return this;}});var b={};["get","post","put","delete","GET","POST","PUT","DELETE"].each(function(e){b[e]=function(g){var f={method:e};
if(g!=null){f.data=g;}return this.send(f);};});c.implement(b);Element.Properties.send={set:function(e){var f=this.get("send").cancel();f.setOptions(e);
return this;},get:function(){var e=this.retrieve("send");if(!e){e=new c({data:this,link:"cancel",method:this.get("method")||"post",url:this.get("action")});
this.store("send",e);}return e;}};Element.implement({send:function(e){var f=this.get("send");f.send({data:this,url:e||f.options.url});return this;}});})();
Request.HTML=new Class({Extends:Request,options:{update:false,append:false,evalScripts:true,filter:false,headers:{Accept:"text/html, application/xml, text/xml, */*"}},success:function(e){var d=this.options,b=this.response;
b.html=e.stripScripts(function(f){b.javascript=f;});var c=b.html.match(/<body[^>]*>([\s\S]*?)<\/body>/i);if(c){b.html=c[1];}var a=new Element("div").set("html",b.html);
b.tree=a.childNodes;b.elements=a.getElements("*");if(d.filter){b.tree=b.elements.filter(d.filter);}if(d.update){document.id(d.update).empty().set("html",b.html);
}else{if(d.append){document.id(d.append).adopt(a.getChildren());}}if(d.evalScripts){Browser.exec(b.javascript);}this.onSuccess(b.tree,b.elements,b.html,b.javascript);
}});Element.Properties.load={set:function(a){var b=this.get("load").cancel();b.setOptions(a);return this;},get:function(){var a=this.retrieve("load");if(!a){a=new Request.HTML({data:this,link:"cancel",update:this,method:"get"});
this.store("load",a);}return a;}};Element.implement({load:function(){this.get("load").send(Array.link(arguments,{data:Type.isObject,url:Type.isString}));
return this;}});if(typeof JSON=="undefined"){this.JSON={};}JSON=new Hash({stringify:JSON.stringify,parse:JSON.parse});(function(){var special={"\b":"\\b","\t":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"};
var escape=function(chr){return special[chr]||"\\u"+("0000"+chr.charCodeAt(0).toString(16)).slice(-4);};JSON.validate=function(string){string=string.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,"@").replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,"]").replace(/(?:^|:|,)(?:\s*\[)+/g,"");
return(/^[\],:{}\s]*$/).test(string);};JSON.encode=JSON.stringify?function(obj){return JSON.stringify(obj);}:function(obj){if(obj&&obj.toJSON){obj=obj.toJSON();
}switch(typeOf(obj)){case"string":return'"'+obj.replace(/[\x00-\x1f\\"]/g,escape)+'"';case"array":return"["+obj.map(JSON.encode).clean()+"]";case"object":case"hash":var string=[];
Object.each(obj,function(value,key){var json=JSON.encode(value);if(json){string.push(JSON.encode(key)+":"+json);}});return"{"+string+"}";case"number":case"boolean":return""+obj;
case"null":return"null";}return null;};JSON.decode=function(string,secure){if(!string||typeOf(string)!="string"){return null;}if(secure||JSON.secure){if(JSON.parse){return JSON.parse(string);
}if(!JSON.validate(string)){throw new Error("JSON could not decode the input; security is enabled and the value is not secure.");}}return eval("("+string+")");
};}).call(this);Request.JSON=new Class({Extends:Request,options:{secure:true},initialize:function(a){this.parent(a);Object.append(this.headers,{Accept:"application/json","X-Request":"JSON"});
},success:function(c){var b;try{b=this.response.json=JSON.decode(c,this.options.secure);}catch(a){this.fireEvent("error",[c,a]);return;}if(b==null){this.onFailure();
}else{this.onSuccess(b,c);}}});var Cookie=new Class({Implements:Options,options:{path:"/",domain:false,duration:false,secure:false,document:document,encode:true},initialize:function(b,a){this.key=b;
this.setOptions(a);},write:function(b){if(this.options.encode){b=encodeURIComponent(b);}if(this.options.domain){b+="; domain="+this.options.domain;}if(this.options.path){b+="; path="+this.options.path;
}if(this.options.duration){var a=new Date();a.setTime(a.getTime()+this.options.duration*24*60*60*1000);b+="; expires="+a.toGMTString();}if(this.options.secure){b+="; secure";
}this.options.document.cookie=this.key+"="+b;return this;},read:function(){var a=this.options.document.cookie.match("(?:^|;)\\s*"+this.key.escapeRegExp()+"=([^;]*)");
return(a)?decodeURIComponent(a[1]):null;},dispose:function(){new Cookie(this.key,Object.merge({},this.options,{duration:-1})).write("");return this;}});
Cookie.write=function(b,c,a){return new Cookie(b,a).write(c);};Cookie.read=function(a){return new Cookie(a).read();};Cookie.dispose=function(b,a){return new Cookie(b,a).dispose();
};(function(j,l){var m,g,f=[],c,b,n=true;try{n=j.frameElement!=null;}catch(i){}var h=function(){clearTimeout(b);if(m){return;}Browser.loaded=m=true;l.removeListener("DOMContentLoaded",h).removeListener("readystatechange",a);
l.fireEvent("domready");j.fireEvent("domready");};var a=function(){for(var e=f.length;e--;){if(f[e]()){h();return true;}}return false;};var k=function(){clearTimeout(b);
if(!a()){b=setTimeout(k,10);}};l.addListener("DOMContentLoaded",h);var d=l.createElement("div");if(d.doScroll&&!n){f.push(function(){try{d.doScroll();return true;
}catch(o){}return false;});c=true;}if(l.readyState){f.push(function(){var e=l.readyState;return(e=="loaded"||e=="complete");});}if("onreadystatechange" in l){l.addListener("readystatechange",a);
}else{c=true;}if(c){k();}Element.Events.domready={onAdd:function(e){if(m){e.call(this);}}};Element.Events.load={base:"load",onAdd:function(e){if(g&&this==j){e.call(this);
}},condition:function(){if(this==j){h();delete Element.Events.load;}return true;}};j.addEvent("load",function(){g=true;});})(window,document);(function(){var Swiff=this.Swiff=new Class({Implements:Options,options:{id:null,height:1,width:1,container:null,properties:{},params:{quality:"high",allowScriptAccess:"always",wMode:"window",swLiveConnect:true},callBacks:{},vars:{}},toElement:function(){return this.object;
},initialize:function(path,options){this.instance="Swiff_"+String.uniqueID();this.setOptions(options);options=this.options;var id=this.id=options.id||this.instance;
var container=document.id(options.container);Swiff.CallBacks[this.instance]={};var params=options.params,vars=options.vars,callBacks=options.callBacks;
var properties=Object.append({height:options.height,width:options.width},options.properties);var self=this;for(var callBack in callBacks){Swiff.CallBacks[this.instance][callBack]=(function(option){return function(){return option.apply(self.object,arguments);
};})(callBacks[callBack]);vars[callBack]="Swiff.CallBacks."+this.instance+"."+callBack;}params.flashVars=Object.toQueryString(vars);if(Browser.ie){properties.classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000";
params.movie=path;}else{properties.type="application/x-shockwave-flash";}properties.data=path;var build='<object id="'+id+'"';for(var property in properties){build+=" "+property+'="'+properties[property]+'"';
}build+=">";for(var param in params){if(params[param]){build+='<param name="'+param+'" value="'+params[param]+'" />';}}build+="</object>";this.object=((container)?container.empty():new Element("div")).set("html",build).firstChild;
},replaces:function(element){element=document.id(element,true);element.parentNode.replaceChild(this.toElement(),element);return this;},inject:function(element){document.id(element,true).appendChild(this.toElement());
return this;},remote:function(){return Swiff.remote.apply(Swiff,[this.toElement()].append(arguments));}});Swiff.CallBacks={};Swiff.remote=function(obj,fn){var rs=obj.CallFunction('<invoke name="'+fn+'" returntype="javascript">'+__flash__argumentsToXML(arguments,2)+"</invoke>");
return eval(rs);};}).call(this);

//MooTools More, <http://mootools.net/more>. Copyright (c) 2006-2009 Aaron Newton <http://clientcide.com/>, Valerio Proietti <http://mad4milk.net> & the MooTools team <http://mootools.net/developers>, MIT Style License.

/*
---

script: More.js

name: More

description: MooTools More

license: MIT-style license

requires:
  - Core/MooTools

provides: [MooTools.More]

...
*/

MooTools.More = {
	'version': '1.2.5.1',
	'build': '254884f2b83651bf95260eed5c6cceb838e22d8e'
};


/*
---

script: Log.js

name: Log

description: Provides basic logging functionality for plugins to implement.

license: MIT-style license

authors:
  - Guillermo Rauch
  - Thomas Aylott
  - Scott Kyle

requires:
  - Core/Class
  - /MooTools.More

provides: [Log]

...
*/

(function(){

var global = this;

var log = function(){
	if (global.console && console.log){
		try {
			console.log.apply(console, arguments);
		} catch(e) {
			console.log(Array.slice(arguments));
		}
	} else {
		Log.logged.push(arguments);
	}
	return this;
};

var disabled = function(){
	this.logged.push(arguments);
	return this;
};

this.Log = new Class({
	
	logged: [],
	
	log: disabled,
	
	resetLog: function(){
		this.logged.empty();
		return this;
	},

	enableLog: function(){
		this.log = log;
		this.logged.each(function(args){
			this.log.apply(this, args);
		}, this);
		return this.resetLog();
	},

	disableLog: function(){
		this.log = disabled;
		return this;
	}
	
});

Log.extend(new Log).enableLog();

// legacy
Log.logger = function(){
	return this.log.apply(this, arguments);
};

})();


/*
---

script: Class.Binds.js

name: Class.Binds

description: Automagically binds specified methods in a class to the instance of the class.

license: MIT-style license

authors:
  - Aaron Newton

requires:
  - Core/Class
  - /MooTools.More

provides: [Class.Binds]

...
*/

Class.Mutators.Binds = function(binds){
    return binds;
};

Class.Mutators.initialize = function(initialize){
	return function(){
		$splat(this.Binds).each(function(name){
			var original = this[name];
			if (original) this[name] = original.bind(this);
		}, this);
		return initialize.apply(this, arguments);
	};
};


/*
---

script: Class.Occlude.js

name: Class.Occlude

description: Prevents a class from being applied to a DOM element twice.

license: MIT-style license.

authors:
  - Aaron Newton

requires: 
  - Core/Class
  - Core/Element
  - /MooTools.More

provides: [Class.Occlude]

...
*/

Class.Occlude = new Class({

	occlude: function(property, element){
		element = document.id(element || this.element);
		var instance = element.retrieve(property || this.property);
		if (instance && !$defined(this.occluded))
			return this.occluded = instance;

		this.occluded = false;
		element.store(property || this.property, this);
		return this.occluded;
	}

});


/*
---

script: Element.Forms.js

name: Element.Forms

description: Extends the Element native object to include methods useful in managing inputs.

license: MIT-style license

authors:
  - Aaron Newton

requires:
  - Core/Element
  - /MooTools.More

provides: [Element.Forms]

...
*/

Element.implement({

	tidy: function(){
		this.set('value', this.get('value').tidy());
	},

	getTextInRange: function(start, end){
		return this.get('value').substring(start, end);
	},

	getSelectedText: function(){
		if (this.setSelectionRange) return this.getTextInRange(this.getSelectionStart(), this.getSelectionEnd());
		return document.selection.createRange().text;
	},

	getSelectedRange: function() {
		if ($defined(this.selectionStart)) return {start: this.selectionStart, end: this.selectionEnd};
		var pos = {start: 0, end: 0};
		var range = this.getDocument().selection.createRange();
		if (!range || range.parentElement() != this) return pos;
		var dup = range.duplicate();
		if (this.type == 'text') {
			pos.start = 0 - dup.moveStart('character', -100000);
			pos.end = pos.start + range.text.length;
		} else {
			var value = this.get('value');
			var offset = value.length;
			dup.moveToElementText(this);
			dup.setEndPoint('StartToEnd', range);
			if(dup.text.length) offset -= value.match(/[\n\r]*$/)[0].length;
			pos.end = offset - dup.text.length;
			dup.setEndPoint('StartToStart', range);
			pos.start = offset - dup.text.length;
		}
		return pos;
	},

	getSelectionStart: function(){
		return this.getSelectedRange().start;
	},

	getSelectionEnd: function(){
		return this.getSelectedRange().end;
	},

	setCaretPosition: function(pos){
		if (pos == 'end') pos = this.get('value').length;
		this.selectRange(pos, pos);
		return this;
	},

	getCaretPosition: function(){
		return this.getSelectedRange().start;
	},

	selectRange: function(start, end){
		if (this.setSelectionRange) {
			this.focus();
			this.setSelectionRange(start, end);
		} else {
			var value = this.get('value');
			var diff = value.substr(start, end - start).replace(/\r/g, '').length;
			start = value.substr(0, start).replace(/\r/g, '').length;
			var range = this.createTextRange();
			range.collapse(true);
			range.moveEnd('character', start + diff);
			range.moveStart('character', start);
			range.select();
		}
		return this;
	},

	insertAtCursor: function(value, select){
		var pos = this.getSelectedRange();
		var text = this.get('value');
		this.set('value', text.substring(0, pos.start) + value + text.substring(pos.end, text.length));
		if ($pick(select, true)) this.selectRange(pos.start, pos.start + value.length);
		else this.setCaretPosition(pos.start + value.length);
		return this;
	},

	insertAroundCursor: function(options, select){
		options = $extend({
			before: '',
			defaultMiddle: '',
			after: ''
		}, options);
		var value = this.getSelectedText() || options.defaultMiddle;
		var pos = this.getSelectedRange();
		var text = this.get('value');
		if (pos.start == pos.end){
			this.set('value', text.substring(0, pos.start) + options.before + value + options.after + text.substring(pos.end, text.length));
			this.selectRange(pos.start + options.before.length, pos.end + options.before.length + value.length);
		} else {
			var current = text.substring(pos.start, pos.end);
			this.set('value', text.substring(0, pos.start) + options.before + current + options.after + text.substring(pos.end, text.length));
			var selStart = pos.start + options.before.length;
			if ($pick(select, true)) this.selectRange(selStart, selStart + current.length);
			else this.setCaretPosition(selStart + text.length);
		}
		return this;
	}

});

/*
---

script: Element.Measure.js

name: Element.Measure

description: Extends the Element native object to include methods useful in measuring dimensions.

credits: "Element.measure / .expose methods by Daniel Steigerwald License: MIT-style license. Copyright: Copyright (c) 2008 Daniel Steigerwald, daniel.steigerwald.cz"

license: MIT-style license

authors:
  - Aaron Newton

requires:
  - Core/Element.Style
  - Core/Element.Dimensions
  - /MooTools.More

provides: [Element.Measure]

...
*/

Element.implement({

	measure: function(fn){
		var vis = function(el) {
			return !!(!el || el.offsetHeight || el.offsetWidth);
		};
		if (vis(this)) return fn.apply(this);
		var parent = this.getParent(),
			restorers = [],
			toMeasure = []; 
		while (!vis(parent) && parent != document.body) {
			toMeasure.push(parent.expose());
			parent = parent.getParent();
		}
		var restore = this.expose();
		var result = fn.apply(this);
		restore();
		toMeasure.each(function(restore){
			restore();
		});
		return result;
	},

	expose: function(){
		if (this.getStyle('display') != 'none') return $empty;
		var before = this.style.cssText;
		this.setStyles({
			display: 'block',
			position: 'absolute',
			visibility: 'hidden'
		});
		return function(){
			this.style.cssText = before;
		}.bind(this);
	},

	getDimensions: function(options){
		options = $merge({computeSize: false},options);
		var dim = {};
		var getSize = function(el, options){
			return (options.computeSize)?el.getComputedSize(options):el.getSize();
		};
		var parent = this.getParent('body');
		if (parent && this.getStyle('display') == 'none'){
			dim = this.measure(function(){
				return getSize(this, options);
			});
		} else if (parent){
			try { //safari sometimes crashes here, so catch it
				dim = getSize(this, options);
			}catch(e){}
		} else {
			dim = {x: 0, y: 0};
		}
		return $chk(dim.x) ? $extend(dim, {width: dim.x, height: dim.y}) : $extend(dim, {x: dim.width, y: dim.height});
	},

	getComputedSize: function(options){
		//legacy support for my stupid spelling error
		if (options && options.plains) options.planes = options.plains;
		
		options = $merge({
			styles: ['padding','border'],
			planes: {
				height: ['top','bottom'],
				width: ['left','right']
			},
			mode: 'both'
		}, options);
		
		var size = {width: 0,height: 0};
		switch (options.mode){
			case 'vertical':
				delete size.width;
				delete options.planes.width;
				break;
			case 'horizontal':
				delete size.height;
				delete options.planes.height;
				break;
		}
		var getStyles = [];
		//this function might be useful in other places; perhaps it should be outside this function?
		$each(options.planes, function(plane, key){
			plane.each(function(edge){
				options.styles.each(function(style){
					getStyles.push((style == 'border') ? style + '-' + edge + '-' + 'width' : style + '-' + edge);
				});
			});
		});
		var styles = {};
		getStyles.each(function(style){ styles[style] = this.getComputedStyle(style); }, this);
		var subtracted = [];
		$each(options.planes, function(plane, key){ //keys: width, height, planes: ['left', 'right'], ['top','bottom']
			var capitalized = key.capitalize();
			size['total' + capitalized] = size['computed' + capitalized] = 0;
			plane.each(function(edge){ //top, left, right, bottom
				size['computed' + edge.capitalize()] = 0;
				getStyles.each(function(style, i){ //padding, border, etc.
					//'padding-left'.test('left') size['totalWidth'] = size['width'] + [padding-left]
					if (style.test(edge)){
						styles[style] = styles[style].toInt() || 0; //styles['padding-left'] = 5;
						size['total' + capitalized] = size['total' + capitalized] + styles[style];
						size['computed' + edge.capitalize()] = size['computed' + edge.capitalize()] + styles[style];
					}
					//if width != width (so, padding-left, for instance), then subtract that from the total
					if (style.test(edge) && key != style &&
						(style.test('border') || style.test('padding')) && !subtracted.contains(style)){
						subtracted.push(style);
						size['computed' + capitalized] = size['computed' + capitalized]-styles[style];
					}
				});
			});
		});

		['Width', 'Height'].each(function(value){
			var lower = value.toLowerCase();
			if(!$chk(size[lower])) return;

			size[lower] = size[lower] + this['offset' + value] + size['computed' + value];
			size['total' + value] = size[lower] + size['total' + value];
			delete size['computed' + value];
		}, this);

		return $extend(styles, size);
	}

});

/*
---

script: Element.Position.js

name: Element.Position

description: Extends the Element native object to include methods useful positioning elements relative to others.

license: MIT-style license

authors:
  - Aaron Newton

requires:
  - Core/Element.Dimensions
  - /Element.Measure

provides: [Element.Position]

...
*/

(function(){

var original = Element.prototype.position;

Element.implement({

	position: function(options){
		//call original position if the options are x/y values
		if (options && ($defined(options.x) || $defined(options.y))) return original ? original.apply(this, arguments) : this;
		$each(options||{}, function(v, k){ if (!$defined(v)) delete options[k]; });
		options = $merge({
			// minimum: { x: 0, y: 0 },
			// maximum: { x: 0, y: 0},
			relativeTo: document.body,
			position: {
				x: 'center', //left, center, right
				y: 'center' //top, center, bottom
			},
			edge: false,
			offset: {x: 0, y: 0},
			returnPos: false,
			relFixedPosition: false,
			ignoreMargins: false,
			ignoreScroll: false,
			allowNegative: false
		}, options);
		//compute the offset of the parent positioned element if this element is in one
		var parentOffset = {x: 0, y: 0}, 
				parentPositioned = false;
		/* dollar around getOffsetParent should not be necessary, but as it does not return
		 * a mootools extended element in IE, an error occurs on the call to expose. See:
		 * http://mootools.lighthouseapp.com/projects/2706/tickets/333-element-getoffsetparent-inconsistency-between-ie-and-other-browsers */
		var offsetParent = this.measure(function(){
			return document.id(this.getOffsetParent());
		});
		if (offsetParent && offsetParent != this.getDocument().body){
			parentOffset = offsetParent.measure(function(){
				return this.getPosition();
			});
			parentPositioned = offsetParent != document.id(options.relativeTo);
			options.offset.x = options.offset.x - parentOffset.x;
			options.offset.y = options.offset.y - parentOffset.y;
		}
		//upperRight, bottomRight, centerRight, upperLeft, bottomLeft, centerLeft
		//topRight, topLeft, centerTop, centerBottom, center
		var fixValue = function(option){
			if ($type(option) != 'string') return option;
			option = option.toLowerCase();
			var val = {};
			
			if (option.test('left')) val.x = 'left';
			else if (option.test('right')) val.x = 'right';
			else val.x = 'center';
			
			if (option.test('upper') || option.test('top')) val.y = 'top';
			else if (option.test('bottom')) val.y = 'bottom';
			else val.y = 'center';
			
			return val;
		};
		options.edge = fixValue(options.edge);
		options.position = fixValue(options.position);
		if (!options.edge){
			if (options.position.x == 'center' && options.position.y == 'center') options.edge = {x:'center', y:'center'};
			else options.edge = {x:'left', y:'top'};
		}

		this.setStyle('position', 'absolute');
		var rel = document.id(options.relativeTo) || document.body,
				calc = rel == document.body ? window.getScroll() : rel.getPosition(),
				top = calc.y, left = calc.x;

		var dim = this.getDimensions({computeSize: true, styles:['padding', 'border','margin']});
		var pos = {},
				prefY = options.offset.y,
				prefX = options.offset.x,
				winSize = window.getSize();
		switch(options.position.x){
			case 'left':
				pos.x = left + prefX;
				break;
			case 'right':
				pos.x = left + prefX + rel.offsetWidth;
				break;
			default: //center
				pos.x = left + ((rel == document.body ? winSize.x : rel.offsetWidth)/2) + prefX;
				break;
		}
		switch(options.position.y){
			case 'top':
				pos.y = top + prefY;
				break;
			case 'bottom':
				pos.y = top + prefY + rel.offsetHeight;
				break;
			default: //center
				pos.y = top + ((rel == document.body ? winSize.y : rel.offsetHeight)/2) + prefY;
				break;
		}
		if (options.edge){
			var edgeOffset = {};

			switch(options.edge.x){
				case 'left':
					edgeOffset.x = 0;
					break;
				case 'right':
					edgeOffset.x = -dim.x-dim.computedRight-dim.computedLeft;
					break;
				default: //center
					edgeOffset.x = -(dim.totalWidth/2);
					break;
			}
			switch(options.edge.y){
				case 'top':
					edgeOffset.y = 0;
					break;
				case 'bottom':
					edgeOffset.y = -dim.y-dim.computedTop-dim.computedBottom;
					break;
				default: //center
					edgeOffset.y = -(dim.totalHeight/2);
					break;
			}
			pos.x += edgeOffset.x;
			pos.y += edgeOffset.y;
		}
		pos = {
			left: ((pos.x >= 0 || parentPositioned || options.allowNegative) ? pos.x : 0).toInt(),
			top: ((pos.y >= 0 || parentPositioned || options.allowNegative) ? pos.y : 0).toInt()
		};
		var xy = {left: 'x', top: 'y'};
		['minimum', 'maximum'].each(function(minmax) {
			['left', 'top'].each(function(lr) {
				var val = options[minmax] ? options[minmax][xy[lr]] : null;
				if (val != null && ((minmax == 'minimum') ? pos[lr] < val: pos[lr] > val)) pos[lr] = val;
			});
		});
		if (rel.getStyle('position') == 'fixed' || options.relFixedPosition){
			var winScroll = window.getScroll();
			pos.top+= winScroll.y;
			pos.left+= winScroll.x;
		}
		var relScroll = rel.getScroll();
		if (options.ignoreScroll) {
			pos.top -= relScroll.y;
			pos.left -= relScroll.x;
		} else {
			pos.top += relScroll.y;
			pos.left += relScroll.x;
		}
		if (options.ignoreMargins) {
			pos.left += (
				options.edge.x == 'right' ? dim['margin-right'] : 
				options.edge.x == 'center' ? -dim['margin-left'] + ((dim['margin-right'] + dim['margin-left'])/2) : 
					- dim['margin-left']
			);
			pos.top += (
				options.edge.y == 'bottom' ? dim['margin-bottom'] : 
				options.edge.y == 'center' ? -dim['margin-top'] + ((dim['margin-bottom'] + dim['margin-top'])/2) : 
					- dim['margin-top']
			);
		}
		pos.left = Math.ceil(pos.left);
		pos.top = Math.ceil(pos.top);
		if (options.returnPos) return pos;
		else this.setStyles(pos);
		return this;
	}

});

})();


/*
---

script: Element.Shortcuts.js

name: Element.Shortcuts

description: Extends the Element native object to include some shortcut methods.

license: MIT-style license

authors:
  - Aaron Newton

requires:
  - Core/Element.Style
  - /MooTools.More

provides: [Element.Shortcuts]

...
*/

Element.implement({

	isDisplayed: function(){
		return this.getStyle('display') != 'none';
	},

	isVisible: function(){
		var w = this.offsetWidth,
			h = this.offsetHeight;
		return (w == 0 && h == 0) ? false : (w > 0 && h > 0) ? true : this.style.display != 'none';
	},

	toggle: function(){
		return this[this.isDisplayed() ? 'hide' : 'show']();
	},

	hide: function(){
		var d;
		try {
			//IE fails here if the element is not in the dom
			d = this.getStyle('display');
		} catch(e){}
		if (d == "none") return this;
		return this.store('element:_originalDisplay', d || '').setStyle('display', 'none');
	},

	show: function(display){
		if (!display && this.isDisplayed()) return this;
		display = display || this.retrieve('element:_originalDisplay') || 'block';
		return this.setStyle('display', (display == 'none') ? 'block' : display);
	},

	swapClass: function(remove, add){
		return this.removeClass(remove).addClass(add);
	}
});

Document.implement({
	clearSelection: function(){
		if (document.selection && document.selection.empty) {
			document.selection.empty();
		} else if (window.getSelection) {
			var selection = window.getSelection();
			if (selection && selection.removeAllRanges) selection.removeAllRanges();
		}
	}
});

/*
---

script: Fx.Elements.js

name: Fx.Elements

description: Effect to change any number of CSS properties of any number of Elements.

license: MIT-style license

authors:
  - Valerio Proietti

requires:
  - Core/Fx.CSS
  - /MooTools.More

provides: [Fx.Elements]

...
*/

Fx.Elements = new Class({

	Extends: Fx.CSS,

	initialize: function(elements, options){
		this.elements = this.subject = $$(elements);
		this.parent(options);
	},

	compute: function(from, to, delta){
		var now = {};

		for (var i in from){
			var iFrom = from[i], iTo = to[i], iNow = now[i] = {};
			for (var p in iFrom) iNow[p] = this.parent(iFrom[p], iTo[p], delta);
		}

		return now;
	},

	set: function(now){
		for (var i in now){
			if (!this.elements[i]) continue;

			var iNow = now[i];
			for (var p in iNow) this.render(this.elements[i], p, iNow[p], this.options.unit);
		}

		return this;
	},

	start: function(obj){
		if (!this.check(obj)) return this;
		var from = {}, to = {};

		for (var i in obj){
			if (!this.elements[i]) continue;

			var iProps = obj[i], iFrom = from[i] = {}, iTo = to[i] = {};

			for (var p in iProps){
				var parsed = this.prepare(this.elements[i], p, iProps[p]);
				iFrom[p] = parsed.from;
				iTo[p] = parsed.to;
			}
		}

		return this.parent(from, to);
	}

});


/*
---

script: Fx.Accordion.js

name: Fx.Accordion

description: An Fx.Elements extension which allows you to easily create accordion type controls.

license: MIT-style license

authors:
  - Valerio Proietti

requires:
  - Core/Element.Event
  - /Fx.Elements

provides: [Fx.Accordion]

...
*/

Fx.Accordion = new Class({

	Extends: Fx.Elements,

	options: {/*
		onActive: $empty(toggler, section),
		onBackground: $empty(toggler, section),
		*/
		fixedHeight: false,
		fixedWidth: false,
		display: 0,
		show: false,
		height: true,
		width: false,
		opacity: true,
		alwaysHide: false,
		trigger: 'click',
		initialDisplayFx: true,
		returnHeightToAuto: true
	},

	initialize: function(){
		var params = Array.link(arguments, {
			'container': Element.type, //deprecated
			'options': Object.type,
			'togglers': $defined,
			'elements': $defined
		});
		this.parent(params.elements, params.options);
		this.togglers = $$(params.togglers);
		this.previous = -1;
		this.internalChain = new Chain();
		if (this.options.alwaysHide) this.options.wait = true;
		if ($chk(this.options.show)){
			this.options.display = false;
			this.previous = this.options.show;
		}
		if (this.options.start){
			this.options.display = false;
			this.options.show = false;
		}
		this.effects = {};
		if (this.options.opacity) this.effects.opacity = 'fullOpacity';
		if (this.options.width) this.effects.width = this.options.fixedWidth ? 'fullWidth' : 'offsetWidth';
		if (this.options.height) this.effects.height = this.options.fixedHeight ? 'fullHeight' : 'scrollHeight';
		for (var i = 0, l = this.togglers.length; i < l; i++) this.addSection(this.togglers[i], this.elements[i]);
		this.elements.each(function(el, i){
			if (this.options.show === i){
				this.fireEvent('active', [this.togglers[i], el]);
			} else {
				for (var fx in this.effects) el.setStyle(fx, 0);
			}
		}, this);
		if ($chk(this.options.display) || this.options.initialDisplayFx === false) this.display(this.options.display, this.options.initialDisplayFx);
		if (this.options.fixedHeight !== false) this.options.returnHeightToAuto = false;
		this.addEvent('complete', this.internalChain.callChain.bind(this.internalChain));
	},

	addSection: function(toggler, element){
		toggler = document.id(toggler);
		element = document.id(element);
		var test = this.togglers.contains(toggler);
		this.togglers.include(toggler);
		this.elements.include(element);
		var idx = this.togglers.indexOf(toggler);
		var displayer = this.display.bind(this, idx);
		toggler.store('accordion:display', displayer);
		toggler.addEvent(this.options.trigger, displayer);
		if (this.options.height) element.setStyles({'padding-top': 0, 'border-top': 'none', 'padding-bottom': 0, 'border-bottom': 'none'});
		if (this.options.width) element.setStyles({'padding-left': 0, 'border-left': 'none', 'padding-right': 0, 'border-right': 'none'});
		element.fullOpacity = 1;
		if (this.options.fixedWidth) element.fullWidth = this.options.fixedWidth;
		if (this.options.fixedHeight) element.fullHeight = this.options.fixedHeight;
		element.setStyle('overflow', 'hidden');
		if (!test){
			for (var fx in this.effects) element.setStyle(fx, 0);
		}
		return this;
	},

	removeSection: function(toggler, displayIndex) {
		var idx = this.togglers.indexOf(toggler);
		var element = this.elements[idx];
		var remover = function(){
			this.togglers.erase(toggler);
			this.elements.erase(element);
			this.detach(toggler);
		}.bind(this);
		if (this.now == idx || displayIndex != undefined) this.display($pick(displayIndex, idx - 1 >= 0 ? idx - 1 : 0)).chain(remover);
		else remover();
		return this;
	},

	detach: function(toggler){
		var remove = function(toggler) {
			toggler.removeEvent(this.options.trigger, toggler.retrieve('accordion:display'));
		}.bind(this);
		if (!toggler) this.togglers.each(remove);
		else remove(toggler);
		return this;
	},

	display: function(index, useFx){
		if (!this.check(index, useFx)) return this;
		useFx = $pick(useFx, true);
		index = ($type(index) == 'element') ? this.elements.indexOf(index) : index;
		if (index == this.previous && !this.options.alwaysHide) return this;
		if (this.options.returnHeightToAuto){
			var prev = this.elements[this.previous];
			if (prev && !this.selfHidden){
				for (var fx in this.effects){
					prev.setStyle(fx, prev[this.effects[fx]]);
				}
			}
		}
		if ((this.timer && this.options.wait) || (index === this.previous && !this.options.alwaysHide)) return this;
		this.previous = index;
		var obj = {};
		this.elements.each(function(el, i){
			obj[i] = {};
			var hide;
			if (i != index){
				hide = true;
			} else if (this.options.alwaysHide && ((el.offsetHeight > 0 && this.options.height) || el.offsetWidth > 0 && this.options.width)){
				hide = true;
				this.selfHidden = true;
			}
			this.fireEvent(hide ? 'background' : 'active', [this.togglers[i], el]);
			for (var fx in this.effects) obj[i][fx] = hide ? 0 : el[this.effects[fx]];
		}, this);
		this.internalChain.clearChain();
		this.internalChain.chain(function(){
			if (this.options.returnHeightToAuto && !this.selfHidden){
				var el = this.elements[index];
				if (el) el.setStyle('height', 'auto');
			};
		}.bind(this));
		return useFx ? this.start(obj) : this.set(obj);
	}

});

/*
	Compatibility with 1.2.0
*/
var Accordion = new Class({

	Extends: Fx.Accordion,

	initialize: function(){
		this.parent.apply(this, arguments);
		var params = Array.link(arguments, {'container': Element.type});
		this.container = params.container;
	},

	addSection: function(toggler, element, pos){
		toggler = document.id(toggler);
		element = document.id(element);
		var test = this.togglers.contains(toggler);
		var len = this.togglers.length;
		if (len && (!test || pos)){
			pos = $pick(pos, len - 1);
			toggler.inject(this.togglers[pos], 'before');
			element.inject(toggler, 'after');
		} else if (this.container && !test){
			toggler.inject(this.container);
			element.inject(this.container);
		}
		return this.parent.apply(this, arguments);
	}

});

/*
---

script: Fx.Move.js

name: Fx.Move

description: Defines Fx.Move, a class that works with Element.Position.js to transition an element from one location to another.

license: MIT-style license

authors:
  - Aaron Newton

requires:
  - Core/Fx.Morph
  - /Element.Position

provides: [Fx.Move]

...
*/

Fx.Move = new Class({

	Extends: Fx.Morph,

	options: {
		relativeTo: document.body,
		position: 'center',
		edge: false,
		offset: {x: 0, y: 0}
	},

	start: function(destination){
		var element = this.element,
			topLeft = element.getStyles('top', 'left');
		if (topLeft.top == 'auto' || topLeft.left == 'auto'){
			element.setPosition(element.getPosition(element.getOffsetParent()));
		}
		return this.parent(element.position($merge(this.options, destination, {returnPos: true})));
	}

});

Element.Properties.move = {

	set: function(options){
		var morph = this.retrieve('move');
		if (morph) morph.cancel();
		return this.eliminate('move').store('move:options', $extend({link: 'cancel'}, options));
	},

	get: function(options){
		if (options || !this.retrieve('move')){
			if (options || !this.retrieve('move:options')) this.set('move', options);
			this.store('move', new Fx.Move(this, this.retrieve('move:options')));
		}
		return this.retrieve('move');
	}

};

Element.implement({

	move: function(options){
		this.get('move').start(options);
		return this;
	}

});


/*
---

script: Fx.Reveal.js

name: Fx.Reveal

description: Defines Fx.Reveal, a class that shows and hides elements with a transition.

license: MIT-style license

authors:
  - Aaron Newton

requires:
  - Core/Fx.Morph
  - /Element.Shortcuts
  - /Element.Measure

provides: [Fx.Reveal]

...
*/

Fx.Reveal = new Class({

	Extends: Fx.Morph,

	options: {/*	  
		onShow: $empty(thisElement),
		onHide: $empty(thisElement),
		onComplete: $empty(thisElement),
		heightOverride: null,
		widthOverride: null, */
		link: 'cancel',
		styles: ['padding', 'border', 'margin'],
		transitionOpacity: !Browser.Engine.trident4,
		mode: 'vertical',
		display: function(){
			return this.element.get('tag') != 'tr' ? 'block' : 'table-row';
		},
		hideInputs: Browser.Engine.trident ? 'select, input, textarea, object, embed' : false,
		opacity: 1
	},

	dissolve: function(){
		try {
			if (!this.hiding && !this.showing){
				if (this.element.getStyle('display') != 'none'){
					this.hiding = true;
					this.showing = false;
					this.hidden = true;
					this.cssText = this.element.style.cssText;
					var startStyles = this.element.getComputedSize({
						styles: this.options.styles,
						mode: this.options.mode
					});
					this.element.setStyle('display', $lambda(this.options.display).apply(this));
					if (this.options.transitionOpacity) startStyles.opacity = this.options.opacity;
					var zero = {};
					$each(startStyles, function(style, name){
						zero[name] = [style, 0];
					}, this);
					this.element.setStyle('overflow', 'hidden');
					var hideThese = this.options.hideInputs ? this.element.getElements(this.options.hideInputs) : null;
					this.$chain.unshift(function(){
						if (this.hidden){
							this.hiding = false;
							$each(startStyles, function(style, name){
								startStyles[name] = style;
							}, this);
							this.element.style.cssText = this.cssText;
							this.element.setStyle('display', 'none');
							if (hideThese) hideThese.setStyle('visibility', 'visible');
						}
						this.fireEvent('hide', this.element);
						this.callChain();
					}.bind(this));
					if (hideThese) hideThese.setStyle('visibility', 'hidden');
					this.start(zero);
				} else {
					this.callChain.delay(10, this);
					this.fireEvent('complete', this.element);
					this.fireEvent('hide', this.element);
				}
			} else if (this.options.link == 'chain'){
				this.chain(this.dissolve.bind(this));
			} else if (this.options.link == 'cancel' && !this.hiding){
				this.cancel();
				this.dissolve();
			}
		} catch(e){
			this.hiding = false;
			this.element.setStyle('display', 'none');
			this.callChain.delay(10, this);
			this.fireEvent('complete', this.element);
			this.fireEvent('hide', this.element);
		}
		return this;
	},

	reveal: function(){
		try {
			if (!this.showing && !this.hiding){
				if (this.element.getStyle('display') == 'none'){
					this.showing = true;
					this.hiding = this.hidden =  false;
					var startStyles;
					this.cssText = this.element.style.cssText;
					//toggle display, but hide it
					this.element.measure(function(){
						//create the styles for the opened/visible state
						startStyles = this.element.getComputedSize({
							styles: this.options.styles,
							mode: this.options.mode
						});
					}.bind(this));
					$each(startStyles, function(style, name){
						startStyles[name] = style;
					});
					//if we're overridding height/width
					if ($chk(this.options.heightOverride)) startStyles.height = this.options.heightOverride.toInt();
					if ($chk(this.options.widthOverride)) startStyles.width = this.options.widthOverride.toInt();
					if (this.options.transitionOpacity) {
						this.element.setStyle('opacity', 0);
						startStyles.opacity = this.options.opacity;
					}
					//create the zero state for the beginning of the transition
					var zero = {
						height: 0,
						display: $lambda(this.options.display).apply(this)
					};
					$each(startStyles, function(style, name){ zero[name] = 0; });
					//set to zero
					this.element.setStyles($merge(zero, {overflow: 'hidden'}));
					//hide inputs
					var hideThese = this.options.hideInputs ? this.element.getElements(this.options.hideInputs) : null;
					if (hideThese) hideThese.setStyle('visibility', 'hidden');
					//start the effect
					this.start(startStyles);
					this.$chain.unshift(function(){
						this.element.style.cssText = this.cssText;
						this.element.setStyle('display', $lambda(this.options.display).apply(this));
						if (!this.hidden) this.showing = false;
						if (hideThese) hideThese.setStyle('visibility', 'visible');
						this.callChain();
						this.fireEvent('show', this.element);
					}.bind(this));
				} else {
					this.callChain();
					this.fireEvent('complete', this.element);
					this.fireEvent('show', this.element);
				}
			} else if (this.options.link == 'chain'){
				this.chain(this.reveal.bind(this));
			} else if (this.options.link == 'cancel' && !this.showing){
				this.cancel();
				this.reveal();
			}
		} catch(e){
			this.element.setStyles({
				display: $lambda(this.options.display).apply(this),
				visiblity: 'visible',
				opacity: this.options.opacity
			});
			this.showing = false;
			this.callChain.delay(10, this);
			this.fireEvent('complete', this.element);
			this.fireEvent('show', this.element);
		}
		return this;
	},

	toggle: function(){
		if (this.element.getStyle('display') == 'none'){
			this.reveal();
		} else {
			this.dissolve();
		}
		return this;
	},

	cancel: function(){
		this.parent.apply(this, arguments);
		this.element.style.cssText = this.cssText;
		this.hiding = false;
		this.showing = false;
		return this;
	}

});

Element.Properties.reveal = {

	set: function(options){
		var reveal = this.retrieve('reveal');
		if (reveal) reveal.cancel();
		return this.eliminate('reveal').store('reveal:options', options);
	},

	get: function(options){
		if (options || !this.retrieve('reveal')){
			if (options || !this.retrieve('reveal:options')) this.set('reveal', options);
			this.store('reveal', new Fx.Reveal(this, this.retrieve('reveal:options')));
		}
		return this.retrieve('reveal');
	}

};

Element.Properties.dissolve = Element.Properties.reveal;

Element.implement({

	reveal: function(options){
		this.get('reveal', options).reveal();
		return this;
	},

	dissolve: function(options){
		this.get('reveal', options).dissolve();
		return this;
	},

	nix: function(){
		var params = Array.link(arguments, {destroy: Boolean.type, options: Object.type});
		this.get('reveal', params.options).dissolve().chain(function(){
			this[params.destroy ? 'destroy' : 'dispose']();
		}.bind(this));
		return this;
	},

	wink: function(){
		var params = Array.link(arguments, {duration: Number.type, options: Object.type});
		var reveal = this.get('reveal', params.options);
		reveal.reveal().chain(function(){
			(function(){
				reveal.dissolve();
			}).delay(params.duration || 2000);
		});
	}


});

/*
---

script: Fx.Scroll.js

name: Fx.Scroll

description: Effect to smoothly scroll any element, including the window.

license: MIT-style license

authors:
  - Valerio Proietti

requires:
  - Core/Fx
  - Core/Element.Event
  - Core/Element.Dimensions
  - /MooTools.More

provides: [Fx.Scroll]

...
*/

Fx.Scroll = new Class({

	Extends: Fx,

	options: {
		offset: {x: 0, y: 0},
		wheelStops: true
	},

	initialize: function(element, options){
		this.element = this.subject = document.id(element);
		this.parent(options);
		var cancel = this.cancel.bind(this, false);

		if ($type(this.element) != 'element') this.element = document.id(this.element.getDocument().body);

		var stopper = this.element;

		if (this.options.wheelStops){
			this.addEvent('start', function(){
				stopper.addEvent('mousewheel', cancel);
			}, true);
			this.addEvent('complete', function(){
				stopper.removeEvent('mousewheel', cancel);
			}, true);
		}
	},

	set: function(){
		var now = Array.flatten(arguments);
		if (Browser.Engine.gecko) now = [Math.round(now[0]), Math.round(now[1])];
		this.element.scrollTo(now[0] + this.options.offset.x, now[1] + this.options.offset.y);
	},

	compute: function(from, to, delta){
		return [0, 1].map(function(i){
			return Fx.compute(from[i], to[i], delta);
		});
	},

	start: function(x, y){
		if (!this.check(x, y)) return this;
		var scrollSize = this.element.getScrollSize(),
			scroll = this.element.getScroll(), 
			values = {x: x, y: y};
		for (var z in values){
			var max = scrollSize[z];
			if ($chk(values[z])) values[z] = ($type(values[z]) == 'number') ? values[z] : max;
			else values[z] = scroll[z];
			values[z] += this.options.offset[z];
		}
		return this.parent([scroll.x, scroll.y], [values.x, values.y]);
	},

	toTop: function(){
		return this.start(false, 0);
	},

	toLeft: function(){
		return this.start(0, false);
	},

	toRight: function(){
		return this.start('right', false);
	},

	toBottom: function(){
		return this.start(false, 'bottom');
	},

	toElement: function(el){
		var position = document.id(el).getPosition(this.element);
		return this.start(position.x, position.y);
	},

	scrollIntoView: function(el, axes, offset){
		axes = axes ? $splat(axes) : ['x','y'];
		var to = {};
		el = document.id(el);
		var pos = el.getPosition(this.element);
		var size = el.getSize();
		var scroll = this.element.getScroll();
		var containerSize = this.element.getSize();
		var edge = {
			x: pos.x + size.x,
			y: pos.y + size.y
		};
		['x','y'].each(function(axis) {
			if (axes.contains(axis)) {
				if (edge[axis] > scroll[axis] + containerSize[axis]) to[axis] = edge[axis] - containerSize[axis];
				if (pos[axis] < scroll[axis]) to[axis] = pos[axis];
			}
			if (to[axis] == null) to[axis] = scroll[axis];
			if (offset && offset[axis]) to[axis] = to[axis] + offset[axis];
		}, this);
		if (to.x != scroll.x || to.y != scroll.y) this.start(to.x, to.y);
		return this;
	},

	scrollToCenter: function(el, axes, offset){
		axes = axes ? $splat(axes) : ['x', 'y'];
		el = $(el);
		var to = {},
			pos = el.getPosition(this.element),
			size = el.getSize(),
			scroll = this.element.getScroll(),
			containerSize = this.element.getSize(),
			edge = {
				x: pos.x + size.x,
				y: pos.y + size.y
			};

		['x','y'].each(function(axis){
			if(axes.contains(axis)){
				to[axis] = pos[axis] - (containerSize[axis] - size[axis])/2;
			}
			if(to[axis] == null) to[axis] = scroll[axis];
			if(offset && offset[axis]) to[axis] = to[axis] + offset[axis];
		}, this);
		if (to.x != scroll.x || to.y != scroll.y) this.start(to.x, to.y);
		return this;
	}

});


/*
---

script: Fx.Slide.js

name: Fx.Slide

description: Effect to slide an element in and out of view.

license: MIT-style license

authors:
  - Valerio Proietti

requires:
  - Core/Fx
  - Core/Element.Style
  - /MooTools.More

provides: [Fx.Slide]

...
*/

Fx.Slide = new Class({

	Extends: Fx,

	options: {
		mode: 'vertical',
		wrapper: false,
		hideOverflow: true,
		resetHeight: false
	},

	initialize: function(element, options){
		this.addEvent('complete', function(){
			this.open = (this.wrapper['offset' + this.layout.capitalize()] != 0);
			if (this.open && this.options.resetHeight) this.wrapper.setStyle('height', '');
			if (this.open && Browser.Engine.webkit419) this.element.dispose().inject(this.wrapper);
		}, true);
		this.element = this.subject = document.id(element);
		this.parent(options);
		var wrapper = this.element.retrieve('wrapper');
		var styles = this.element.getStyles('margin', 'position', 'overflow');
		if (this.options.hideOverflow) styles = $extend(styles, {overflow: 'hidden'});
		if (this.options.wrapper) wrapper = document.id(this.options.wrapper).setStyles(styles);
		this.wrapper = wrapper || new Element('div', {
			styles: styles
		}).wraps(this.element);
		this.element.store('wrapper', this.wrapper).setStyle('margin', 0);
		this.now = [];
		this.open = true;
	},

	vertical: function(){
		this.margin = 'margin-top';
		this.layout = 'height';
		this.offset = this.element.offsetHeight;
	},

	horizontal: function(){
		this.margin = 'margin-left';
		this.layout = 'width';
		this.offset = this.element.offsetWidth;
	},

	set: function(now){
		this.element.setStyle(this.margin, now[0]);
		this.wrapper.setStyle(this.layout, now[1]);
		return this;
	},

	compute: function(from, to, delta){
		return [0, 1].map(function(i){
			return Fx.compute(from[i], to[i], delta);
		});
	},

	start: function(how, mode){
		if (!this.check(how, mode)) return this;
		this[mode || this.options.mode]();
		var margin = this.element.getStyle(this.margin).toInt();
		var layout = this.wrapper.getStyle(this.layout).toInt();
		var caseIn = [[margin, layout], [0, this.offset]];
		var caseOut = [[margin, layout], [-this.offset, 0]];
		var start;
		switch (how){
			case 'in': start = caseIn; break;
			case 'out': start = caseOut; break;
			case 'toggle': start = (layout == 0) ? caseIn : caseOut;
		}
		return this.parent(start[0], start[1]);
	},

	slideIn: function(mode){
		return this.start('in', mode);
	},

	slideOut: function(mode){
		return this.start('out', mode);
	},

	hide: function(mode){
		this[mode || this.options.mode]();
		this.open = false;
		return this.set([-this.offset, 0]);
	},

	show: function(mode){
		this[mode || this.options.mode]();
		this.open = true;
		return this.set([0, this.offset]);
	},

	toggle: function(mode){
		return this.start('toggle', mode);
	}

});

Element.Properties.slide = {

	set: function(options){
		var slide = this.retrieve('slide');
		if (slide) slide.cancel();
		return this.eliminate('slide').store('slide:options', $extend({link: 'cancel'}, options));
	},

	get: function(options){
		if (options || !this.retrieve('slide')){
			if (options || !this.retrieve('slide:options')) this.set('slide', options);
			this.store('slide', new Fx.Slide(this, this.retrieve('slide:options')));
		}
		return this.retrieve('slide');
	}

};

Element.implement({

	slide: function(how, mode){
		how = how || 'toggle';
		var slide = this.get('slide'), toggle;
		switch (how){
			case 'hide': slide.hide(mode); break;
			case 'show': slide.show(mode); break;
			case 'toggle':
				var flag = this.retrieve('slide:flag', slide.open);
				slide[flag ? 'slideOut' : 'slideIn'](mode);
				this.store('slide:flag', !flag);
				toggle = true;
			break;
			default: slide.start(how, mode);
		}
		if (!toggle) this.eliminate('slide:flag');
		return this;
	}

});


/*
---

script: Fx.SmoothScroll.js

name: Fx.SmoothScroll

description: Class for creating a smooth scrolling effect to all internal links on the page.

license: MIT-style license

authors:
  - Valerio Proietti

requires:
  - Core/Selectors
  - /Fx.Scroll

provides: [Fx.SmoothScroll]

...
*/

var SmoothScroll = Fx.SmoothScroll = new Class({

	Extends: Fx.Scroll,

	initialize: function(options, context){
		context = context || document;
		this.doc = context.getDocument();
		var win = context.getWindow();
		this.parent(this.doc, options);
		this.links = $$(this.options.links || this.doc.links);
		var location = win.location.href.match(/^[^#]*/)[0] + '#';
		this.links.each(function(link){
			if (link.href.indexOf(location) != 0) {return;}
			var anchor = link.href.substr(location.length);
			if (anchor) this.useLink(link, anchor);
		}, this);
		if (!Browser.Engine.webkit419) {
			this.addEvent('complete', function(){
				win.location.hash = this.anchor;
			}, true);
		}
	},

	useLink: function(link, anchor){
		var el;
		link.addEvent('click', function(event){
			if (el !== false && !el) el = document.id(anchor) || this.doc.getElement('a[name=' + anchor + ']');
			if (el) {
				event.preventDefault();
				this.anchor = anchor;
				this.toElement(el).chain(function(){
					this.fireEvent('scrolledTo', [link, el]);
				}.bind(this));
				link.blur();
			}
		}.bind(this));
	}
});

/*
---

script: Fx.Sort.js

name: Fx.Sort

description: Defines Fx.Sort, a class that reorders lists with a transition.

license: MIT-style license

authors:
  - Aaron Newton

requires:
  - Core/Element.Dimensions
  - /Fx.Elements
  - /Element.Measure

provides: [Fx.Sort]

...
*/

Fx.Sort = new Class({

	Extends: Fx.Elements,

	options: {
		mode: 'vertical'
	},

	initialize: function(elements, options){
		this.parent(elements, options);
		this.elements.each(function(el){
			if (el.getStyle('position') == 'static') el.setStyle('position', 'relative');
		});
		this.setDefaultOrder();
	},

	setDefaultOrder: function(){
		this.currentOrder = this.elements.map(function(el, index){
			return index;
		});
	},

	sort: function(newOrder){
		if ($type(newOrder) != 'array') return false;
		var top = 0,
			left = 0,
			next = {},
			zero = {},
			vert = this.options.mode == 'vertical';
		var current = this.elements.map(function(el, index){
			var size = el.getComputedSize({styles: ['border', 'padding', 'margin']});
			var val;
			if (vert){
				val = {
					top: top,
					margin: size['margin-top'],
					height: size.totalHeight
				};
				top += val.height - size['margin-top'];
			} else {
				val = {
					left: left,
					margin: size['margin-left'],
					width: size.totalWidth
				};
				left += val.width;
			}
			var plane = vert ? 'top' : 'left';
			zero[index] = {};
			var start = el.getStyle(plane).toInt();
			zero[index][plane] = start || 0;
			return val;
		}, this);
		this.set(zero);
		newOrder = newOrder.map(function(i){ return i.toInt(); });
		if (newOrder.length != this.elements.length){
			this.currentOrder.each(function(index){
				if (!newOrder.contains(index)) newOrder.push(index);
			});
			if (newOrder.length > this.elements.length)
				newOrder.splice(this.elements.length-1, newOrder.length - this.elements.length);
		}
		var margin = top = left = 0;
		newOrder.each(function(item, index){
			var newPos = {};
			if (vert){
				newPos.top = top - current[item].top - margin;
				top += current[item].height;
			} else {
				newPos.left = left - current[item].left;
				left += current[item].width;
			}
			margin = margin + current[item].margin;
			next[item]=newPos;
		}, this);
		var mapped = {};
		$A(newOrder).sort().each(function(index){
			mapped[index] = next[index];
		});
		this.start(mapped);
		this.currentOrder = newOrder;
		return this;
	},

	rearrangeDOM: function(newOrder){
		newOrder = newOrder || this.currentOrder;
		var parent = this.elements[0].getParent();
		var rearranged = [];
		this.elements.setStyle('opacity', 0);
		//move each element and store the new default order
		newOrder.each(function(index){
			rearranged.push(this.elements[index].inject(parent).setStyles({
				top: 0,
				left: 0
			}));
		}, this);
		this.elements.setStyle('opacity', 1);
		this.elements = $$(rearranged);
		this.setDefaultOrder();
		return this;
	},

	getDefaultOrder: function(){
		return this.elements.map(function(el, index){
			return index;
		});
	},

	forward: function(){
		return this.sort(this.getDefaultOrder());
	},

	backward: function(){
		return this.sort(this.getDefaultOrder().reverse());
	},

	reverse: function(){
		return this.sort(this.currentOrder.reverse());
	},

	sortByElements: function(elements){
		return this.sort(elements.map(function(el){
			return this.elements.indexOf(el);
		}, this));
	},

	swap: function(one, two){
		if ($type(one) == 'element') one = this.elements.indexOf(one);
		if ($type(two) == 'element') two = this.elements.indexOf(two);
		
		var newOrder = $A(this.currentOrder);
		newOrder[this.currentOrder.indexOf(one)] = two;
		newOrder[this.currentOrder.indexOf(two)] = one;
		return this.sort(newOrder);
	}

});

/*
---

script: Drag.js

name: Drag

description: The base Drag Class. Can be used to drag and resize Elements using mouse events.

license: MIT-style license

authors:
  - Valerio Proietti
  - Tom Occhinno
  - Jan Kassens

requires:
  - Core/Events
  - Core/Options
  - Core/Element.Event
  - Core/Element.Style
  - Core/Element.Dimensions
  - /MooTools.More

provides: [Drag]
...

*/

var Drag = new Class({

	Implements: [Events, Options],

	options: {/*
		onBeforeStart: $empty(thisElement),
		onStart: $empty(thisElement, event),
		onSnap: $empty(thisElement)
		onDrag: $empty(thisElement, event),
		onCancel: $empty(thisElement),
		onComplete: $empty(thisElement, event),*/
		snap: 6,
		unit: 'px',
		grid: false,
		style: true,
		limit: false,
		handle: false,
		invert: false,
		preventDefault: false,
		stopPropagation: false,
		modifiers: {x: 'left', y: 'top'}
	},

	initialize: function(){
		var params = Array.link(arguments, {'options': Object.type, 'element': $defined});
		this.element = document.id(params.element);
		this.document = this.element.getDocument();
		this.setOptions(params.options || {});
		var htype = $type(this.options.handle);
		this.handles = ((htype == 'array' || htype == 'collection') ? $$(this.options.handle) : document.id(this.options.handle)) || this.element;
		this.mouse = {'now': {}, 'pos': {}};
		this.value = {'start': {}, 'now': {}};

		this.selection = (Browser.Engine.trident) ? 'selectstart' : 'mousedown';

		this.bound = {
			start: this.start.bind(this),
			check: this.check.bind(this),
			drag: this.drag.bind(this),
			stop: this.stop.bind(this),
			cancel: this.cancel.bind(this),
			eventStop: $lambda(false)
		};
		this.attach();
	},

	attach: function(){
		this.handles.addEvent('mousedown', this.bound.start);
		return this;
	},

	detach: function(){
		this.handles.removeEvent('mousedown', this.bound.start);
		return this;
	},

	start: function(event){
		if (event.rightClick) return;
		if (this.options.preventDefault) event.preventDefault();
		if (this.options.stopPropagation) event.stopPropagation();
		this.mouse.start = event.page;
		this.fireEvent('beforeStart', this.element);
		var limit = this.options.limit;
		this.limit = {x: [], y: []};
		var styles = this.element.getStyles('left', 'right', 'top', 'bottom');
		this._invert = {
			x: this.options.modifiers.x == 'left' && styles.left == 'auto' &&
			   !isNaN(styles.right.toInt()) && (this.options.modifiers.x = 'right'),
			y: this.options.modifiers.y == 'top' && styles.top == 'auto' &&
			   !isNaN(styles.bottom.toInt()) && (this.options.modifiers.y = 'bottom')
		};

		var z, coordinates;
		for (z in this.options.modifiers){
			if (!this.options.modifiers[z]) continue;

			var style = this.element.getStyle(this.options.modifiers[z]);

			// Some browsers (IE and Opera) don't always return pixels.
			if (style && !style.match(/px$/)){
				if (!coordinates) coordinates = this.element.getCoordinates(this.element.getOffsetParent());
				style = coordinates[this.options.modifiers[z]];
			}

			if (this.options.style) this.value.now[z] = (style || 0).toInt();
			else this.value.now[z] = this.element[this.options.modifiers[z]];

			if (this.options.invert) this.value.now[z] *= -1;
			if (this._invert[z]) this.value.now[z] *= -1;

			this.mouse.pos[z] = event.page[z] - this.value.now[z];

			if (limit && limit[z]){
				for (var i = 2; i--; i){
					if ($chk(limit[z][i])) this.limit[z][i] = $lambda(limit[z][i])();
				}
			}
		}

		if ($type(this.options.grid) == 'number') this.options.grid = {x: this.options.grid, y: this.options.grid};
		this.document.addEvents({mousemove: this.bound.check, mouseup: this.bound.cancel});
		this.document.addEvent(this.selection, this.bound.eventStop);
	},

	check: function(event){
		if (this.options.preventDefault) event.preventDefault();
		var distance = Math.round(Math.sqrt(Math.pow(event.page.x - this.mouse.start.x, 2) + Math.pow(event.page.y - this.mouse.start.y, 2)));
		if (distance > this.options.snap){
			this.cancel();
			this.document.addEvents({
				mousemove: this.bound.drag,
				mouseup: this.bound.stop
			});
			this.fireEvent('start', [this.element, event]).fireEvent('snap', this.element);
		}
	},

	drag: function(event){
		if (this.options.preventDefault) event.preventDefault();
		this.mouse.now = event.page;
		for (var z in this.options.modifiers){
			if (!this.options.modifiers[z]) continue;
			this.value.now[z] = this.mouse.now[z] - this.mouse.pos[z];
			if (this.options.invert) this.value.now[z] *= -1;
			if (this._invert[z]) this.value.now[z] *= -1;
			if (this.options.limit && this.limit[z]){
				if ($chk(this.limit[z][1]) && (this.value.now[z] > this.limit[z][1])){
					this.value.now[z] = this.limit[z][1];
				} else if ($chk(this.limit[z][0]) && (this.value.now[z] < this.limit[z][0])){
					this.value.now[z] = this.limit[z][0];
				}
			}
			if (this.options.grid[z]) this.value.now[z] -= ((this.value.now[z] - (this.limit[z][0]||0)) % this.options.grid[z]);
			if (this.options.style) {
				this.element.setStyle(this.options.modifiers[z], this.value.now[z] + this.options.unit);
			} else {
				this.element[this.options.modifiers[z]] = this.value.now[z];
			}
		}
		this.fireEvent('drag', [this.element, event]);
	},

	cancel: function(event){
		this.document.removeEvent('mousemove', this.bound.check);
		this.document.removeEvent('mouseup', this.bound.cancel);
		if (event){
			this.document.removeEvent(this.selection, this.bound.eventStop);
			this.fireEvent('cancel', this.element);
		}
	},

	stop: function(event){
		this.document.removeEvent(this.selection, this.bound.eventStop);
		this.document.removeEvent('mousemove', this.bound.drag);
		this.document.removeEvent('mouseup', this.bound.stop);
		if (event) this.fireEvent('complete', [this.element, event]);
	}

});

Element.implement({

	makeResizable: function(options){
		var drag = new Drag(this, $merge({modifiers: {x: 'width', y: 'height'}}, options));
		this.store('resizer', drag);
		return drag.addEvent('drag', function(){
			this.fireEvent('resize', drag);
		}.bind(this));
	}

});


/*
---

script: Drag.Move.js

name: Drag.Move

description: A Drag extension that provides support for the constraining of draggables to containers and droppables.

license: MIT-style license

authors:
  - Valerio Proietti
  - Tom Occhinno
  - Jan Kassens
  - Aaron Newton
  - Scott Kyle

requires:
  - Core/Element.Dimensions
  - /Drag

provides: [Drag.Move]

...
*/

Drag.Move = new Class({

	Extends: Drag,

	options: {/*
		onEnter: $empty(thisElement, overed),
		onLeave: $empty(thisElement, overed),
		onDrop: $empty(thisElement, overed, event),*/
		droppables: [],
		container: false,
		precalculate: false,
		includeMargins: true,
		checkDroppables: true
	},

	initialize: function(element, options){
		this.parent(element, options);
		element = this.element;
		
		this.droppables = $$(this.options.droppables);
		this.container = document.id(this.options.container);
		
		if (this.container && $type(this.container) != 'element')
			this.container = document.id(this.container.getDocument().body);

		if (this.options.style){
			if (this.options.modifiers.x == "left" && this.options.modifiers.y == "top"){
				var parentStyles,
					parent = document.id(element.getOffsetParent());
				if (parent) parentStyles = parent.getStyles('border-top-width', 'border-left-width');

				var styles = element.getStyles('left', 'top');
				if (parent && (styles.left == 'auto' || styles.top == 'auto')){
					var parentPosition = element.getPosition(parent);
					parentPosition.x = parentPosition.x - (parentStyles['border-left-width'] ? parentStyles['border-left-width'].toInt() : 0);
					parentPosition.y = parentPosition.y - (parentStyles['border-top-width'] ? parentStyles['border-top-width'].toInt() : 0);
					element.setPosition(parentPosition);
				}
			}
			if (element.getStyle('position') == 'static') element.setStyle('position', 'absolute');
		}

		this.addEvent('start', this.checkDroppables, true);

		this.overed = null;
	},

	start: function(event){
		if (this.container) this.options.limit = this.calculateLimit();
		
		if (this.options.precalculate){
			this.positions = this.droppables.map(function(el){
				return el.getCoordinates();
			});
		}
		
		this.parent(event);
	},
	
	calculateLimit: function(){
		var offsetParent = document.id(this.element.getOffsetParent()) || document.body,
			containerCoordinates = this.container.getCoordinates(offsetParent),
			containerBorder = {},
			elementMargin = {},
			elementBorder = {},
			containerMargin = {},
			offsetParentBorder = {},
			offsetParentPadding = {};

		['top', 'right', 'bottom', 'left'].each(function(pad){
			containerBorder[pad] = this.container.getStyle('border-' + pad).toInt();
			elementBorder[pad] = this.element.getStyle('border-' + pad).toInt();
			elementMargin[pad] = this.element.getStyle('margin-' + pad).toInt();
			containerMargin[pad] = this.container.getStyle('margin-' + pad).toInt();
			offsetParentPadding[pad] = offsetParent.getStyle('padding-' + pad).toInt();
			offsetParentBorder[pad] = offsetParent.getStyle('border-' + pad).toInt();
		}, this);

		var width = this.element.offsetWidth + elementMargin.left + elementMargin.right,
			height = this.element.offsetHeight + elementMargin.top + elementMargin.bottom,
			left = 0,
			top = 0,
			right = containerCoordinates.right - containerBorder.right - width,
			bottom = containerCoordinates.bottom - containerBorder.bottom - height;

		if (this.options.includeMargins){
			left += elementMargin.left;
			top += elementMargin.top;
		} else {
			right += elementMargin.right;
			bottom += elementMargin.bottom;
		}
		
		if (this.element.getStyle('position') == 'relative'){
			var coords = this.element.getCoordinates(offsetParent);
			coords.left -= this.element.getStyle('left').toInt();
			coords.top -= this.element.getStyle('top').toInt();
			
			left += containerBorder.left - coords.left;
			top += containerBorder.top - coords.top;
			right += elementMargin.left - coords.left;
			bottom += elementMargin.top - coords.top;
			
			if (this.container != offsetParent){
				left += containerMargin.left + offsetParentPadding.left;
				top += (Browser.Engine.trident4 ? 0 : containerMargin.top) + offsetParentPadding.top;
			}
		} else {
			left -= elementMargin.left;
			top -= elementMargin.top;
			if (this.container == offsetParent){
				right -= containerBorder.left;
				bottom -= containerBorder.top;
			} else {
				left += containerCoordinates.left + containerBorder.left - offsetParentBorder.left;
				top += containerCoordinates.top + containerBorder.top - offsetParentBorder.top;
				right -= offsetParentBorder.left;
				bottom -= offsetParentBorder.top;
			}
		}
		
		return {
			x: [left, right],
			y: [top, bottom]
		};
	},

	checkAgainst: function(el, i){
		el = (this.positions) ? this.positions[i] : el.getCoordinates();
		var now = this.mouse.now;
		return (now.x > el.left && now.x < el.right && now.y < el.bottom && now.y > el.top);
	},

	checkDroppables: function(){
		var overed = this.droppables.filter(this.checkAgainst, this).getLast();
		if (this.overed != overed){
			if (this.overed) this.fireEvent('leave', [this.element, this.overed]);
			if (overed) this.fireEvent('enter', [this.element, overed]);
			this.overed = overed;
		}
	},

	drag: function(event){
		this.parent(event);
		if (this.options.checkDroppables && this.droppables.length) this.checkDroppables();
	},

	stop: function(event){
		this.checkDroppables();
		this.fireEvent('drop', [this.element, this.overed, event]);
		this.overed = null;
		return this.parent(event);
	}

});

Element.implement({

	makeDraggable: function(options){
		var drag = new Drag.Move(this, options);
		this.store('dragger', drag);
		return drag;
	}

});


/*
---

script: Slider.js

name: Slider

description: Class for creating horizontal and vertical slider controls.

license: MIT-style license

authors:
  - Valerio Proietti

requires:
  - Core/Element.Dimensions
  - /Class.Binds
  - /Drag
  - /Element.Measure

provides: [Slider]

...
*/

var Slider = new Class({

	Implements: [Events, Options],

	Binds: ['clickedElement', 'draggedKnob', 'scrolledElement'],

	options: {/*
		onTick: $empty(intPosition),
		onChange: $empty(intStep),
		onComplete: $empty(strStep),*/
		onTick: function(position){
			if (this.options.snap) position = this.toPosition(this.step);
			this.knob.setStyle(this.property, position);
		},
		initialStep: 0,
		snap: false,
		offset: 0,
		range: false,
		wheel: false,
		steps: 100,
		mode: 'horizontal'
	},

	initialize: function(element, knob, options){
		this.setOptions(options);
		this.element = document.id(element);
		this.knob = document.id(knob);
		this.previousChange = this.previousEnd = this.step = -1;
		var offset, limit = {}, modifiers = {'x': false, 'y': false};
		switch (this.options.mode){
			case 'vertical':
				this.axis = 'y';
				this.property = 'top';
				offset = 'offsetHeight';
				break;
			case 'horizontal':
				this.axis = 'x';
				this.property = 'left';
				offset = 'offsetWidth';
		}
		
		this.full = this.element.measure(function(){ 
			this.half = this.knob[offset] / 2; 
			return this.element[offset] - this.knob[offset] + (this.options.offset * 2); 
		}.bind(this));
		
		this.setRange(this.options.range);

		this.knob.setStyle('position', 'relative').setStyle(this.property, - this.options.offset);
		modifiers[this.axis] = this.property;
		limit[this.axis] = [- this.options.offset, this.full - this.options.offset];

		var dragOptions = {
			snap: 0,
			limit: limit,
			modifiers: modifiers,
			onDrag: this.draggedKnob,
			onStart: this.draggedKnob,
			onBeforeStart: (function(){
				this.isDragging = true;
			}).bind(this),
			onCancel: function() {
				this.isDragging = false;
			}.bind(this),
			onComplete: function(){
				this.isDragging = false;
				this.draggedKnob();
				this.end();
			}.bind(this)
		};
		if (this.options.snap){
			dragOptions.grid = Math.ceil(this.stepWidth);
			dragOptions.limit[this.axis][1] = this.full;
		}

		this.drag = new Drag(this.knob, dragOptions);
		this.attach();
		if (this.options.initialStep != null) this.set(this.options.initialStep)
	},

	attach: function(){
		this.element.addEvent('mousedown', this.clickedElement);
		if (this.options.wheel) this.element.addEvent('mousewheel', this.scrolledElement);
		this.drag.attach();
		return this;
	},

	detach: function(){
		this.element.removeEvent('mousedown', this.clickedElement);
		this.element.removeEvent('mousewheel', this.scrolledElement);
		this.drag.detach();
		return this;
	},

	set: function(step){
		if (!((this.range > 0) ^ (step < this.min))) step = this.min;
		if (!((this.range > 0) ^ (step > this.max))) step = this.max;

		this.step = Math.round(step);
		this.checkStep();
		this.fireEvent('tick', this.toPosition(this.step));
		this.end();
		return this;
	},
	
	setRange: function(range, pos){
		this.min = $pick(range[0], 0);
		this.max = $pick(range[1], this.options.steps);
		this.range = this.max - this.min;
		this.steps = this.options.steps || this.full;
		this.stepSize = Math.abs(this.range) / this.steps;
		this.stepWidth = this.stepSize * this.full / Math.abs(this.range);
		this.set($pick(pos, this.step).floor(this.min).max(this.max));
		return this;
	},

	clickedElement: function(event){
		if (this.isDragging || event.target == this.knob) return;

		var dir = this.range < 0 ? -1 : 1;
		var position = event.page[this.axis] - this.element.getPosition()[this.axis] - this.half;
		position = position.limit(-this.options.offset, this.full -this.options.offset);

		this.step = Math.round(this.min + dir * this.toStep(position));
		this.checkStep();
		this.fireEvent('tick', position);
		this.end();
	},

	scrolledElement: function(event){
		var mode = (this.options.mode == 'horizontal') ? (event.wheel < 0) : (event.wheel > 0);
		this.set(mode ? this.step - this.stepSize : this.step + this.stepSize);
		event.stop();
	},

	draggedKnob: function(){
		var dir = this.range < 0 ? -1 : 1;
		var position = this.drag.value.now[this.axis];
		position = position.limit(-this.options.offset, this.full -this.options.offset);
		this.step = Math.round(this.min + dir * this.toStep(position));
		this.checkStep();
	},

	checkStep: function(){
		if (this.previousChange != this.step){
			this.previousChange = this.step;
			this.fireEvent('change', this.step);
		}
	},

	end: function(){
		if (this.previousEnd !== this.step){
			this.previousEnd = this.step;
			this.fireEvent('complete', this.step + '');
		}
	},

	toStep: function(position){
		var step = (position + this.options.offset) * this.stepSize / this.full * this.steps;
		return this.options.steps ? Math.round(step -= step % this.stepSize) : step;
	},

	toPosition: function(step){
		return (this.full * Math.abs(this.min - step)) / (this.steps * this.stepSize) - this.options.offset;
	}

});


/*
---

script: Sortables.js

name: Sortables

description: Class for creating a drag and drop sorting interface for lists of items.

license: MIT-style license

authors:
  - Tom Occhino

requires:
  - /Drag.Move

provides: [Sortables]

...
*/

var Sortables = new Class({

	Implements: [Events, Options],

	options: {/*
		onSort: $empty(element, clone),
		onStart: $empty(element, clone),
		onComplete: $empty(element),*/
		snap: 4,
		opacity: 1,
		clone: false,
		revert: false,
		handle: false,
		constrain: false,
		preventDefault: false
	},

	initialize: function(lists, options){
		this.setOptions(options);
		this.elements = [];
		this.lists = [];
		this.idle = true;

		this.addLists($$(document.id(lists) || lists));
		if (!this.options.clone) this.options.revert = false;
		if (this.options.revert) this.effect = new Fx.Morph(null, $merge({duration: 250, link: 'cancel'}, this.options.revert));
	},

	attach: function(){
		this.addLists(this.lists);
		return this;
	},

	detach: function(){
		this.lists = this.removeLists(this.lists);
		return this;
	},

	addItems: function(){
		Array.flatten(arguments).each(function(element){
			this.elements.push(element);
			var start = element.retrieve('sortables:start', this.start.bindWithEvent(this, element));
			(this.options.handle ? element.getElement(this.options.handle) || element : element).addEvent('mousedown', start);
		}, this);
		return this;
	},

	addLists: function(){
		Array.flatten(arguments).each(function(list){
			this.lists.push(list);
			this.addItems(list.getChildren());
		}, this);
		return this;
	},

	removeItems: function(){
		return $$(Array.flatten(arguments).map(function(element){
			this.elements.erase(element);
			var start = element.retrieve('sortables:start');
			(this.options.handle ? element.getElement(this.options.handle) || element : element).removeEvent('mousedown', start);
			
			return element;
		}, this));
	},

	removeLists: function(){
		return $$(Array.flatten(arguments).map(function(list){
			this.lists.erase(list);
			this.removeItems(list.getChildren());
			
			return list;
		}, this));
	},

	getClone: function(event, element){
		if (!this.options.clone) return new Element(element.tagName).inject(document.body);
		if ($type(this.options.clone) == 'function') return this.options.clone.call(this, event, element, this.list);
		var clone = element.clone(true).setStyles({
			margin: '0px',
			position: 'absolute',
			visibility: 'hidden',
			'width': element.getStyle('width')
		});
		//prevent the duplicated radio inputs from unchecking the real one
		if (clone.get('html').test('radio')) {
			clone.getElements('input[type=radio]').each(function(input, i) {
				input.set('name', 'clone_' + i);
				if (input.get('checked')) element.getElements('input[type=radio]')[i].set('checked', true);
			});
		}
		
		return clone.inject(this.list).setPosition(element.getPosition(element.getOffsetParent()));
	},

	getDroppables: function(){
		var droppables = this.list.getChildren();
		if (!this.options.constrain) droppables = this.lists.concat(droppables).erase(this.list);
		return droppables.erase(this.clone).erase(this.element);
	},

	insert: function(dragging, element){
		var where = 'inside';
		if (this.lists.contains(element)){
			this.list = element;
			this.drag.droppables = this.getDroppables();
		} else {
			where = this.element.getAllPrevious().contains(element) ? 'before' : 'after';
		}
		this.element.inject(element, where);
		this.fireEvent('sort', [this.element, this.clone]);
	},

	start: function(event, element){
		if (
			!this.idle ||
			event.rightClick ||
			['button', 'input'].contains(document.id(event.target).get('tag'))
		) return;

		this.idle = false;
		this.element = element;
		this.opacity = element.get('opacity');
		this.list = element.getParent();
		this.clone = this.getClone(event, element);

		this.drag = new Drag.Move(this.clone, {
			preventDefault: this.options.preventDefault,
			snap: this.options.snap,
			container: this.options.constrain && this.element.getParent(),
			droppables: this.getDroppables(),
			onSnap: function(){
				event.stop();
				this.clone.setStyle('visibility', 'visible');
				this.element.set('opacity', this.options.opacity || 0);
				this.fireEvent('start', [this.element, this.clone]);
			}.bind(this),
			onEnter: this.insert.bind(this),
			onCancel: this.reset.bind(this),
			onComplete: this.end.bind(this)
		});

		this.clone.inject(this.element, 'before');
		this.drag.start(event);
	},

	end: function(){
		this.drag.detach();
		this.element.set('opacity', this.opacity);
		if (this.effect){
			var dim = this.element.getStyles('width', 'height');
			var pos = this.clone.computePosition(this.element.getPosition(this.clone.getOffsetParent()));
			this.effect.element = this.clone;
			this.effect.start({
				top: pos.top,
				left: pos.left,
				width: dim.width,
				height: dim.height,
				opacity: 0.25
			}).chain(this.reset.bind(this));
		} else {
			this.reset();
		}
	},

	reset: function(){
		this.idle = true;
		this.clone.destroy();
		this.fireEvent('complete', this.element);
	},

	serialize: function(){
		var params = Array.link(arguments, {modifier: Function.type, index: $defined});
		var serial = this.lists.map(function(list){
			return list.getChildren().map(params.modifier || function(element){
				return element.get('id');
			}, this);
		}, this);

		var index = params.index;
		if (this.lists.length == 1) index = 0;
		return $chk(index) && index >= 0 && index < this.lists.length ? serial[index] : serial;
	}

});


/*
---

script: IframeShim.js

name: IframeShim

description: Defines IframeShim, a class for obscuring select lists and flash objects in IE.

license: MIT-style license

authors:
  - Aaron Newton

requires:
  - Core/Element.Event
  - Core/Element.Style
  - Core/Options
  - Core/Events
  - /Element.Position
  - /Class.Occlude

provides: [IframeShim]

...
*/

var IframeShim = new Class({

	Implements: [Options, Events, Class.Occlude],

	options: {
		className: 'iframeShim',
		src: 'javascript:false;document.write("");',
		display: false,
		zIndex: null,
		margin: 0,
		offset: {x: 0, y: 0},
		browsers: (Browser.Engine.trident4 || (Browser.Engine.gecko && !Browser.Engine.gecko19 && Browser.Platform.mac))
	},

	property: 'IframeShim',

	initialize: function(element, options){
		this.element = document.id(element);
		if (this.occlude()) return this.occluded;
		this.setOptions(options);
		this.makeShim();
		return this;
	},

	makeShim: function(){
		if(this.options.browsers){
			var zIndex = this.element.getStyle('zIndex').toInt();

			if (!zIndex){
				zIndex = 1;
				var pos = this.element.getStyle('position');
				if (pos == 'static' || !pos) this.element.setStyle('position', 'relative');
				this.element.setStyle('zIndex', zIndex);
			}
			zIndex = ($chk(this.options.zIndex) && zIndex > this.options.zIndex) ? this.options.zIndex : zIndex - 1;
			if (zIndex < 0) zIndex = 1;
			this.shim = new Element('iframe', {
				src: this.options.src,
				scrolling: 'no',
				frameborder: 0,
				styles: {
					zIndex: zIndex,
					position: 'absolute',
					border: 'none',
					filter: 'progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)'
				},
				'class': this.options.className
			}).store('IframeShim', this);
			var inject = (function(){
				this.shim.inject(this.element, 'after');
				this[this.options.display ? 'show' : 'hide']();
				this.fireEvent('inject');
			}).bind(this);
			if (!IframeShim.ready) window.addEvent('load', inject);
			else inject();
		} else {
			this.position = this.hide = this.show = this.dispose = $lambda(this);
		}
	},

	position: function(){
		if (!IframeShim.ready || !this.shim) return this;
		var size = this.element.measure(function(){ 
			return this.getSize(); 
		});
		if (this.options.margin != undefined){
			size.x = size.x - (this.options.margin * 2);
			size.y = size.y - (this.options.margin * 2);
			this.options.offset.x += this.options.margin;
			this.options.offset.y += this.options.margin;
		}
		this.shim.set({width: size.x, height: size.y}).position({
			relativeTo: this.element,
			offset: this.options.offset
		});
		return this;
	},

	hide: function(){
		if (this.shim) this.shim.setStyle('display', 'none');
		return this;
	},

	show: function(){
		if (this.shim) this.shim.setStyle('display', 'block');
		return this.position();
	},

	dispose: function(){
		if (this.shim) this.shim.dispose();
		return this;
	},

	destroy: function(){
		if (this.shim) this.shim.destroy();
		return this;
	}

});

window.addEvent('load', function(){
	IframeShim.ready = true;
});


/*
---

script: Keyboard.js

name: Keyboard

description: KeyboardEvents used to intercept events on a class for keyboard and format modifiers in a specific order so as to make alt+shift+c the same as shift+alt+c.

license: MIT-style license

authors:
  - Perrin Westrich
  - Aaron Newton
  - Scott Kyle

requires:
  - Core/Events
  - Core/Options
  - Core/Element.Event
  - /Log

provides: [Keyboard]

...
*/

(function(){
	
	var Keyboard = this.Keyboard = new Class({

		Extends: Events,

		Implements: [Options, Log],

		options: {
			/*
			onActivate: $empty,
			onDeactivate: $empty,
			*/
			defaultEventType: 'keydown',
			active: false,
			manager: null,
			events: {},
			nonParsedEvents: ['activate', 'deactivate', 'onactivate', 'ondeactivate', 'changed', 'onchanged']
		},

		initialize: function(options){
			if (options && options.manager) {
				this.manager = options.manager;
				delete options.manager;
			}
			this.setOptions(options);
			this.setup();
		}, 
		setup: function(){
			this.addEvents(this.options.events);
			//if this is the root manager, nothing manages it
			if (Keyboard.manager && !this.manager) Keyboard.manager.manage(this);
			if (this.options.active) this.activate();
		},

		handle: function(event, type){
			//Keyboard.stop(event) prevents key propagation
			if (event.preventKeyboardPropagation) return;
			
			var bubbles = !!this.manager;
			if (bubbles && this.activeKB){
				this.activeKB.handle(event, type);
				if (event.preventKeyboardPropagation) return;
			}
			this.fireEvent(type, event);
			
			if (!bubbles && this.activeKB) this.activeKB.handle(event, type);
		},

		addEvent: function(type, fn, internal){
			return this.parent(Keyboard.parse(type, this.options.defaultEventType, this.options.nonParsedEvents), fn, internal);
		},

		removeEvent: function(type, fn){
			return this.parent(Keyboard.parse(type, this.options.defaultEventType, this.options.nonParsedEvents), fn);
		},

		toggleActive: function(){
			return this[this.active ? 'deactivate' : 'activate']();
		},

		activate: function(instance){
			if (instance) {
				if (instance.isActive()) return this;
				//if we're stealing focus, store the last keyboard to have it so the relinquish command works
				if (this.activeKB && instance != this.activeKB) {
					this.previous = this.activeKB;
					this.previous.fireEvent('deactivate');
				}
				//if we're enabling a child, assign it so that events are now passed to it
				this.activeKB = instance.fireEvent('activate');
				Keyboard.manager.fireEvent('changed');
			} else if (this.manager) {
				//else we're enabling ourselves, we must ask our parent to do it for us
				this.manager.activate(this);
			}
			return this;
		},

		isActive: function(){
			return this.manager ? this.manager.activeKB == this :  Keyboard.manager == this;
		},

		deactivate: function(instance){
			if (instance) {
				if(instance === this.activeKB) {
					this.activeKB = null;
					instance.fireEvent('deactivate');
					Keyboard.manager.fireEvent('changed');
				}
			} else if (this.manager) {
				this.manager.deactivate(this);
			}
			return this;
		},

		relinquish: function(){
			if (this.isActive() && this.manager && this.manager.previous) this.manager.activate(this.manager.previous);
		},

		//management logic
		manage: function(instance){
			if (instance.manager && instance.manager != Keyboard.manager && this != Keyboard.manager) instance.manager.drop(instance);
			this.instances.push(instance);
			instance.manager = this;
			if (!this.activeKB) this.activate(instance);
		},

		_disable: function(instance){
			if (this.activeKB == instance) this.activeKB = null;
		},

		drop: function(instance){
			this._disable(instance);
			this.instances.erase(instance);
			Keyboard.manager.manage(instance);
			if (this.activeKB == instance && this.previous && this.instances.contains(this.previous)) this.activate(this.previous);
		},

		instances: [],

		trace: function(){
			Keyboard.trace(this);
		},

		each: function(fn){
			Keyboard.each(this, fn);
		}

	});
	
	var parsed = {};
	var modifiers = ['shift', 'control', 'alt', 'meta'];
	var regex = /^(?:shift|control|ctrl|alt|meta)$/;
	
	Keyboard.parse = function(type, eventType, ignore){
		if (ignore && ignore.contains(type.toLowerCase())) return type;
		
		type = type.toLowerCase().replace(/^(keyup|keydown):/, function($0, $1){
			eventType = $1;
			return '';
		});

		if (!parsed[type]){
			var key, mods = {};
			type.split('+').each(function(part){
				if (regex.test(part)) mods[part] = true;
				else key = part;
			});

			mods.control = mods.control || mods.ctrl; // allow both control and ctrl
			
			var keys = [];
			modifiers.each(function(mod){
				if (mods[mod]) keys.push(mod);
			});
			
			if (key) keys.push(key);
			parsed[type] = keys.join('+');
		}

		return eventType + ':' + parsed[type];
	};

	Keyboard.each = function(keyboard, fn){
		var current = keyboard || Keyboard.manager;
		while (current){
			fn.run(current);
			current = current.activeKB;
		}
	};

	Keyboard.stop = function(event){
		event.preventKeyboardPropagation = true;
	};

	Keyboard.manager = new Keyboard({
		active: true
	});
	
	Keyboard.trace = function(keyboard){
		keyboard = keyboard || Keyboard.manager;
		keyboard.enableLog();
		keyboard.log('the following items have focus: ');
		Keyboard.each(keyboard, function(current){
			keyboard.log(document.id(current.widget) || current.wiget || current);
		});
	};
	
	var handler = function(event){
		var keys = [];
		modifiers.each(function(mod){
			if (event[mod]) keys.push(mod);
		});
		
		if (!regex.test(event.key)) keys.push(event.key);
		Keyboard.manager.handle(event, event.type + ':' + keys.join('+'));
	};
	
	document.addEvents({
		'keyup': handler,
		'keydown': handler
	});

	Event.Keys.extend({
		'shift': 16,
		'control': 17,
		'alt': 18,
		'capslock': 20,
		'pageup': 33,
		'pagedown': 34,
		'end': 35,
		'home': 36,
		'numlock': 144,
		'scrolllock': 145,
		';': 186,
		'=': 187,
		',': 188,
		'-': Browser.Engine.gecko ? 109 : 189,
		'.': 190,
		'/': 191,
		'`': 192,
		'[': 219,
		'\\': 220,
		']': 221,
		"'": 222
	});

})();


/*
---

script: Keyboard.Extras.js

name: Keyboard.Extras

description: Enhances Keyboard by adding the ability to name and describe keyboard shortcuts, and the ability to grab shortcuts by name and bind the shortcut to different keys.

license: MIT-style license

authors:
  - Perrin Westrich

requires:
  - /Keyboard
  - /MooTools.More

provides: [Keyboard.Extras]

...
*/
Keyboard.prototype.options.nonParsedEvents.combine(['rebound', 'onrebound']);

Keyboard.implement({

	/*
		shortcut should be in the format of:
		{
			'keys': 'shift+s', // the default to add as an event.
			'description': 'blah blah blah', // a brief description of the functionality.
			'handler': function(){} // the event handler to run when keys are pressed.
		}
	*/
	addShortcut: function(name, shortcut) {
		this.shortcuts = this.shortcuts || [];
		this.shortcutIndex = this.shortcutIndex || {};
		
		shortcut.getKeyboard = $lambda(this);
		shortcut.name = name;
		this.shortcutIndex[name] = shortcut;
		this.shortcuts.push(shortcut);
		if(shortcut.keys) this.addEvent(shortcut.keys, shortcut.handler);
		return this;
	},

	addShortcuts: function(obj){
		for(var name in obj) this.addShortcut(name, obj[name]);
		return this;
	},

	removeShortcut: function(name) {
		var shortcut = this.getShortcut(name);
		if (shortcut && shortcut.keys) {
			this.removeEvent(shortcut.keys, shortcut.handler);
			delete this.shortcutIndex[name];
			this.shortcuts.erase(shortcut);
		}
		return this;
	},

	removeShortcuts: function(names) {
		names.each(this.removeShortcut, this);
		return this;
	},

	getShortcuts: function(){
		return this.shortcuts || [];
	},

	getShortcut: function(name){
		return (this.shortcutIndex || {})[name];
	}

});

Keyboard.rebind = function(newKeys, shortcuts){
	$splat(shortcuts).each(function(shortcut){
		shortcut.getKeyboard().removeEvent(shortcut.keys, shortcut.handler);
		shortcut.getKeyboard().addEvent(newKeys, shortcut.handler);
		shortcut.keys = newKeys;
		shortcut.getKeyboard().fireEvent('rebound');
	});
};


Keyboard.getActiveShortcuts = function(keyboard) {
	var activeKBS = [], activeSCS = [];
	Keyboard.each(keyboard, [].push.bind(activeKBS));
	activeKBS.each(function(kb){ activeSCS.extend(kb.getShortcuts()); });
	return activeSCS;
};

Keyboard.getShortcut = function(name, keyboard, opts){
	opts = opts || {};
	var shortcuts = opts.many ? [] : null,
		set = opts.many ? function(kb){
				var shortcut = kb.getShortcut(name);
				if(shortcut) shortcuts.push(shortcut);
			} : function(kb) { 
				if(!shortcuts) shortcuts = kb.getShortcut(name);
			};
	Keyboard.each(keyboard, set);
	return shortcuts;
};

Keyboard.getShortcuts = function(name, keyboard) {
	return Keyboard.getShortcut(name, keyboard, { many: true });
};


/*
---

script: Tips.js

name: Tips

description: Class for creating nice tips that follow the mouse cursor when hovering an element.

license: MIT-style license

authors:
  - Valerio Proietti
  - Christoph Pojer

requires:
  - Core/Options
  - Core/Events
  - Core/Element.Event
  - Core/Element.Style
  - Core/Element.Dimensions
  - /MooTools.More

provides: [Tips]

...
*/

(function(){

var read = function(option, element){
	return (option) ? ($type(option) == 'function' ? option(element) : element.get(option)) : '';
};

this.Tips = new Class({

	Implements: [Events, Options],

	options: {
		/*
		onAttach: $empty(element),
		onDetach: $empty(element),
		*/
		onShow: function(){
			this.tip.setStyle('display', 'block');
		},
		onHide: function(){
			this.tip.setStyle('display', 'none');
		},
		title: 'title',
		text: function(element){
			return element.get('rel') || element.get('href');
		},
		showDelay: 100,
		hideDelay: 100,
		className: 'tip-wrap',
		offset: {x: 16, y: 16},
		windowPadding: {x:0, y:0},
		fixed: false
	},

	initialize: function(){
		var params = Array.link(arguments, {options: Object.type, elements: $defined});
		this.setOptions(params.options);
		if (params.elements) this.attach(params.elements);
		this.container = new Element('div', {'class': 'tip'});
	},

	toElement: function(){
		if (this.tip) return this.tip;

		return this.tip = new Element('div', {
			'class': this.options.className,
			styles: {
				position: 'absolute',
				top: 0,
				left: 0
			}
		}).adopt(
			new Element('div', {'class': 'tip-top'}),
			this.container,
			new Element('div', {'class': 'tip-bottom'})
		);
	},

	attach: function(elements){
		$$(elements).each(function(element){
			var title = read(this.options.title, element),
				text = read(this.options.text, element);
			
			element.erase('title').store('tip:native', title).retrieve('tip:title', title);
			element.retrieve('tip:text', text);
			this.fireEvent('attach', [element]);
			
			var events = ['enter', 'leave'];
			if (!this.options.fixed) events.push('move');
			
			events.each(function(value){
				var event = element.retrieve('tip:' + value);
				if (!event) event = this['element' + value.capitalize()].bindWithEvent(this, element);
				
				element.store('tip:' + value, event).addEvent('mouse' + value, event);
			}, this);
		}, this);
		
		return this;
	},

	detach: function(elements){
		$$(elements).each(function(element){
			['enter', 'leave', 'move'].each(function(value){
				element.removeEvent('mouse' + value, element.retrieve('tip:' + value)).eliminate('tip:' + value);
			});
			
			this.fireEvent('detach', [element]);
			
			if (this.options.title == 'title'){ // This is necessary to check if we can revert the title
				var original = element.retrieve('tip:native');
				if (original) element.set('title', original);
			}
		}, this);
		
		return this;
	},

	elementEnter: function(event, element){
		this.container.empty();
		
		['title', 'text'].each(function(value){
			var content = element.retrieve('tip:' + value);
			if (content) this.fill(new Element('div', {'class': 'tip-' + value}).inject(this.container), content);
		}, this);
		
		$clear(this.timer);
		this.timer = (function(){
			this.show(element);
			this.position((this.options.fixed) ? {page: element.getPosition()} : event);
		}).delay(this.options.showDelay, this);
	},

	elementLeave: function(event, element){
		$clear(this.timer);
		this.timer = this.hide.delay(this.options.hideDelay, this, element);
		this.fireForParent(event, element);
	},

	fireForParent: function(event, element){
		element = element.getParent();
		if (!element || element == document.body) return;
		if (element.retrieve('tip:enter')) element.fireEvent('mouseenter', event);
		else this.fireForParent(event, element);
	},

	elementMove: function(event, element){
		this.position(event);
	},

	position: function(event){
		if (!this.tip) document.id(this);

		var size = window.getSize(), scroll = window.getScroll(),
			tip = {x: this.tip.offsetWidth, y: this.tip.offsetHeight},
			props = {x: 'left', y: 'top'},
			obj = {};
		
		for (var z in props){
			obj[props[z]] = event.page[z] + this.options.offset[z];
			if ((obj[props[z]] + tip[z] - scroll[z]) > size[z] - this.options.windowPadding[z]) obj[props[z]] = event.page[z] - this.options.offset[z] - tip[z];
		}
		
		this.tip.setStyles(obj);
	},

	fill: function(element, contents){
		if(typeof contents == 'string') element.set('html', contents);
		else element.adopt(contents);
	},

	show: function(element){
		if (!this.tip) document.id(this);
		if (!this.tip.getParent()) this.tip.inject(document.body);
		this.fireEvent('show', [this.tip, element]);
	},

	hide: function(element){
		if (!this.tip) document.id(this);
		this.fireEvent('hide', [this.tip, element]);
	}

});

})();


// JavaScript i18n
// 24ways.org

function _(s) {
  if (typeof(i18n)!='undefined' && i18n[window._locale][s]) {
    return i18n[window._locale][s];
  }
  return s;
}

function sprintf(s) {
  var bits = s.split('%');
  var out = bits[0];
  var re = /^([ds])(.*)$/;
  for (var i=1; i<bits.length; i++) {
    p = re.exec(bits[i]);
    if (!p || arguments[i]==null) continue;
    if (p[1] == 'd') {
      out += parseInt(arguments[i], 10);
    } else if (p[1] == 's') {
      out += arguments[i];
    }
    out += p[2];
  }
  return out;
}

function pretty_num(n) {
  n += '';
  var o = '';
  for (i=n.length; i>3; i-=3) {
    o = i18n.thousands_sep + n.slice(i-3, i) + o;
  }
  o = n.slice(0, i) + o;
  return o;
}

function pluralise(s, p, n) {
  if (n != 1) return _(p);
  return _(s);
}

// French translation file
var i18n = {
  fr: {
    thousands_sep: ' ',
	
	'en' : 'fr',
	'Comments':'Commentaires',
	
    'Send': 'Envoyer',
    'Reply': 'R&eacute;pondre',
    'Cancel': 'Annuler',
		'Please enter some text': 'Vous ne pouvez pas envoyer un commentaire vide',
		'Hide all': 'Tout cacher',
		'Show all': 'Tout afficher',
    
    'See ticket': 'Voir la note',
	'Archive': 'Archiver',
	'Unarchive': 'Désarchiver',
	"New Version": "Nouvelle Version",
	"No": "Non",
	"Download": "Télécharger",
	"Deleted":"Supprimé",
	"Name":"Nom",
	"Date":"Date",
	"Validated on":"Validé le",
    
    'less than a minute ago': 'il y a moins d\'une minute',
    'a minute ago': 'il y a une minute',
    '%s minutes ago': 'il y a %s minutes',
    'about 1 hour ago': 'il y a environ une heure',
    'about %s hours ago': 'il y a environ %s heures',
    '1 day ago': 'il y a 1 jour',
    '%s days ago': 'il y a %s jours',
    'about 1 month ago': 'il y a environ 1 mois',
    '%s months ago': 'il y a %s mois',
    'about 1 year ago': 'il y a environ 1 an',
    'over %s years ago': "il y a plus de %s ans",
    'now': "maintenant",

	"Just double click on the picture below to leave comments!" : "Double cliquez sur l'image pour laisser des commentaires !",

		'/img/en/btn-remove-customer_en.png': '/img/fr/btn-remove-customer_fr.png',
		'/img/en/btn-remove-file_en.png': '/img/fr/btn-remove-file_fr.png',
		'/img/en/just-click_en.png': '/img/fr/just-click_fr.png',
		'/img/en/btn-validate_en.png':'/img/fr/btn-validate_fr.png',
		'/img/en/btn-sendmessage_en.png':'/img/fr/btn-sendmessage_fr.png',
		
		"Setup your agency and ": "Cr&eacute;ez votre agence et ", 
		
		"warning-pdf": "Nous ne supportons pas encore les PDF multi-pages, seule la première page sera utilisée.",
		
		"Loading files":"Chargement des fichiers",
		"Send this comment":"Envoyer ce commentaire",
		"Cannot submit form": "Il y a des erreurs dans votre formulaire, merci de les corriger avant de l'envoyer.",
		"Double click to leave a note": "Double cliquez n'importe où sur cette image pour laisser un commentaire !"
	},
	
	en: {
	  "warning-pdf": "As we do not support multi-page PDF yet, only the first page will be used.",
		"Cannot submit form": "There are errors in your form, please correct those before submitting.",
		"Double click to leave a note": "Double click anywhere on this picture to leave a comment!"
	}

};


// function update_text() {
  //     var hay = getValue('hay');
  //     var carrots = getValue('carrots');
  //     var bells = getValue('bells');
  //     var total = 50 * bells + 30 * hay + 10 * carrots;
  //     hay = sprintf(pluralise('%s bushel of hay', '%s bushels of hay', hay), pretty_num(hay));
  //     carrots = sprintf(pluralise('%s carrot', '%s carrots', carrots), pretty_num(carrots));
  //     bells = sprintf(pluralise('%s shiny bell', '%s shiny bells', bells), pretty_num(bells));
  //     var list = sprintf(_('%s, %s, and %s'), hay, carrots, bells);
  //     var out = sprintf(_('You are ordering %s, at a total cost of <strong>%s</strong> gold pieces.'),
  //         list, pretty_num(total));
  //     out += ' ';
  //     out += _('Thank you.');
  //     document.getElementById('preview').innerHTML = out;
  // }

  // window.onload = function() {
    //     var inputs = document.getElementsByTagName('input');
    //     for (i=0; i<inputs.length-2; i++) {
      //         inputs[i].onchange = update_text;
      //     }
      //     document.forms[0].onsubmit = function() { return false; };
      // };



/**
 * SimpleTabs - Unobtrusive Tabs with Ajax
 *
 * @example
 *
 *	var tabs = new SimpleTabs($('tab-element'), {
 * 		selector: 'h2.tab-tab'
 *	});
 *
 * @version		1.0
 *
 * @license		MIT License
 * @author		Harald Kirschner <mail [at] digitarald.de>
 * @copyright	2007 Author
 */
var SimpleTabs = new Class({

	Implements: [Events, Options],

	/**
	 * Options
	 */
	options: {
		show: 0,
		selector: '.tab-tab',
		classWrapper: 'tab-wrapper',
		classMenu: 'tab-menu',
		classContainer: 'tab-container',
		onSelect: function(toggle, container, index) {
			toggle.addClass('tab-selected active');
			container.setStyle('display', '');
			var next = toggle.getNext();
			if($chk(next)) next.addClass('next');
		},
		onDeselect: function(toggle, container, index) {
			toggle.removeClass('tab-selected active');
			container.setStyle('display', 'none');
			var next = toggle.getNext();
			if($chk(next)) next.removeClass('next');
		},
		onRequest: function(toggle, container, index) {
			container.addClass('tab-ajax-loading');
		},
		onComplete: function(toggle, container, index) {
			container.removeClass('tab-ajax-loading');
		},
		onFailure: function(toggle, container, index) {
			container.removeClass('tab-ajax-loading');
		},
		followOnClick: false,
		onAdded: Class.empty,
		getContent: null,
		ajaxOptions: {},
		cache: true
	},

	/**
	 * Constructor
	 *
	 * @param {Element} The parent Element that holds the tab elements
	 * @param {Object} Options
	 */
	initialize: function(element, options) {
		this.element = $(element);
		this.setOptions(options);
		this.selected = null;
		this.build();
	},

	build: function() {
		this.tabs = [];
		this.menu = new Element('ul', {'class': this.options.classMenu});
		this.wrapper = new Element('div', {'class': this.options.classWrapper});

		this.element.getElements(this.options.selector).each(function(el) {
			var content = el.get('href') || (this.options.getContent ? this.options.getContent.call(this, el) : el.getNext());
			this.addTab(el.innerHTML, el.title || el.innerHTML, content);
		}, this);
		this.element.empty().adopt(this.menu, this.wrapper);

		if (this.tabs.length) this.select(this.options.show);
	},

	/**
	 * Add a new tab at the end of the tab menu
	 *
	 * @param {String} inner Text
	 * @param {String} Title
	 * @param {Element|String} Content Element or URL for Ajax
	 */
	addTab: function(text, title, content) {
		var grab = $(content);
		var classes = grab.getPrevious().get('class');
		var container = (grab || new Element('div'))
			.setStyle('display', 'none')
			.addClass(this.options.classContainer)
			.inject(this.wrapper);
		var pos = this.tabs.length;
		var evt = (this.options.hover) ? 'mouseenter' : 'click';
		var tab = {
			container: container,
			toggle: new Element('li').grab(new Element('a', {
				href: '#',
				title: title
			}).grab(
				new Element('span', {html: text})
			)).addEvent(evt, this.onClick.bindWithEvent(this, [pos])).inject(this.menu)
		};
		tab.toggle.set('class', classes);
		if (!grab && $type(content) == 'string') tab.url = content;
		this.tabs.push(tab);
		return this.fireEvent('onAdded', [tab.toggle, tab.container, pos]);
	},

	onClick: function(evt, index) {
		this.select(index);
		return this.followOnClick;
	},

	/**
	 * Select the tab via tab-index
	 *
	 * @param {Number} Tab-index
	 */
	select: function(index) {
		if (this.selected === index || !this.tabs[index]) return this;
		if (this.ajax) this.ajax.cancel().removeEvents();
		var tab = this.tabs[index];
		var params = [tab.toggle, tab.container, index];
		if (this.selected !== null) {
			var current = this.tabs[this.selected];
			if (this.ajax && this.ajax.running) this.ajax.cancel();
			params.extend([current.toggle, current.container, this.selected]);
			this.fireEvent('onDeselect', [current.toggle, current.container, this.selected]);
		}
		this.fireEvent('onSelect', params);
		if (tab.url && (!tab.loaded || !this.options.cache)) {
			this.ajax = this.ajax || new Request.HTML();
			this.ajax.setOptions({
				url: tab.url,
				method: 'get',
				update: tab.container,
				onFailure: this.fireEvent.pass(['onFailure', params], this),
				onComplete: function(resp) {
					tab.loaded = true;
					this.fireEvent('onComplete', params);
				}.bind(this)
			}).setOptions(this.options.ajaxOptions);
			this.ajax.send();
			this.fireEvent('onRequest', params);
		}
		this.selected = index;
		return this;
	}

});

/**
 * Fx.ProgressBar
 *
 * @version		1.1
 *
 * @license		MIT License
 *
 * @author		Harald Kirschner <mail [at] digitarald [dot] de>
 * @copyright	Authors
 */

Fx.ProgressBar = new Class({

	Extends: Fx,

	options: {
		text: null,
		url: null,
		transition: Fx.Transitions.Circ.easeOut,
		fit: true,
		link: 'cancel'
	},

	initialize: function(element, options) {
		this.element = $(element);
		this.parent(options);
				
		var url = this.options.url;
		if (url) {
			this.element.setStyles({
				'background-image': 'url(' + url + ')',
				'background-repeat': 'no-repeat'
			});
		}
		
		if (this.options.fit) {
			url = url || this.element.getStyle('background-image').replace(/^url\(["']?|["']?\)$/g, '');
			if (url) {
				var fill = new Image();
				fill.onload = function() {
					this.fill = fill.width;
					fill = fill.onload = null;
					this.set(this.now || 0);
				}.bind(this);
				fill.src = url;
				if (!this.fill && fill.width) fill.onload();
			}
		} else {
			this.set(0);
		}
	},

	start: function(to, total) {
		return this.parent(this.now, (arguments.length == 1) ? to.limit(0, 100) : to / total * 100);
	},

	set: function(to) {
		this.now = to;
		var css = (this.fill)
			? (((this.fill / -2) + (to / 100) * (this.element.width || 1) || 0).round() + 'px')
			: ((100 - to) + '%');
		
		this.element.setStyle('backgroundPosition', css + ' 0px').title = Math.round(to) + '%';
		
		var text = $(this.options.text);
		if (text) text.set('text', Math.round(to) + '%');
		
		return this;
	}

});

/**
 * Swiff.Uploader - Flash FileReference Control
 *
 * @version		3.0
 *
 * @license		MIT License
 *
 * @author		Harald Kirschner <http://digitarald.de>
 * @author		Valerio Proietti, <http://mad4milk.net>
 * @copyright	Authors
 */

Swiff.Uploader = new Class({

	Extends: Swiff,

	Implements: Events,

	options: {
		path: 'Swiff.Uploader.swf',
		
		target: null,
		zIndex: 9999,
		
		height: 30,
		width: 100,
		callBacks: null,
		params: {
			wMode: 'opaque',
			menu: 'false',
			allowScriptAccess: 'always'
		},

		typeFilter: null,
		multiple: true,
		queued: true,
		verbose: false,

		url: null,
		method: null,
		data: null,
		mergeData: true,
		fieldName: null,

		fileSizeMin: 1,
		fileSizeMax: null, // Official limit is 100 MB for FileReference, but I tested up to 2Gb!
		allowDuplicates: false,
		timeLimit: (Browser.Platform.linux) ? 0 : 30,

		buttonImage: null,
		policyFile: null,
		
		fileListMax: 0,
		fileListSizeMax: 0,

		instantStart: false,
		appendCookieData: false,
		
		fileClass: null
		/*
		onLoad: $empty,
		onFail: $empty,
		onStart: $empty,
		onQueue: $empty,
		onComplete: $empty,
		onBrowse: $empty,
		onDisabledBrowse: $empty,
		onCancel: $empty,
		onSelect: $empty,
		onSelectSuccess: $empty,
		onSelectFail: $empty,
		
		onButtonEnter: $empty,
		onButtonLeave: $empty,
		onButtonDown: $empty,
		onButtonDisable: $empty,
		
		onFileStart: $empty,
		onFileStop: $empty,
		onFileRequeue: $empty,
		onFileOpen: $empty,
		onFileProgress: $empty,
		onFileComplete: $empty,
		onFileRemove: $empty,
		
		onBeforeStart: $empty,
		onBeforeStop: $empty,
		onBeforeRemove: $empty
		*/
	},

	initialize: function(options) {
		// protected events to control the class, added
		// before setting options (which adds own events)
		this.addEvent('load', this.initializeSwiff, true)
			.addEvent('select', this.processFiles, true)
			.addEvent('complete', this.update, true)
			.addEvent('fileRemove', function(file) {
				this.fileList.erase(file);
			}.bind(this), true);

		this.setOptions(options);

		// callbacks are no longer in the options, every callback
		// is fired as event, this is just compat
		if (this.options.callBacks) {
			Hash.each(this.options.callBacks, function(fn, name) {
				this.addEvent(name, fn);
			}, this);
		}

		this.options.callBacks = {
			fireCallback: this.fireCallback.bind(this)
		};

		var path = this.options.path;
		if (!path.contains('?')) path += '?noCache=' + $time(); // cache in IE

		// container options for Swiff class
		this.options.container = this.box = new Element('span', {'class': 'swiff-uploader-box'}).inject($(this.options.container) || document.body);

		// target 
		this.target = $(this.options.target);
		if (this.target) {
			var scroll = window.getScroll();
			this.box.setStyles({
				position: 'absolute',
				visibility: 'visible',
				zIndex: this.options.zIndex,
				overflow: 'hidden',
				height: 1, width: 1,
				top: scroll.y, left: scroll.x
			});
			
			// we force wMode to transparent for the overlay effect
			this.parent(path, {
				params: {
					wMode: 'transparent'
				},
				height: '100%',
				width: '100%'
			});
			
			this.target.addEvent('mouseenter', this.reposition.bind(this, []));
			
			// button interactions, relayed to to the target
			this.addEvents({
				buttonEnter: this.targetRelay.bind(this, ['mouseenter']),
				buttonLeave: this.targetRelay.bind(this, ['mouseleave']),
				buttonDown: this.targetRelay.bind(this, ['mousedown']),
				buttonDisable: this.targetRelay.bind(this, ['disable'])
			});
			
			this.reposition();
			window.addEvent('resize', this.reposition.bind(this, []));
		} else {
			this.parent(path);
		}

		this.inject(this.box);

		this.fileList = [];
		
		this.size = this.uploading = this.bytesLoaded = this.percentLoaded = 0;
		
		if (Browser.Plugins.Flash.version < 9) {
			this.fireEvent('fail', ['flash']);
		} else {
			this.verifyLoad.delay(1000, this);
		}
	},
	
	verifyLoad: function() {
		if (this.loaded) return;
		if (!this.object.parentNode) {
			this.fireEvent('fail', ['disabled']);
		} else if (this.object.style.display == 'none') {
			this.fireEvent('fail', ['hidden']);
		} else if (!this.object.offsetWidth) {
			this.fireEvent('fail', ['empty']);
		}
	},

	fireCallback: function(name, args) {
		// file* callbacks are relayed to the specific file
		if (name.substr(0, 4) == 'file') {
			// updated queue data is the second argument
			if (args.length > 1) this.update(args[1]);
			var data = args[0];
			
			var file = this.findFile(data.id);
			this.fireEvent(name, file || data, 5);
			if (file) {
				var fire = name.replace(/^file([A-Z])/, function($0, $1) {
					return $1.toLowerCase();
				});
				file.update(data).fireEvent(fire, [data], 10);
			}
		} else {
			this.fireEvent(name, args, 5);
		}
	},

	update: function(data) {
		// the data is saved right to the instance 
		$extend(this, data);
		this.fireEvent('queue', [this], 10);
		return this;
	},

	findFile: function(id) {
		for (var i = 0; i < this.fileList.length; i++) {
			if (this.fileList[i].id == id) return this.fileList[i];
		}
		return null;
	},

	initializeSwiff: function() {
		// extracted options for the swf 
		this.remote('initialize', {
			width: this.options.width,
			height: this.options.height,
			typeFilter: this.options.typeFilter,
			multiple: this.options.multiple,
			queued: this.options.queued,
			url: this.options.url,
			method: this.options.method,
			data: this.options.data,
			mergeData: this.options.mergeData,
			fieldName: this.options.fieldName,
			verbose: this.options.verbose,
			fileSizeMin: this.options.fileSizeMin,
			fileSizeMax: this.options.fileSizeMax,
			allowDuplicates: this.options.allowDuplicates,
			timeLimit: this.options.timeLimit,
			buttonImage: this.options.buttonImage,
			policyFile: this.options.policyFile
		});

		this.loaded = true;

		this.appendCookieData();
	},
	
	targetRelay: function(name) {
		if (this.target) this.target.fireEvent(name);
	},

	reposition: function(coords) {
		// update coordinates, manual or automatically
		coords = coords || (this.target && this.target.offsetHeight)
			? this.target.getCoordinates(this.box.getOffsetParent())
			: {top: window.getScrollTop(), left: 0, width: 40, height: 40}
		this.box.setStyles(coords);
		this.fireEvent('reposition', [coords, this.box, this.target]);
	},

	setOptions: function(options) {
		if (options) {
			if (options.url) options.url = Swiff.Uploader.qualifyPath(options.url);
			if (options.buttonImage) options.buttonImage = Swiff.Uploader.qualifyPath(options.buttonImage);
			this.parent(options);
			if (this.loaded) this.remote('setOptions', options);
		}
		return this;
	},

	setEnabled: function(status) {
		this.remote('setEnabled', status);
	},

	start: function() {
		this.fireEvent('beforeStart');
		this.remote('start');
	},

	stop: function() {
		this.fireEvent('beforeStop');
		this.remote('stop');
	},

	remove: function() {
		this.fireEvent('beforeRemove');
		this.remote('remove');
	},

	fileStart: function(file) {
		this.remote('fileStart', file.id);
	},

	fileStop: function(file) {
		this.remote('fileStop', file.id);
	},

	fileRemove: function(file) {
		this.remote('fileRemove', file.id);
	},

	fileRequeue: function(file) {
		this.remote('fileRequeue', file.id);
	},

	appendCookieData: function() {
		var append = this.options.appendCookieData;
		if (!append) return;
		
		var hash = {};
		document.cookie.split(/;\s*/).each(function(cookie) {
			cookie = cookie.split('=');
			if (cookie.length == 2) {
				hash[decodeURIComponent(cookie[0])] = decodeURIComponent(cookie[1]);
			}
		});

		var data = this.options.data || {};
		if ($type(append) == 'string') data[append] = hash;
		else $extend(data, hash);

		this.setOptions({data: data});
	},

	processFiles: function(successraw, failraw, queue) {
		var cls = this.options.fileClass || Swiff.Uploader.File;

		var fail = [], success = [];

		if (successraw) {
			successraw.each(function(data) {
				var ret = new cls(this, data);
				if (!ret.validate()) {
					ret.remove.delay(10, ret);
					fail.push(ret);
				} else {
					this.size += data.size;
					this.fileList.push(ret);
					success.push(ret);
					ret.render();
				}
			}, this);

			this.fireEvent('selectSuccess', [success], 10);
		}

		if (failraw || fail.length) {
			fail.extend((failraw) ? failraw.map(function(data) {
				return new cls(this, data);
			}, this) : []).each(function(file) {
				file.invalidate().render();
			});

			this.fireEvent('selectFail', [fail], 10);
		}

		this.update(queue);

		if (this.options.instantStart && success.length) this.start();
	}

});

$extend(Swiff.Uploader, {

	STATUS_QUEUED: 0,
	STATUS_RUNNING: 1,
	STATUS_ERROR: 2,
	STATUS_COMPLETE: 3,
	STATUS_STOPPED: 4,

	log: function() {
		if (window.console && console.info) console.info.apply(console, arguments);
	},

	unitLabels: {
		b: [{min: 1, unit: 'B'}, {min: 1024, unit: 'kB'}, {min: 1048576, unit: 'MB'}, {min: 1073741824, unit: 'GB'}],
		s: [{min: 1, unit: 's'}, {min: 60, unit: 'm'}, {min: 3600, unit: 'h'}, {min: 86400, unit: 'd'}]
	},

	formatUnit: function(base, type, join) {
		var labels = Swiff.Uploader.unitLabels[(type == 'bps') ? 'b' : type];
		var append = (type == 'bps') ? '/s' : '';
		var i, l = labels.length, value;

		if (base < 1) return '0 ' + labels[0].unit + append;

		if (type == 's') {
			var units = [];

			for (i = l - 1; i >= 0; i--) {
				value = Math.floor(base / labels[i].min);
				if (value) {
					units.push(value + ' ' + labels[i].unit);
					base -= value * labels[i].min;
					if (!base) break;
				}
			}

			return (join === false) ? units : units.join(join || ', ');
		}

		for (i = l - 1; i >= 0; i--) {
			value = labels[i].min;
			if (base >= value) break;
		}

		return (base / value).toFixed(1) + ' ' + labels[i].unit + append;
	}

});

Swiff.Uploader.qualifyPath = (function() {
	
	var anchor;
	
	return function(path) {
		(anchor || (anchor = new Element('a'))).href = path;
		return anchor.href;
	};

})();

Swiff.Uploader.File = new Class({

	Implements: Events,

	initialize: function(base, data) {
		this.base = base;
		this.update(data);
	},

	update: function(data) {
		return $extend(this, data);
	},

	validate: function() {
		var options = this.base.options;
		
		if (options.fileListMax && this.base.fileList.length >= options.fileListMax) {
			this.validationError = 'fileListMax';
			return false;
		}
		
		if (options.fileListSizeMax && (this.base.size + this.size) > options.fileListSizeMax) {
			this.validationError = 'fileListSizeMax';
			return false;
		}
		
		return true;
	},

	invalidate: function() {
		this.invalid = true;
		this.base.fireEvent('fileInvalid', this, 10);
		return this.fireEvent('invalid', this, 10);
	},

	render: function() {
		return this;
	},

	setOptions: function(options) {
		if (options) {
			if (options.url) options.url = Swiff.Uploader.qualifyPath(options.url);
			this.base.remote('fileSetOptions', this.id, options);
			this.options = $merge(this.options, options);
		}
		return this;
	},

	start: function() {
		this.base.fileStart(this);
		return this;
	},

	stop: function() {
		this.base.fileStop(this);
		return this;
	},

	remove: function() {
		this.base.fileRemove(this);
		return this;
	},

	requeue: function() {
		this.base.fileRequeue(this);
	} 

});


/*
Script: GrowingInput.js
	Alters the size of an input depending on its content

	License:
		MIT-style license.

	Authors:
		Guillermo Rauch
*/

(function(){

GrowingInput = new Class({
	
	Implements: [Options, Events],
	
	options: {
		min: 0,
		max: null,
		startWidth: 2,
		correction: 15
	},
	
	initialize: function(element, options){
		this.setOptions(options);
		this.element = $(element).store('growing', this).set('autocomplete', 'off');		                                                            		                                                           		
		this.calc = new Element('span', {
			'styles': {
				'float': 'left',
				'display': 'inline-block',
				'position': 'absolute',
				'left': -1000
			}
		}).inject(this.element, 'after');					
		['font-size', 'font-family', 'padding-left', 'padding-top', 'padding-bottom', 
		 'padding-right', 'border-left', 'border-right', 'border-top', 'border-bottom', 
		 'word-spacing', 'letter-spacing', 'text-indent', 'text-transform'].each(function(p){
				this.calc.setStyle(p, this.element.getStyle(p));
		}, this);				
		this.resize();
		var resize = this.resize.bind(this);
		this.element.addEvents({blur: resize, keyup: resize, keydown: resize, keypress: resize});
	},
	
	calculate: function(chars){
		this.calc.set('html', chars);
		var width = this.calc.getStyle('width').toInt();
		return (width ? width : this.options.startWidth) + this.options.correction;
	},
	
	resize: function(){
		this.lastvalue = this.value;
		this.value = this.element.value;
		var value = this.value;		
		if($chk(this.options.min) && this.value.length < this.options.min){
			if($chk(this.lastvalue) && (this.lastvalue.length <= this.options.min)) return;
			value = str_pad(this.value, this.options.min, '-');
		} else if($chk(this.options.max) && this.value.length > this.options.max){
			if($chk(this.lastvalue) && (this.lastvalue.length >= this.options.max)) return;
			value = this.value.substr(0, this.options.max);
		}
		this.element.setStyle('width', this.calculate(value));
		return this;
	}
	
});

var str_repeat = function(str, times){ return new Array(times + 1).join(str); };
var str_pad = function(self, length, str, dir){
	if (self.length >= length) return this;
	str = str || ' ';
	var pad = str_repeat(str, length - self.length).substr(0, length - self.length);
	if (!dir || dir == 'right') return self + pad;
	if (dir == 'left') return pad + self;
	return pad.substr(0, (pad.length / 2).floor()) + self + pad.substr(0, (pad.length / 2).ceil());
};

})();

/*
Script: TextboxList.js
	Displays a textbox as a combination of boxes an inputs (eg: facebook tokenizer)

	Authors:
		Guillermo Rauch
		
	Note:
		TextboxList is not priceless for commercial use. See <http://devthought.com/projects/mootools/textboxlist/>. 
		Purchase to remove this message.
*/

var TextboxList = new Class({
          
  Implements: [Options, Events],

  plugins: [],

  options: {/*
    onFocus: $empty,
    onBlur: $empty,
    onBitFocus: $empty,
    onBitBlur: $empty,
    onBitAdd: $empty,
    onBitRemove: $empty,
    onBitBoxFocus: $empty,
    onBitBoxBlur: $empty,
    onBitBoxAdd: $empty,
    onBitBoxRemove: $empty,
    onBitEditableFocus: $empty,
    onBitEditableBlue: $empty,
    onBitEditableAdd: $empty,
    onBitEditableRemove: $empty,*/
    prefix: 'textboxlist',
    max: null,
		unique: false,
		uniqueInsensitive: true,
    endEditableBit: true,
		startEditableBit: true,
		hideEditableBits: true,
    inBetweenEditableBits: true,
		keys: {previous: Event.Keys.left, next: Event.Keys.right},
		bitsOptions: {editable: {}, box: {}},
    plugins: {},
		check: function(s){ return s.clean().replace(/,/g, '') != ''; },
		encode: function(o){ 
			return o.map(function(v){				
				v = ($chk(v[0]) ? v[0] : v[1]);
				return $chk(v) ? v : null;
			}).clean().join(','); 
		},
		decode: function(o){ return o.split(','); }
  },
  
  initialize: function(element, options){
		this.setOptions(options);		
		this.original = $(element).setStyle('display', 'none').set('autocomplete', 'off').addEvent('focus', this.focusLast.bind(this));
    this.container = new Element('div', {'class': this.options.prefix}).inject(element, 'after');
		this.container.addEvent('click', function(e){ 
			if ((e.target == this.list || e.target == this.container) && (!this.focused || $(this.current) != this.list.getLast())) this.focusLast(); 			
		}.bind(this));
    this.list = new Element('ul', {'class': this.options.prefix + '-bits'}).inject(this.container);		
		for (var name in this.options.plugins) this.enablePlugin(name, this.options.plugins[name]);		
		['check', 'encode', 'decode'].each(function(i){ this.options[i] = this.options[i].bind(this); }, this);
		this.afterInit();
  },

	enablePlugin: function(name, options){
		this.plugins[name] = new TextboxList[name.camelCase().capitalize()](this, options);
	},
	
	afterInit: function(){
		if (this.options.unique) this.index = [];
		if (this.options.endEditableBit) this.create('editable', null, {tabIndex: this.original.tabIndex}).inject(this.list);
		var update = this.update.bind(this);
		this.addEvent('bitAdd', update, true).addEvent('bitRemove', update, true);
		document.addEvents({
			click: function(e){
				if (!this.focused) return;
				if (e.target.className.contains(this.options.prefix)){
					if (e.target == this.container) return;
					var parent = e.target.getParent('.' + this.options.prefix);
					if (parent == this.container) return;
				}
				this.blur();
			}.bind(this),
			keydown: function(ev){
				if (!this.focused || !this.current) return;
				var caret = this.current.is('editable') ? this.current.getCaret() : null;
				var value = this.current.getValue()[1];
				var special = ['shift', 'alt', 'meta', 'ctrl'].some(function(e){ return ev[e]; });
				var custom = special || (this.current.is('editable') && this.current.isSelected());
				switch (ev.code){
					case Event.Keys.backspace:
						if (this.current.is('box')){ 
							ev.stop();
							return this.current.remove(); 
						}
					case this.options.keys.previous:
						if (this.current.is('box') || ((caret == 0 || !value.length) && !custom)){
							ev.stop();
							this.focusRelative('previous');
						}
						break;
					case Event.Keys['delete']:
						if (this.current.is('box')){ 
							ev.stop();
							return this.current.remove(); 
						}
					case this.options.keys.next: 
						if (this.current.is('box') || (caret == value.length && !custom)){
							ev.stop();
							this.focusRelative('next');
						}
				}
			}.bind(this)
		});		
		this.setValues(this.options.decode(this.original.get('value')));
	},
	
	create: function(klass, value, options){
		if (klass == 'box'){
			if ((!value[0] && !value[1]) || ($chk(value[1]) && !this.options.check(value[1]))) return false;
			if ($chk(this.options.max) && this.list.getChildren('.' + this.options.prefix + '-bit-box').length + 1 > this.options.max) return false;
			if (this.options.unique && this.index.contains(this.uniqueValue(value))) return false;		
		}		
		return new TextboxListBit[klass.capitalize()](value, this, $merge(this.options.bitsOptions[klass], options));		
	},
	
	uniqueValue: function(value){
		return $chk(value[0]) ? value[0] : (this.options.uniqueInsensitive ? value[1].toLowerCase() : value[1]);
	},
	
	onFocus: function(bit){
		if (this.current) this.current.blur();
		$clear(this.blurtimer);
		this.current = bit;
		this.container.addClass(this.options.prefix + '-focus');
		if (!this.focused){
			this.focused = true;
			this.fireEvent('focus', bit);
		}
	},
	
	onBlur: function(bit, all){
		this.current = null;
		this.container.removeClass(this.options.prefix + '-focus');		
		this.blurtimer = this.blur.delay(all ? 0 : 200, this);
	},
	
	onAdd: function(bit){
		if (this.options.unique && bit.is('box')) this.index.push(this.uniqueValue(bit.value));
		if (bit.is('box')){
			var prior = this.getBit($(bit).getPrevious());
			if ((prior && prior.is('box') && this.options.inBetweenEditableBits) || (!prior && this.options.startEditableBit)){				
				var b = this.create('editable').inject(prior || this.list, prior ? 'after' : 'top');
				if (this.options.hideEditableBits) b.hide();
			}
		}
	},
	
	onRemove: function(bit){
		if (!this.focused) return;
		if (this.options.unique && bit.is('box')) this.index.erase(this.uniqueValue(bit.value));
		var prior = this.getBit($(bit).getPrevious());
		if (prior && prior.is('editable')) prior.remove();
		this.focusRelative('next', bit);
	},
	
	focusRelative: function(dir, to){
		var b = this.getBit($($pick(to, this.current))['get' + dir.capitalize()]());
		if (b) b.focus();
		return this; 
	},
	
	focusLast: function(){		
		var lastElement = this.list.getLast();
		if (lastElement) this.getBit(lastElement).focus();
		return this;
	},
	
	blur: function(){		
		if (! this.focused) return this;
		if (this.current) this.current.blur();
		this.focused = false;
		return this.fireEvent('blur');
	},
	
	add: function(plain, id, html, afterEl){
		var b = this.create('box', [id, plain, html]);
		if (b){
			if (!afterEl) afterEl = this.list.getLast('.' + this.options.prefix + '-bit-box');
			b.inject(afterEl || this.list, afterEl ? 'after' : 'top');
		}
		return this;
	},
	
	getBit: function(obj){
		return ($type(obj) == 'element') ? obj.retrieve('textboxlist:bit') : obj;
	},
	
	getValues: function(){
		return this.list.getChildren().map(function(el){
			var bit = this.getBit(el);
			if (bit.is('editable')) return null;
			return bit.getValue();
		}, this).clean();
	},
	
	//If id was the first parameter
	getIds: function(){
		return this.list.getChildren().map(function(el){
			var bit = this.getBit(el);
			if (bit.is('editable')) return null;
			return bit.getValue()[0];
		}, this).clean();
	},
	
	//remove all the bits of the textboxlist
	removeAllBits: function(){
		this.list.getChildren().map(function(el){
			var bit = this.getBit(el);
		  bit.remove();
		}, this);
	},
	
	setValues: function(values){
		if (!values) return;
		values.each(function(v){
			if (v) this.add.apply(this, $type(v) == 'array' ? [v[1], v[0], v[2]] : [v]);
		}, this);		
	},
	
	update: function(){
		this.original.set('value', this.options.encode(this.getValues()));
	}
  
});

var TextboxListBit = new Class({
  
  Implements: Options,  

  initialize: function(value, textboxlist, options){
		this.name = this.type.capitalize();
		this.value = value;
    this.textboxlist = textboxlist;
    this.setOptions(options);            
    this.prefix = this.textboxlist.options.prefix + '-bit';
		this.typeprefix = this.prefix + '-' + this.type;
    this.bit = new Element('li').addClass(this.prefix).addClass(this.typeprefix).store('textboxlist:bit', this);
		this.bit.addEvents({
			mouseenter: function(){ 
				this.bit.addClass(this.prefix + '-hover').addClass(this.typeprefix + '-hover'); 
			}.bind(this),
			mouseleave: function(){
				this.bit.removeClass(this.prefix + '-hover').removeClass(this.typeprefix + '-hover'); 
			}.bind(this)
		});
  },

	inject: function(element, where){
		this.bit.inject(element, where);	
		this.textboxlist.onAdd(this);	
		return this.fireBitEvent('add');
	},

	focus: function(){
		if (this.focused) return this;
		this.show();
		this.focused = true;
		this.textboxlist.onFocus(this);
		this.bit.addClass(this.prefix + '-focus').addClass(this.prefix + '-' + this.type + '-focus');
		return this.fireBitEvent('focus');
	},

	blur: function(){
		if (!this.focused) return this;
		this.focused = false;
		this.textboxlist.onBlur(this);
		this.bit.removeClass(this.prefix + '-focus').removeClass(this.prefix + '-' + this.type + '-focus');
		return this.fireBitEvent('blur');
	},
	
	remove: function(){
		this.blur();		
		this.textboxlist.onRemove(this);
		this.bit.destroy();
		return this.fireBitEvent('remove');
	},
	
	show: function(){
		this.bit.setStyle('display', 'block');
		return this;
	},
	
	hide: function(){
		this.bit.setStyle('display', 'none');
		return this;
	},
	
	fireBitEvent: function(type){
		type = type.capitalize();
		this.textboxlist.fireEvent('bit' + type, this).fireEvent('bit' + this.name + type, this);
		return this;
	},
	
  is: function(t){
    return this.type == t;
  },

	setValue: function(v){
		this.value = v;
		return this;
	},

	getValue: function(){
		return this.value;
	},

	toElement: function(){
		return this.bit;
	}
  
});

TextboxListBit.Editable = new Class({
  
	Extends: TextboxListBit,

  options: {
		tabIndex: null,
		growing: true,
		growingOptions: {},
		stopEnter: true,
		addOnBlur: false,
		addKeys: Event.Keys.enter
  },
  
  type: 'editable',
  
  initialize: function(value, textboxlist, options){
    this.parent(value, textboxlist, options);
    this.element = new Element('input', {type: 'text', 'class': this.typeprefix + '-input', autocomplete: 'off', value: this.value ? this.value[1] : ''}).inject(this.bit);		
		if ($chk(this.options.tabIndex)) this.element.tabIndex = this.options.tabIndex;
		if (this.options.growing) new GrowingInput(this.element, this.options.growingOptions);		
		this.element.addEvents({
			focus: function(){ this.focus(true); }.bind(this),
			blur: function(){
				this.blur(true);
				if (this.options.addOnBlur) this.toBox(); 
			}.bind(this)
		});
		if (this.options.addKeys || this.options.stopEnter){
			this.element.addEvent('keydown', function(ev){
				if (!this.focused) return;
				if (this.options.stopEnter && ev.code === Event.Keys.enter) ev.stop();
				if ($splat(this.options.addKeys).contains(ev.code)){
					ev.stop();
					this.toBox();
				}
			}.bind(this));
		}
  },

	hide: function(){
		this.parent();
		this.hidden = true;
		return this;
	},
  
	focus: function(noReal){
		this.parent();
		if (!noReal) this.element.focus();	
		return this;
	},
	
	blur: function(noReal){
		this.parent();
		if (!noReal) this.element.blur();
		if (this.hidden && !this.element.value.length) this.hide();
		return this;
	},
	
	getCaret: function(){
		if (this.element.createTextRange){
	    var r = document.selection.createRange().duplicate();		
	  	r.moveEnd('character', this.element.value.length);
	  	if (r.text === '') return this.element.value.length;
	  	return this.element.value.lastIndexOf(r.text);
	  } else return this.element.selectionStart;
	},
	
	getCaretEnd: function(){
		if (this.element.createTextRange){
			var r = document.selection.createRange().duplicate();
			r.moveStart('character', -this.element.value.length);
			return r.text.length;
		} else return this.element.selectionEnd;
	},
	
	isSelected: function(){
		return this.focused && (this.getCaret() !== this.getCaretEnd());
	},

	setValue: function(val){
		this.element.value = $chk(val[0]) ? val[0] : val[1];
		if (this.options.growing) this.element.retrieve('growing').resize();
		return this;
	},

	getValue: function(){
		return [null, this.element.value, null];
	},
	
	toBox: function(){
		var value = this.getValue();				
		var b = this.textboxlist.create('box', value);
		if (b){
			b.inject(this.bit, 'before');
			this.setValue([null, '', null])
			return b;
		}
		return null;
	}
	
});

TextboxListBit.Box = new Class({
  
	Extends: TextboxListBit,

  options: {
		deleteButton: true
  },
  
  type: 'box',
  
  initialize: function(value, textboxlist, options){
    this.parent(value, textboxlist, options);
		this.bit.set('html', $chk(this.value[2]) ? this.value[2] : this.value[1]);
		this.bit.addEvent('click', this.focus.bind(this));
		if (this.options.deleteButton){
			this.bit.addClass(this.typeprefix + '-deletable');
			this.close = new Element('a', {href: '#', 'class': this.typeprefix + '-deletebutton', events: {click: this.remove.bind(this)}}).inject(this.bit);
		}
		this.bit.getChildren().addEvent('click', function(e){ e.stop(); });
  }
  
});

/*
Script: TextboxList.Autocomplete.js
	TextboxList Autocomplete plugin

	Authors:
		Guillermo Rauch
	
	Note:
		TextboxList is not priceless for commercial use. See <http://devthought.com/projects/mootools/textboxlist/>
		Purchase to remove this message.
*/

(function(){

TextboxList.Autocomplete = new Class({
	
	Implements: Options,
	
	options: {
		minLength: 1,
		maxResults: 10,
		insensitive: true,
		highlight: true,
		highlightSelector: null,
		mouseInteraction: true,
		onlyFromValues: false,
		queryRemote: false,
		remote: {
			url: '',
			param: 'search',
			extraParams: {},
			loadPlaceholder: 'Please wait...'
		},
		method: 'standard',
		placeholder: 'Type to receive suggestions'
	},
	
	initialize: function(textboxlist, options){
		this.setOptions(options);
		this.textboxlist = textboxlist;
		this.textboxlist.addEvent('bitEditableAdd', this.setupBit.bind(this), true)
			.addEvent('bitEditableFocus', this.search.bind(this), true)
			.addEvent('bitEditableBlur', this.hide.bind(this), true)
			.setOptions({bitsOptions: {editable: {addKeys:[], stopEnter: false}}});
		if (Browser.Engine.trident) this.textboxlist.setOptions({bitsOptions: {editable: {addOnBlur: false}}});
		if (this.textboxlist.options.unique){
			this.index = [];
			this.textboxlist.addEvent('bitBoxRemove', function(bit){
				if (bit.autoValue) this.index.erase(bit.autoValue);
			}.bind(this), true);
		}
		this.prefix = this.textboxlist.options.prefix + '-autocomplete';
		this.method = TextboxList.Autocomplete.Methods[this.options.method];
		this.container = new Element('div', {'class': this.prefix}).setStyle('width', this.textboxlist.container.getStyle('width')).inject(this.textboxlist.container);
		if ($chk(this.options.placeholder) || this.options.queryServer) 
			this.placeholder = new Element('div', {'class': this.prefix+'-placeholder'}).inject(this.container);		
		this.list = new Element('ul', {'class': this.prefix + '-results'}).inject(this.container);
		this.list.addEvent('click', function(ev){ ev.stop(); });
		this.values = this.results = this.searchValues = [];
		this.navigate = this.navigate.bind(this);
	},
	
	setValues: function(values){
		this.values = values;
	},
	
	setupBit: function(bit){
		bit.element.addEvent('keydown', this.navigate, true).addEvent('keyup', function(){ this.search(); }.bind(this), true);
	},
		
	search: function(bit){
		if (bit) this.currentInput = bit;
		if (!this.options.queryRemote && !this.values.length) return;
		var search = this.currentInput.getValue()[1];
		if (search.length < this.options.minLength) this.showPlaceholder(this.options.placeholder);
		if (search == this.currentSearch) return;
		this.currentSearch = search;
		this.list.setStyle('display', 'none');
		if (search.length < this.options.minLength) return;
		if (this.options.queryRemote){
			if (this.searchValues[search]){
				this.values = this.searchValues[search];
			} else {
				var data = this.options.remote.extraParams, that = this;
				if ($type(data) == 'function') data = data.run([], this);
				data[this.options.remote.param] = search;
				if (this.currentRequest) this.currentRequest.cancel();
				this.currentRequest = new Request.JSON({url: this.options.remote.url, data: data, onRequest: function(){
					that.showPlaceholder(that.options.remote.loadPlaceholder);
				}, onSuccess: function(data){
					that.searchValues[search] = data;
					that.values = data;
					that.showResults(search);
				}}).send();
			}
		} 
		if (this.values.length) this.showResults(search);
	},
	
	showResults: function(search){		
		var results = this.method.filter(this.values, search, this.options.insensitive, this.options.maxResults);
		if (this.index) results = results.filter(function(v){ return !this.index.contains(v); }, this);
		this.hidePlaceholder();
		if (!results.length) return;
		this.blur();
		this.list.empty().setStyle('display', 'block');
		results.each(function(r){ this.addResult(r, search); }, this);
		if (this.options.onlyFromValues) this.focusFirst();
		this.results = results;
	},	
	
	addResult: function(r, search){
		var element = new Element('li', {'class': this.prefix + '-result', 'html': $pick(r[3], r[1])}).store('textboxlist:auto:value', r);
		this.list.adopt(element);
		if (this.options.highlight) $$(this.options.highlightSelector ? element.getElements(this.options.highlightSelector) : element).each(function(el){
			if (el.get('html')) this.method.highlight(el, search, this.options.insensitive, this.prefix + '-highlight');
		}, this);
		if (this.options.mouseInteraction){
			element.setStyle('cursor', 'pointer').addEvents({
				mouseenter: function(){ this.focus(element); }.bind(this),
				mousedown: function(ev){
					ev.stop(); 
					$clear(this.hidetimer);
					this.doAdd = true;
				}.bind(this),
				mouseup: function(){
					if (this.doAdd){
						this.addCurrent();
						this.currentInput.focus();
						this.search();
						this.doAdd = false;
					}
				}.bind(this)
			});
			if (!this.options.onlyFromValues) element.addEvent('mouseleave', function(){ if (this.current == element) this.blur(); }.bind(this));	
		}
	},
	
	hide: function(ev){
		this.hidetimer = (function(){
			this.hidePlaceholder();
			this.list.setStyle('display', 'none');
			this.currentSearch = null;
		}).delay(Browser.Engine.trident ? 150 : 0, this);
	},
	
	showPlaceholder: function(customHTML){
		if (this.placeholder){
			this.placeholder.setStyle('display', 'block');	
			if (customHTML) this.placeholder.set('html', customHTML);
		}		
	},
	
	hidePlaceholder: function(){
		if (this.placeholder) this.placeholder.setStyle('display', 'none');
	},
	
	focus: function(element){
		if (!element) return this;
		this.blur();
		this.current = element.addClass(this.prefix + '-result-focus');
	},
	
	blur: function(){
		if (this.current){
			this.current.removeClass(this.prefix + '-result-focus');
			this.current = null;
		}
	},
	
	focusFirst: function(){
		return this.focus(this.list.getFirst());
	},
	
	focusRelative: function(dir){
		if (!this.current) return this;
		return this.focus(this.current['get' + dir.capitalize()]());
	},
	
	addCurrent: function(){
		var value = this.current.retrieve('textboxlist:auto:value');
		var b = this.textboxlist.create('box', value.slice(0, 3));
		if (b){
			b.autoValue = value;
			if (this.index != null) this.index.push(value);
			this.currentInput.setValue([null, '', null]);
			b.inject($(this.currentInput), 'before');
		}
		this.blur();
		return this;
	},
	
	navigate: function(ev){
		switch (ev.code){
			case Event.Keys.up:			
				ev.stop();
				(!this.options.onlyFromValues && this.current && this.current == this.list.getFirst()) ? this.blur() : this.focusRelative('previous');
				break;
			case Event.Keys.down:			
				ev.stop();
				this.current ? this.focusRelative('next') : this.focusFirst();
				break;
			case Event.Keys.enter:
				ev.stop();
				if (this.current) this.addCurrent();
				else if (!this.options.onlyFromValues){
					var value = this.currentInput.getValue();				
					var b = this.textboxlist.create('box', value);
					if (b){
						b.inject($(this.currentInput), 'before');
						this.currentInput.setValue([null, '', null]);
					}
				}
		}
	}
	
});

TextboxList.Autocomplete.Methods = {
	
	standard: {
		filter: function(values, search, insensitive, max){
			var newvals = [], regexp = new RegExp('\\b' + search.escapeRegExp(), insensitive ? 'i' : '');
			for (var i = 0; i < values.length; i++){
				if (newvals.length === max) break;
				if (values[i][1].test(regexp)) newvals.push(values[i]);
			}
			return newvals;
		},
		
		highlight: function(element, search, insensitive, klass){
			var regex = new RegExp('(<[^>]*>)|(\\b'+ search.escapeRegExp() +')', insensitive ? 'ig' : 'g');
			return element.set('html', element.get('html').replace(regex, function(a, b, c){
				return (a.charAt(0) == '<') ? a : '<strong class="'+ klass +'">' + c + '</strong>'; 
			}));
		}
	}
	
};

})();

/*
Script: PlaceholderInput.js
	Sets a default message for input type="text" and textareas

	License:
		MIT-style license.

	Authors:
		Guillermo Rauch
*/

var PlaceholderInput = new Class({
  
  initialize: function(element, klass){
    this.klass = klass || 'input_placeholder';
    this.element = $(element).store('placeholder', this);    
    this.placeholder = this.element.get('placeholder');
    this.element.addEvents({
      'focus': this.focus.bind(this),
      'blur': this.blur.bind(this)
    }).removeClass(this.klass).set('autocomplete', 'off');
    this.reset();
  },
  
  focus: function(){
    if(this.placeholder && (this.element.get('value', true) == this.placeholder) && this.active) {
      this.element.set('value', '', true).removeClass(this.klass);
			this.active = false;
    }
  },
  
  blur: function(){
    if(this.placeholder && this.element.get('value', true) == '') {
      this.element.addClass(this.klass).set('value', this.placeholder, true);
      this.active = true;
    }
  },
  
  reset: function(){
    this.focus();
    this.blur();
    return this;
  },
  
  setText: function(v){
    this.placeholder = v;
    this.element.set('placeholder', v).set('value', '');
  }
  
});

Element.Properties.value = {

  get: function(real){
    var value = this.value, place = this.retrieve('placeholder');
    if(real || ! place) return value;
    if(place && place.active) return '';
    return value;
  },

  set: function(value, real){
    var place = this.retrieve('placeholder');
    this.value = value;
    if(place && ! real) place.reset();
  }
  
};

/*
--- 
name: JustTheTip
script: JustTheTip.js
description: Tool-tip class that allows for arbitrary HTML and provides lots of events to hook into.

authors: 
  - 3n

provides: 
  - JustTheTip

requires: 
  - More/Class.Binds
  - More/Element.Position
  - Core/Class.Extras
  - Core/Element.Event
  - Core/Element.Style
  - Core/Selectors
  
license: MIT-style

...
*/

var JustTheTip = new Class({
	Implements: [Options, Events],
  Binds: ['hide_tip'],
	
	options : {
		show_delay : 400,
		hide_delay : 200,
		z_index    : 100,
		show_event : 'mouseenter',
		hide_event : 'mouseleave',
		tip_html   : '',
		tip_class  : 'tip',
		tip_enter  : 'mouseenter',
		tip_leave  : 'mouseleave',
		fade_in_duration  : 0,
		fade_out_duration : 0,
		click_away_hide : false,
    position : { 'position': 'upperRight', 'edge': 'upperLeft' },
    shouldShowTip: function(elem){
      return true;
    }
	},
	
	initialize: function(elements, options){
		this.setOptions(options);
		this.elements = elements;

		this.the_tip = new Element('div', {
			'class' 	: this.options.tip_class,
			'styles' 	: {
				'display' 	: 'none',
				'position' 	: 'absolute',
				'top' 			: 0,
				'left' 			: 0,
				'z-index'   : this.options.z_index
			}
		}).inject(document.body)
			.set('html', this.options.tip_html);
			
		this.fireEvent('onTipInjected', [this.the_tip, this]);

		[this.options.tip_enter].flatten().each(function(te){
			this.the_tip.addEvent(te, this._tip_enter.bind(this));
		}, this);
		[this.options.tip_leave].flatten().each(function(tl){
			this.the_tip.addEvent(tl, this._tip_leave.bind(this));
		}, this);
		
		this.is_it_in_yet = false;
		this.attach_events();
		
		return this;
	},
	
	attach_events: function(elements){
	  var elements = elements || this.elements;
		$$(elements).each(function(elem){
			elem.store('just_the_tip_on', true);
			[this.options.show_event].flatten().each(function(se){
			  var events_obj = {}, callback;
				if (se.match(/relay\(/)){
          var thiz = this;
          callback = function(){
             this.store('just_the_tip_on', true);
             thiz.show_tip(this);
           };
				} else
				  callback = this.show_tip.bind(this, elem);
				
				elem.addEvent(se, callback);
				events_obj[se] = callback;
			  elem.store('just-the-tip-events', $merge(elem.retrieve('just-the-tip-events') || {}, events_obj));					
			}, this);
		}.bind(this));

		this._click_away = function(e){
		  if (this._is_tip_shown() && e.target != this.the_tip && !$(e.target).getParents().contains(this.the_tip)){
	      this.hide_tip();
	    }
		}.bind(this);
	},
	detach_events: function(elements){
	  var elements = elements || this.elements;
	  $$(elements).each(function(elem){
      $each(elem.retrieve('just-the-tip-events'), function(v,k){
        elem.removeEvent(k,v);
      });
		}.bind(this));
		
		if (this.options.click_away_hide){
		  $(document.body).removeEvent('click', this._click_away);
		}
	},
	
	_get_position: function(){
	  if ($type(this.options.position) == 'string')
	    return {position: this.options.position};
	  else
	    return this.options.position;
	},
	
	_is_tip_shown: function(){
	  return this.the_tip && this.the_tip.getStyle('display') != 'none';
	},
	_show_tip: function(){
	  this.the_tip.setStyle('display', 'block');
	},
	show_tip: function(elem){
	  if (!this.options.shouldShowTip(elem)) return;
	  if (elem == this.current_element && this._is_tip_shown()) return;
	  
	  if (elem != this.current_element && this._is_tip_shown()){
	    this.hide_tip();
	  }
	  
		this.current_element = elem;
		[this.options.hide_event].flatten().each(function(he){
			this.current_element.addEvent(he, this.hide_tip);
		}, this);
				
		$clear(this.timer);
		this.timer = (function(){
			if (elem.retrieve('just_the_tip_on')){
				this.fireEvent('tipShown', [this.the_tip, this.current_element, this]);
				if (Element.fade){
				  this.the_tip.fade('hide');
          this.the_tip.set('tween', {
            duration   : this.options.fade_in_duration,
            onStart    : this._show_tip.bind(this)
          }).fade('in');
				} else
				  this._show_tip();
        this.the_tip.position( $merge({relativeTo: elem, ignoreScroll: true}, this._get_position()) );        

        if (this.options.click_away_hide){
          $(document.body).addEvent.delay(1, $(document.body), ['click', this._click_away]);
    		}
			}
		}).delay(this.options.show_delay, this);
	},	
	_hide_tip: function(){
	  this.the_tip.setStyle('display','none');
    this.fireEvent('tipHidden', [this.the_tip, this.current_element, this]);
	},
	hide_tip: function(){
		$clear(this.timer);
		this.timer = (function(){
			if (!this.is_it_in_yet) {				
				[this.options.hide_event].flatten().each(function(he){
					this.current_element.removeEvent(he, this.hide_tip);
				}, this);

        if (Element.fade){
          this.the_tip.set('tween', {
            duration   : this.options.fade_out_duration,
            onComplete : this._hide_tip.bind(this)
          }).fade('out');		
        } else
          this._hide_tip();
			}
		}).delay(this.options.hide_delay, this);
		
		if (this.options.click_away_hide){
		  $(document.body).removeEvent('click', this._click_away);
		}
	},
	
	add_element: function(elem){
	  this.attach_events(elem);
	  return this;
	},
	
	turn_tips_on: function(elem){
	  var elem = elem || this.elements;
	  elem.store('just_the_tip_on', true);
	},
	turn_tips_off: function(elem){
	  var elem = elem || this.elements;
	  elem.store('just_the_tip_on', false);
	},
	
	_tip_enter: function(){
		this.is_it_in_yet = true;
	},
	_tip_leave: function(){
		this.is_it_in_yet = false;
		this.hide_tip();
	}
});

/*
	Class: FormCheck
		Performs different tests on forms and indicates errors.

	Usage:
		Works with these types of fields :
		- input (text, radio, checkbox)
		- textarea
		- select

		You just need to add a specific class to each fields you want to check.
		For example, if you add the class
			(code)
			validate['required','length[4, -1]','differs:email','digit']
			(end code)
		the value's field must be set (required) with a minimum length of four chars (4, -1),
		must differs of the input named email (differs:email), and must be digit.

		You can perform check during the datas entry or on the submit action, shows errors as tips or in a div before or after the field,
		show errors one by one or all together, show a list of all errors at the top of the form, localize error messages, add new regex check, ...

		The layout is design only with css. Now I added a hack to use transparent png with IE6, so you can use png images in formcheck.css (works only for theme, so the file must be named formcheck.css). It can also works with multiple forms on a single html page.
		The class supports now internationalization. To use it, simply specify a new <script> element in your html head, like this : <script type="text/javascript" src="formcheck/lang/fr.js"></script>.

		If you add the class
			(code)
			validate['submit']
			(end code)
		to an element like an anchor (or anything else), this element will act as a submit button.

		N.B. : you must load the language script before the formcheck and this method overpass the old way. You can create new languages following existing ones. You can otherwise still specifiy the alerts' strings when you initialize the Class, with options.
		If you don't use a language script, the alert will be displayed in english.

	Test type:
		You can perform various test on fields by adding them to the validate class. Be careful to *not use space chars*. Here is the list of them.

		required 					- The field becomes required. This is a regex, you can change it with class options.
		alpha 						- The value is restricted to alphabetic chars. This is a regex, you can change it with class options.
		alphanum 					- The value is restricted to alphanumeric characters only. This is a regex, you can change it with class options.
		nodigit 					- The field doesn't accept digit chars. This is a regex, you can change it with class options.
		digit 						- The value is restricted to digit (no floating point number) chars, you can pass two arguments (f.e. digit[21,65]) to limit the number between them. Use -1 as second argument to set no maximum.
		number 						- The value is restricted to number, including floating point number. This is a regex, you can change it with class options.
		email 						- The value is restricted to valid email. This is a regex, you can change it with class options.
		image						- The value is restricted to images (jpg, jpeg, png, gif, bmp). This is a regex, you can change it with class options.
		phone 						- The value is restricted to phone chars. This is a regex, you can change it with class options.
		phone_inter					- The value is restricted to international phone number. This is a regex, you can change it with class options.
		url: 						- The value is restricted to url. This is a regex, you can change it with class options.
		confirm 					- The value has to be the same as the specified. f.e. confirm:password.
		differs 					- The value has to be diferent as the one specifies. f.e. differs:user.
		length 						- The value length is restricted by argument (f.e. length[6,10]). Use -1 as second argument to set no maximum.
		group						- Use to validate several checkboxes as a group. Requires 2 arguments, the second one being optional (1 by default): the group id and the minimum amount of boxes to check. The second argument may be set on any or all items of the group. See example below.
		words						- The words number is limited by arguments. f.e. words[1,13]. Use -1 as second argument to don't have a max limit.
		target						- It's not really a validation test, but it allows you to attach the error message to an other element, usefull if the input you validate is hidden. You must specifiy target id, f.e. target:myDiv.

		You can also use a custom function to check a field. For example, if you have a field with class
			(code)
			validate['required','%customCheck']
			(end code)
		the function customCheck(el) will be called to validate the field. '%customcheck' works with other validate(s) together, and '~customcheck' works if the element pass the other validate(s).
		Here is an example of what customCheck could look :
			(code)
			function customCheck(el){
				if (!el.value.test(/^[A-Z]/)) {
					el.errors.push("Username should begin with an uppercase letter");
					return false;
				} else {
					return true;
				}
			}
			(end code)

		To validate checkoxes group, you could make something like :
			(code)
				<input type="checkbox" name="dog" class="validate['group[1,2]']">
				<input type="checkbox" name="cat" class="validate['group[1]']">
				<input type="checkbox" name="mouse" class="validate['group[1]']">
			(end code)
		For checkboxes from group 1, you will need to check at least 2 boxes.

		It is now possible to register new fields after a new FormCheck call by using <FormCheck::register> (see <FormCheck::dispose> too). You need first to add the validate class to the element you want to register ( $('myInput').addClass("validate['required']") ).

	Parameters:
		When you initialize the class with addEvent, you can set some options. If you want to modify regex, you must do it in a hash, like for display or alert. You can also add new regex check method by adding the regex and an alert with the same name.

		Required:

			form_id - The id of the formular. This is required.

		Optional:

			submit					- If you turn this option to false, the FormCheck will only perform a validation, without submitting the form, even on success. You can use validateSuccess event to execute some code.

			submitByAjax 			- you can set this to true if you want to submit your form with ajax. You should use provided events to handle the ajax request (see below). By default it is false.
			ajaxResponseDiv 		- id of element to inject ajax response into (can also use onAjaxSuccess). By default it is false.
			ajaxEvalScripts 		- use evalScripts in the Request response. Can be true or false, by default it is false.
			onAjaxRequest 			- Function to fire when the Request event starts.
			onAjaxComplete 			- Function to fire when the Request event completes regardless of and prior to Success or Failure.
			onAjaxSuccess 			- Function to fire when the Request receives .  Args: response [the request response] - see Mootools docs for Request.onSuccess.
			onAjaxFailure 			- Function to fire if the Request fails.

			onSubmit				- Function to fire when form is submited (so before validation)
			onValidateSuccess 		- Function to fire when validation pass (you should prevent form submission with option submit:false to use this)
			onValidateFailure		- Function to fire when validation fails

			tipsClass 				- The class to apply to tipboxes' errors. By default it is 'fc-tbx'.
			errorClass 				- The class to apply to alertbox (not tips). By default it is 'fc-error'.
			fieldErrorClass 		- The class to apply to fields with errors, except for radios. You should also turn on  options.addClassErrorToField. By default it is 'fc-field-error'

			trimValue				- If set to true, strip whitespace (or other characters) from the beginning and end of values. By default it is false.
			validateDisabled		- If set to true, disabled input will be validated too, otherwise not.

		Display:
			This is a hash of display settings. in here you can modify.

			showErrors 				- 0 : onSubmit, 1 : onSubmit & onBlur, by default it is 0.
			titlesInsteadNames		- 0 : When you do a check using differs or confirm, it takes the field name for the alert. If it's set to 1, it will use the title instead of the name.
			errorsLocation 			- 1 : tips, 2 : before, 3 : after, by default it is 1.
			indicateErrors 			- 0 : none, 1 : one by one, 2 : all, by default it is 1.
			indicateErrorsInit		- 0 : determine if the form must be checked on initialize. Could be usefull to force the user to update fields that don't validate.
			keepFocusOnError 		- 0 : normal behaviour, 1 : the current field keep the focus as it remain errors. By default it is 0.
			checkValueIfEmpty 		- 0 : When you leave a field and you have set the showErrors option to 1, the value is tested only if a value has been set. 1 : The value is tested  in any case.  By default it is 1.
			addClassErrorToField 	- 0 : no class is added to the field, 1 : the options.fieldErrorClass is added to the field with an error (except for radio). By default it is 0.
			removeClassErrorOnTipClosure - 0 : Error class is kept when the tip is closed, 1 : Error class is removed when the tip is closed

			fixPngForIe 			- 0 : do nothing, 1 : fix png alpha for IE6 in formcheck.css. By default it is 1.
			replaceTipsEffect 		- 0 : No effect on tips replace when we resize the broswer, 1: tween transition on browser resize;
			closeTipsButton 		- 0 : the close button of the tipbox is hidden, 1 : the close button of the tipbox is visible. By default it is 1.
			flashTips 				- 0 : normal behaviour, 1 : the tipbox "flash" (disappear and reappear) if errors remain when the form is submitted. By default it is 0.
			tipsPosition 			- 'right' : the tips box is placed on the right part of the field, 'left' to place it on the left part. By default it is 'right'.
			tipsOffsetX 			- Horizontal position of the tips box (margin-left), , by default it is 100 (px).
			tipsOffsetY				- Vertical position of the tips box (margin-bottom), , by default it is -10 (px).

			listErrorsAtTop 		- List all errors at the top of the form, , by default it is false.
			scrollToFirst 			- Smooth scroll the page to first error and focus on it, by default it is true.
			fadeDuration 			- Transition duration (in ms), by default it is 300.

		Alerts:
			This is a hash of alerts settings. in here you can modify strings to localize or wathever else. %0 and %1 represent the argument.

			required 				- "This field is required."
			alpha 					- "This field accepts alphabetic characters only."
			alphanum 				- "This field accepts alphanumeric characters only."
			nodigit 				- "No digits are accepted."
			digit 					- "Please enter a valid integer."
			digitmin 				- "The number must be at least %0"
			digitltd 				- "The value must be between %0 and %1"
			number 					- "Please enter a valid number."
			email 					- "Please enter a valid email: <br /><span>E.g. yourname@domain.com</span>"
			phone 					- "Please enter a valid phone."
			phone_inter 			- "Please enter a valid international phone number."
			url 					- "Please enter a valid url: <br /><span>E.g. http://www.domain.com</span>"
			image					- "This field should only contain image types"
			confirm 				- "This field is different from %0"
			differs 				- "This value must be different of %0"
			length_str 				- "The length is incorrect, it must be between %0 and %1"
			length_fix 				- "The length is incorrect, it must be exactly %0 characters"
			lengthmax 				- "The length is incorrect, it must be at max %0"
			lengthmin 				- "The length is incorrect, it must be at least %0"
			words_min				- "This field must concain at least %0 words, now it has %1 words"
			words_range				- "This field must contain between %0 and %1 words, now it has %2 words"
			words_max				- "This field must contain at max %0 words, now it has %1 words"
			checkbox 				- "Please check the box"
			checkboxes_group		- "Please check at least %0 box(es)"
			radios 					- "Please select a radio"
			select 					- "Please choose a value"

	Example:
		You can initialize a formcheck (no scroll, custom classes and alert) by adding for example this in your html head this code :

		(code)
		<script type="text/javascript">
			window.addEvent('domready', function() {
				var myCheck = new FormCheck('form_id', {
					tipsClass : 'tips_box',
					display : {
						scrollToFirst : false
					},
					alerts : {
						required : 'This field is ablolutely required! Please enter a value'
					}
				})
			});
		</script>
		(end code)

	About:
		formcheck.js v.1.6 for mootools v1.2 - 03 / 2010

		by Mootools.Floor (http://mootools.floor.ch) MIT-style license

		Created by Luca Pillonel (luca-at-nolocation.org),
		Last modified by Luca Pillonel

	Credits:
		This class was inspired by fValidator by Fabio Zendhi Nagao (http://zend.lojcomm.com.br)

		Thanks to all contributors from groups.google.com/group/moofloor (and others as well!) providing ideas, translations, fixes and motivation!
*/

var FormCheck = new Class({

	Implements: [Options, Events],

	options : {

		tipsClass : 'fc-tbx',				//tips error class
		errorClass : 'fc-error',			//div error class
		fieldErrorClass : 'fc-field-error',	//error class for elements

		submit : true,						//false : just validate the form and do nothing else. Use onValidateSuccess event to execute some code
		submitAction: false,				//Action page used to submit the form data to.
		submitMethod: false,				//Method used to submit the form, valid options : 'post' or 'get'

		trimValue : false,					//trim (remove whitespaces before and after) the value
		validateDisabled : false,			//skip validation on disabled input if set to false.

		submitByAjax : false,				//false : standard submit way, true : submit by ajax
		ajaxResponseDiv : false,			//element to inject ajax response into (can also use onAjaxSuccess) [cronix]
		ajaxEvalScripts : false,			//use evalScripts in the Request response [cronix]
		onAjaxRequest : $empty,				//Function to fire when the Request event starts
		onAjaxComplete : $empty,			//Function to fire when the Request is complete, before and regardless of Success or Failure
		onAjaxSuccess : $empty,				//Function to fire when the Request receives .  Args: response [the request response] - see Mootools docs for Request.onSuccess
		onAjaxFailure : $empty,				//Function to fire if the Request fails

		onSubmit		  : $empty,			//Function to fire when user submit the form
		onValidateSuccess : $empty,			//Function to fire when validation pass
		onValidateFailure : $empty,			//Function to fire when validation fails

		display : {
			showErrors : 0,
			titlesInsteadNames : 0,
			errorsLocation : 1,
			indicateErrors : 1,
			indicateErrorsInit : 0,
			keepFocusOnError : 0,
			checkValueIfEmpty : 1,
			addClassErrorToField : 0,
			removeClassErrorOnTipClosure : 0,
			fixPngForIe : 1,
			replaceTipsEffect : 1,
			flashTips : 0,
			closeTipsButton : 1,
			tipsPosition : "right",
			tipsOffsetX : -45,
			tipsOffsetY : 0,
			listErrorsAtTop : false,
			scrollToFirst : true,
			fadeDuration : 300
		},

		alerts : {
			required : "This field is required.",
			alpha : "This field accepts alphabetic characters only.",
			alphanum : "This field accepts alphanumeric characters only.",
			nodigit : "No digits are accepted.",
			digit : "Please enter a valid integer.",
			digitltd : "The value must be between %0 and %1",
			number : "Please enter a valid number.",
			email : "Please enter a valid email.",
			image : 'This field should only contain image types',
			phone : "Please enter a valid phone.",
			phone_inter : "Please enter a valid international phone number.",
			url : "Please enter a valid url.",

			confirm : "This field is different from %0",
			differs : "This value must be different of %0",
			length_str : "The length is incorrect, it must be between %0 and %1",
			length_fix : "The length is incorrect, it must be exactly %0 characters",
			lengthmax : "The length is incorrect, it must be at max %0",
			lengthmin : "The length is incorrect, it must be at least %0",
			words_min : "This field must concain at least %0 words, currently: %1 words",
			words_range : "This field must contain %0-%1 words, currently: %2 words",
			words_max : "This field must contain at max %0 words, currently: %1 words",
			checkbox : "Please check the box",
			checkboxes_group : 'Please check at least %0 box(es)',
			radios : "Please select a radio",
			select : "Please choose a value",
			select_multiple : "Please choose at least one value"
		},

		regexp : {
			required : /[^.*]/,
			alpha : /^[a-z ._-]+$/i,
			alphanum : /^[a-z0-9 ._-]+$/i,
			digit : /^[-+]?[0-9]+$/,
			nodigit : /^[^0-9]+$/,
			number : /^[-+]?\d*\.?\d+$/,
			email : /^([a-zA-Z0-9_\.\-\+%])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/,
			image : /.(jpg|jpeg|png|gif|bmp)$/i,
			phone : /^\+{0,1}[0-9 \(\)\.\-]+$/, // alternate regex : /^[\d\s ().-]+$/,/^((\+\d{1,3}(-| )?\(?\d\)?(-| )?\d{1,5})|(\(?\d{2,6}\)?))(-| )?(\d{3,4})(-| )?(\d{4})(( x| ext)\d{1,5}){0,1}$/
			phone_inter : /^\+{0,1}[0-9 \(\)\.\-]+$/,
			url : /^(http|https|ftp)\:\/\/[a-z0-9\-\.]+\.[a-z]{2,3}(:[a-z0-9]*)?\/?([a-z0-9\-\._\?\,\'\/\\\+&amp;%\$#\=~])*$/i
		}
	},

	/*
	Constructor: initialize
		Constructor

		Add event on formular and perform some stuff, you now, like settings, ...
	*/
	initialize : function(form, options) {
		if (this.form = $(form)) {
			this.form.isValid = true;
			this.regex = ['length'];
			this.groups = {};

			//internalization
			if (typeof(formcheckLanguage) != 'undefined') this.options.alerts = $merge(this.options.alerts, formcheckLanguage);

			this.setOptions(options);

			this.form.setProperty('action',
				this.options.submitAction || this.form.getProperty('action') || 'post');

			this.form.setProperty('method',
				this.options.submitMethod || this.form.getProperty('method') || '');

			this.validations = [];
			this.alreadyIndicated = false;
			this.firstError = false;

			$H(this.options.regexp).each(function(el, key) {
				this.regex.push(key);
			}, this);

			this.form.getElements("*[class*=validate]").each(function(el) {
				this.register(el);
			}, this);

			this.form.addEvents({
				"submit": this.onSubmit.bind(this)
			});

			if(this.options.display.fixPngForIe) this.fixIeStuffs();
			document.addEvent('mousewheel', function(){
				this.isScrolling = false;
			}.bind(this));

			if (this.options.display.indicateErrorsInit) {
				this.validations.each(function(el) {
					if(!this.manageError(el,'submit')) this.form.isValid = false;
				}, this);
			}
		}
	},

	/*
	Function: register
		Allows you to declare afterward new fields to the formcheck, to check dynamically loaded fields for example.
		By default it will be the last element to be validated as it's added after others inputs, but you can define a position with second parameter.

	Example:
		(code)
		<script type="text/javascript">
			window.addEvent('domready', function() {
				formcheck = new FormCheck('form_id');
			});

			// ...some code...

			var newField = new Element('input', {
				class	: "validate['required']",
				name	: "new-field"
			}).inject('form_id');
			formcheck.register(newField, 3);

			new Element('input', {
				class	: "validate['required']",
				name	: "another-field",
				id		: "another-field"
			}).inject('form_id');
			formcheck.register($('another-field'));
		</script>
		(end code)

	See also:
		<FormCheck::dispose>
	*/
	register : function(el, position) {
		el.validation = [];
		el.getProperty("class").split(' ').each(function(classX) {
			if (classX.match(/^validate(\[.+\])$/)) {
				var valid = true;

				var validators = eval(classX.match(/^validate(\[.+\])$/)[1]);
				for(var i = 0; i < validators.length; i++) {
					el.validation.push(validators[i]);
					if (validators[i].match(/^confirm:/)) {
						var field = validators[i].match(/.+:(.+)$/)[1];
						if (this.form[field].validation.contains('required')) el.validation.push('required');
					}
					if (validators[i].match(/^target:.+/)) {
						el.target = validators[i].match(/^target:(.+)/)[1];
					}
				}

				//we check if group is already registered
				el.isChild = this.isChildType(el, validators);
				if (el.isChild && el.type == 'radio') {
					this.validations.each(function(registeredEl){
						if (registeredEl.name == el.name) valid = false;
					}, this);
				}
				if (el.isChild && el.type == 'checkbox') {
					this.validations.each(function(registeredEl){
						if (registeredEl.groupID == el.groupID) valid = false;
					}, this);
				}

				if (position && position <= this.validations.length) {
					var newValidations = [];
					this.validations.each(function(valider, i){
						if (position == i+1 && valid) {
							newValidations.push(el);
							this.addListener(el);
						}
						newValidations.push(valider);
					}, this);
					this.validations = newValidations;
				} else if (valid) {
					this.validations.push(el);
					this.addListener(el);
				}
			}
		}, this);
	},

	/*
	Function: dispose
		Allows you to remove a declared field from formCheck

	Example:
		(code)
		<script type="text/javascript">
			window.addEvent('domready', function() {
				formcheck = new FormCheck('form_id');
			});

			// ...some code...

			formcheck.dispose($('obsolete-field'));
		</script>
		(end code)

	See also:
		<FormCheck::register>
	*/
	dispose : function(element) {
		this.validations.erase(element);
	},

	/*
	Function: addListener
		Private method

		Add listener on fields
	*/
	addListener : function(el) {
		el.errors = [];

		if (el.validation[0] == 'submit') {
			el.addEvent('click', function(e){
				new Event(e).stop();
				if (this.onSubmit(e)) this.form.submit();
			}.bind(this));
			return true;
		}

		if (!el.isChild) {
			el.addEvent('blur', function() {
				if(!this.fxRunning && (el.element || this.options.display.showErrors == 1) && (this.options.display.checkValueIfEmpty || el.value)) this.manageError(el, 'blur');
			}.bind(this));
		//We manage errors on radio
		} else if(el.isChild && el.type == 'radio') {
			//We get all radio from the same group and add a blur option
			var radioGroup = this.form.getElements('input[name="'+ el.getProperty("name") +'"]');
			radioGroup.each(function(radio){
				radio.addEvent('blur', function(){
					if(!this.fxRunning && (el.element || this.options.display.showErrors == 1) && (this.options.display.checkValueIfEmpty || el.value)) this.manageError(el, 'click');
				}.bind(this));
			},this);
		}
	},

	/*
	Function: manageError
		Private method

		Manage display of errors boxes
	*/
	manageError : function(el, method) {
		var isValid = this.validate(el);
		if (method == 'testonly') return isValid;
		if ((!isValid && el.validation.contains('required')) || (el.value && !isValid)) {
			if(this.options.display.listErrorsAtTop && method == 'submit') this.listErrorsAtTop(el);
			if (this.options.display.indicateErrors == 2 ||this.alreadyIndicated == false || el == this.alreadyIndicated) {
				if(!this.firstError) this.firstError = el;
				this.alreadyIndicated = el;

				if (this.options.display.keepFocusOnError && el == this.firstError) {
					(function(){el.focus()}).delay(10);
				}
				this.addError(el);
				return false;
			}
		} else if ((isValid || (!el.validation.contains('required') && !el.value))) {
			this.removeError(el);
			return true;
		}
		return true;
	},

	/*
	Function: validate
		Private method

		Dispatch check to other methods
	*/
	validate : function(el) {
		el.errors = [];
		el.isOk = true;

		//skip validation for disabled fields and trim if specified
		if (!this.options.validateDisabled && el.get('disabled')) return true;
		if (this.options.trimValue && el.value) el.value = el.value.trim();

		el.validation.each(function(rule) {
			if(el.isChild) {
				if (!this.validateGroup(el)) el.isOk = false;
			} else {
				var ruleArgs = [];

				if(rule.match(/target:.+/)) return;
				var ruleMethod = rule;
				if(rule.match(/^.+\[/)) {
					ruleMethod = rule.split('[')[0];
					ruleArgs = eval(rule.match(/^.+(\[.+\])$/)[1].replace(/([A-Z0-9\._-]+)/i, "'$1'"));
				}

				if (this.regex.contains(ruleMethod) && el.get('tag') != "select") {
					if (this.validateRegex(el, ruleMethod, ruleArgs) == false) {
						el.isOk = false;
					}
				}
				if (rule.match(/confirm:.+/)) {
					ruleArgs = [rule.match(/.+:(.+)$/)[1]];
					if (this.validateConfirm(el, ruleArgs) == false) {
						el.isOk = false;
					}
				}
				if (rule.match(/differs:.+/)) {
					ruleArgs = [rule.match(/.+:(.+)$/)[1]];
					if (this.validateDiffers(el, ruleArgs) == false) {
						el.isOk = false;
					}
				}
				if (ruleMethod == 'words') {
					if (this.validateWords(el, ruleArgs) == false) {
						el.isOk = false;
					}
				}
				if (ruleMethod == 'required' && (el.get('tag') == "select" || el.type == "checkbox")) {
					if (this.simpleValidate(el) == false) {
						el.isOk = false;
					}
				}
				if(rule.match(/%[A-Z0-9\._-]+$/i) || (el.isOk && rule.match(/~[A-Z0-9\._-]+$/i))) {
					if(eval(rule.slice(1)+'(el)') == false) {
						el.isOk = false;
					}
				}
			}
		}, this);
		return ( el.isOk ) ? true : false;
	},

	/*
	Function: simpleValidate
		Private method

		Perform simple check for select fields and checkboxes
	*/
	simpleValidate : function(el) {
		if(el.get('tag') == 'select'){
			if(!el.multiple) {
				if(el.selectedIndex <= 0) {
					el.errors.push(this.options.alerts.select);
					return false;
				}
			} else {
				var selected = false;
				el.getChildren('option').each(function(el){
					if(el.selected) selected = true;
				});

				if(!selected){
					el.errors.push(this.options.alerts.select_multiple);
					return false;
				}
			}
		} else if (el.type == "checkbox" && el.checked == false) {
			el.errors.push(this.options.alerts.checkbox);
			return false;
		}
		return true;
	},

	/*
	Function: validateRegex
		Private method

		Perform regex validations
	*/
	validateRegex : function(el, ruleMethod, ruleArgs) {
		var msg = "";
		if (ruleMethod == 'length' && ruleArgs[1]) {
			if (ruleArgs[1] == -1) {
				this.options.regexp.length = new RegExp("^[\\s\\S]{"+ ruleArgs[0] +",}$");
				msg = this.options.alerts.lengthmin.replace("%0",ruleArgs[0]);
			} else if(ruleArgs[0] == ruleArgs[1]) {
				this.options.regexp.length = new RegExp("^[\\s\\S]{"+ ruleArgs[0] +"}$");
				msg = this.options.alerts.length_fix.replace("%0",ruleArgs[0]);
			} else {
				this.options.regexp.length = new RegExp("^[\\s\\S]{"+ ruleArgs[0] +","+ ruleArgs[1] +"}$");
				msg = this.options.alerts.length_str.replace("%0",ruleArgs[0]).replace("%1",ruleArgs[1]);
			}
		} else if (ruleArgs[0] && ruleMethod == 'length') {
			this.options.regexp.length = new RegExp("^.{0,"+ ruleArgs[0] +"}$");
			msg = this.options.alerts.lengthmax.replace("%0",ruleArgs[0]);
		} else {
			msg = this.options.alerts[ruleMethod];
		}
		if ((ruleMethod == 'digit' || ruleMethod == 'number') && ruleArgs[1]) {
			var valueres, regres = true;
			if (!this.options.regexp[ruleMethod].test(el.value)) {
				el.errors.push(this.options.alerts[ruleMethod]);
				regres = false;
			}
			if (ruleArgs[1] == -1) {
				valueres = ( el.value.toFloat() >= ruleArgs[0].toFloat() );
				msg = this.options.alerts.digitmin.replace("%0",ruleArgs[0]);
			} else {
				valueres = ( el.value.toFloat() >= ruleArgs[0].toFloat() && el.value.toFloat() <= ruleArgs[1].toFloat() );
				msg = this.options.alerts.digitltd.replace("%0",ruleArgs[0]).replace("%1",ruleArgs[1]);
			}
			if (regres == false || valueres == false) {
				el.errors.push(msg);
				return false;
			}
		} else if (this.options.regexp[ruleMethod].test(el.value) == false)  {
			el.errors.push(msg);
			return false;
		}
		return true;
	},

	/*
	Function: validateConfirm
		Private method

		Perform confirm validations
	*/
	validateConfirm: function(el,ruleArgs) {
		var confirm = ruleArgs[0];
		if(el.value != this.form[confirm].value){
			var msg = ( this.options.display.titlesInsteadNames ) ?
				this.options.alerts.confirm.replace("%0",this.form[confirm].getProperty('title')) :
				this.options.alerts.confirm.replace("%0",confirm);
			el.errors.push(msg);
			return false;
		}
		return true;
	},

	/*
	Function: validateDiffers
		Private method

		Perform differs validations
	*/
	validateDiffers: function(el,ruleArgs) {
		var differs = ruleArgs[0];
		if(el.value == this.form[differs].value){
			var msg = ( this.options.display.titlesInsteadNames ) ?
				this.options.alerts.differs.replace("%0",this.form[differs].getProperty('title')) :
				this.options.alerts.differs.replace("%0",differs);
			el.errors.push(msg);
			return false;
		}
		return true;
	},

	/*
	Function: validateWords
		Private method

		Perform word count validation
	*/
	validateWords: function(el,ruleArgs) {
		var min = ruleArgs[0];
		var max = ruleArgs[1];

		var words = el.value.replace(/[ \t\v\n\r\f\p]/m, ' ').replace(/[,.;:]/g, ' ').clean().split(' ');

		if(max == -1) {
			if(words.length < min) {
				el.errors.push(this.options.alerts.words_min.replace("%0", min).replace("%1", words.length));
				return false;
			}
		} else {
			if(min > 0)	{
				if(words.length < min || words.length > max) {
					el.errors.push(this.options.alerts.words_range.replace("%0", min).replace("%1", max).replace("%2", words.length));
					return false;
				}
			} else {
				if(words.length > max) {
					el.errors.push(this.options.alerts.words_max.replace("%0", max).replace("%1", words.length));
					return false;
				}
			}
		}
		return true;
	},


	/*
	Function: isFormValid
		public method

		Determine if the form is valid

		Return true or false
	*/
    isFormValid: function() {
		this.form.isValid = true;
		this.validations.each(function(el) {
			var validation = this.manageError(el,'testonly');
			if(!validation) this.form.isValid = false;
		}, this);
		return this.form.isValid;
	},

	/*
	Function: isChildType
		Private method

		Determine if the field is a group of radio, of checkboxes or not.
	*/
	isChildType: function(el, validators) {
		var validator;
		if($defined(el.type) && el.type == 'radio') {
			return true;
		} else if(validator = validators.join().match(/group(\[.*\])/)) {
			var group = eval(validator[1]);
			this.groups[group[0]] = this.groups[group[0]] || [];
			this.groups[group[0]][0] = this.groups[group[0]][0] || [];
			this.groups[group[0]][1] = group[1] || this.groups[group[0]][1] || 1;
			this.groups[group[0]][0].push(el);
			el.groupID = group[0];
			return true;
		}
		return false;
	},

	/*
	Function: validateGroup
		Private method

		Perform radios validations
	*/
	validateGroup : function(el) {
		el.errors = [];
		if(el.type == 'radio') {
			var nlButtonGroup = this.form[el.getProperty("name")];
			el.group = nlButtonGroup;
			var cbCheckeds = false;

			for(var i = 0; i < nlButtonGroup.length; i++) {
				if(nlButtonGroup[i].checked) {
					cbCheckeds = true;
				}
			}
			if(cbCheckeds == false) {
				el.errors.push(this.options.alerts.radios);
				return false;
			} else {
				return true;
			}
		// we have group of checkboxes
		} else if(el.type == 'checkbox') {
			//we get length of checked elements
			var checked = 0;
			this.groups[el.groupID][0].each(function(groupEl){
				if(groupEl.checked) checked++;
			});
			if(checked >= this.groups[el.groupID][1]) {
				return true;
			} else {
				( this.groups[el.groupID][0].length > 1 ) ?
					el.errors.push(this.options.alerts.checkboxes_group.replace('%0', this.groups[el.groupID][1])) :
					el.errors.push(this.options.alerts.checkbox);
				return false;
			}
		// we have unmanaged type
		} else {
			return false;
		}
	},

	/*
	Function: listErrorsAtTop
		Private method

		Display errors
	*/
	listErrorsAtTop : function(obj) {
		if(!this.form.element) {
			 this.form.element = new Element('div', {'id' : 'errorlist', 'class' : this.options.errorClass}).injectTop(this.form);
		}
		if ($type(obj) == 'collection') {
			new Element('p').set('html',"<span>" + obj[0].name + " : </span>" + obj[0].errors[0]).injectInside(this.form.element);
		} else {
			if ((obj.validation.contains('required') && obj.errors.length > 0) || (obj.errors.length > 0 && obj.value && obj.validation.contains('required') == false)) {
				obj.errors.each(function(error) {
					new Element('p').set('html',"<span>" + obj.name + " : </span>" + error).injectInside(this.form.element);
				}, this);
			}
		}
		window.fireEvent('resize');
	},

	/*
	Function: addError
		Private method

		Add error message
	*/
	addError : function(obj) {
	  var buttons = this.form.getElements('input[type=submit]');
    buttons.each(function(b){ b.addClass('disabled'); });
    
		//determine position
		var coord = obj.target ? $(obj.target).getCoordinates() : obj.getCoordinates();

		if(!obj.element && this.options.display.indicateErrors != 0) {
			if (this.options.display.errorsLocation == 1) {
				var pos = (this.options.display.tipsPosition == 'left') ? coord.left : coord.right;
				var options = {
					'opacity' : 0,
					'position' : 'absolute',
					'float' : 'left',
					'left' : pos + this.options.display.tipsOffsetX
				};
				obj.element = new Element('div', {'class' : this.options.tipsClass, 'styles' : options}).injectInside(document.body);
				this.addPositionEvent(obj);
			} else if (this.options.display.errorsLocation == 2){
				obj.element = new Element('div', {'class' : this.options.errorClass, 'styles' : {'opacity' : 0}}).injectBefore(obj);
			} else if (this.options.display.errorsLocation == 3){
				obj.element = new Element('div', {'class' : this.options.errorClass, 'styles' : {'opacity' : 0}});
				if ($type(obj.group) == 'object' || $type(obj.group) == 'collection')
					obj.element.injectAfter(obj.group[obj.group.length-1]);
				else
					obj.element.injectAfter(obj);
			}
		}
		if (obj.element && obj.element != true) {
			obj.element.empty();
			if (this.options.display.errorsLocation == 1) {
				var errors = [];
				obj.errors.each(function(error) {
					errors.push(new Element('p').set('html', error));
				});
				var tips = this.makeTips(errors).injectInside(obj.element);
				if(this.options.display.closeTipsButton) {
					tips.getElements('a.close').addEvent('mouseup', function(){
						this.removeError(obj, 'tip');
					}.bind(this));
				}
				obj.element.setStyle('top', coord.top - tips.getCoordinates().height + this.options.display.tipsOffsetY);
			} else {
				obj.errors.each(function(error) {
					new Element('p').set('html',error).injectInside(obj.element);
				});
			}

			if (!this.options.display.fadeDuration || Browser.Engine.trident && Browser.Engine.version == 5 && this.options.display.errorsLocation < 2) {
				obj.element.setStyle('opacity', 1);
			} else {
				obj.fx = new Fx.Tween(obj.element, {
					'duration' : this.options.display.fadeDuration,
					'ignore' : true,
					'onStart' : function(){
						this.fxRunning = true;
					}.bind(this),
					'onComplete' : function() {
						this.fxRunning = false;
						if (obj.element && obj.element.getStyle('opacity').toInt() == 0) {
							obj.element.destroy();
							obj.element = false;
						}
					}.bind(this)
				});
				if(obj.element.getStyle('opacity').toInt() != 1) obj.fx.start('opacity', 1);
			}
		}
		if (this.options.display.addClassErrorToField && !obj.isChild){
			obj.addClass(this.options.fieldErrorClass);
			obj.element = obj.element || true;
		}

	},

	/*
	Function: addPositionEvent

		Update tips position after a browser resize
	*/
	addPositionEvent : function(obj) {
		if(this.options.display.replaceTipsEffect) {
			obj.event = function(){
				var coord = obj.target ? $(obj.target).getCoordinates() : obj.getCoordinates();
				new Fx.Morph(obj.element, {
					'duration' : this.options.display.fadeDuration
				}).start({
					'left':[obj.element.getStyle('left'), coord.right + this.options.display.tipsOffsetX],
					'top':[obj.element.getStyle('top'), coord.top - obj.element.getCoordinates().height + this.options.display.tipsOffsetY]
				});
			}.bind(this);

		} else {
			obj.event = function(){
				var coord = obj.target ? $(obj.target).getCoordinates() : obj.getCoordinates();
				obj.element.setStyles({
					'left':coord.right + this.options.display.tipsOffsetX,
					'top':coord.top - obj.element.getCoordinates().height + this.options.display.tipsOffsetY
				});
			}.bind(this);
		}
		window.addEvent('resize', obj.event);
	},

	/*
	Function: removeError
		Private method

		Remove the error display
	*/
	removeError : function(obj, method) {
	  var buttons = this.form.getElements('input[type=submit]');
    buttons.each(function(b){ b.removeClass('disabled'); });
    
		if ((this.options.display.addClassErrorToField && !obj.isChild && this.options.display.removeClassErrorOnTipClosure) || (this.options.display.addClassErrorToField && !obj.isChild && !this.options.display.removeClassErrorOnTipClosure && method != 'tip'))
			obj.removeClass(this.options.fieldErrorClass);

		if (!obj.element) return;
		this.alreadyIndicated = false;
		obj.errors = [];
		obj.isOK = true;
		window.removeEvent('resize', obj.event);
		if (this.options.display.errorsLocation >= 2 && obj.element) {
			new Fx.Tween(obj.element, {
				'duration': this.options.display.fadeDuration
			}).start('height', 0);
		}
		if (!this.options.display.fadeDuration || Browser.Engine.trident && Browser.Engine.version == 5 && this.options.display.errorsLocation == 1 && obj.element) {
			this.fxRunning = true;
			obj.element.destroy();
			obj.element = false;
			(function(){this.fxRunning = false}.bind(this)).delay(200);
		} else if (obj.element && obj.element != true) {
			obj.fx.start('opacity', 0);
		}
	},

	/*
	Function: focusOnError
		Private method

		Create set the focus to the first field with an error if needed
	*/
	focusOnError : function (obj) {
		if (this.options.display.scrollToFirst && !this.alreadyFocused && !this.isScrolling) {
			var dest; //moved this up to stop redclariations
			//This can changed to a single switch using default:
			if (!this.options.display.indicateErrors || !this.options.display.errorsLocation) {
				dest = obj.getCoordinates().top-30;
			} else {
				switch (this.options.display.errorsLocation){
					case 1 :
						dest = obj.element.getCoordinates().top;
						break;
					case 2 :
						dest = obj.element.getCoordinates().top-30;
						break;
					case 3 :
						dest = obj.getCoordinates().top-30;
						break;
				}
				this.isScrolling = true;
			}
			if (window.getScroll().y != dest) {
				new Fx.Scroll(window, {
					onComplete : function() {
						this.isScrolling = false;
						if (obj.getProperty('type') != 'hidden') obj.focus();
					}.bind(this)
				}).start(0,dest);
			} else {
				this.isScrolling = false;
				obj.focus();
			}
			this.alreadyFocused = true;
		}
	},

	/*
	Function: fixIeStuffs
		Private method

		Fix png for IE6
	*/
	fixIeStuffs : function () {
		if (Browser.Engine.trident4) {
			//We fix png stuffs
			var rpng = new RegExp('url\\(([\.a-zA-Z0-9_/:-]+\.png)\\)');
			var search = new RegExp('(.+)formcheck\.css');
			for (var i = 0; i < document.styleSheets.length; i++){
				if (document.styleSheets[i].href.match(/formcheck\.css$/)) {
					var root = document.styleSheets[i].href.replace(search, '$1');
					var count = document.styleSheets[i].rules.length;
					for (var j = 0; j < count; j++){
						var cssstyle = document.styleSheets[i].rules[j].style;
						var bgimage = root + cssstyle.backgroundImage.replace(rpng, '$1');
						if (bgimage && bgimage.match(/\.png/i)){
							var scale = (cssstyle.backgroundRepeat == 'no-repeat') ? 'crop' : 'scale';
							cssstyle.filter =  'progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, src=\'' + bgimage + '\', sizingMethod=\''+ scale +'\')';
							cssstyle.backgroundImage = "none";
						}
					}
				}
			}
		}
	},

	/*
	Function: makeTips
		Private method

		Create tips boxes
	*/
	makeTips : function(txt) {
		var table = new Element('table');
			table.cellPadding ='0';
			table.cellSpacing ='0';
			table.border ='0';

			var tbody = new Element('tbody').injectInside(table);
				var tr1 = new Element('tr').injectInside(tbody);
					new Element('td', {'class' : 'tl'}).injectInside(tr1);
					new Element('td', {'class' : 't'}).injectInside(tr1);
					new Element('td', {'class' : 'tr'}).injectInside(tr1);
				var tr2 = new Element('tr').injectInside(tbody);
					new Element('td', {'class' : 'l'}).injectInside(tr2);
					var cont = new Element('td', {'class' : 'c'}).injectInside(tr2);
						var errors = new Element('div', {'class' : 'err'}).injectInside(cont);
						txt.each(function(error) {
							error.injectInside(errors);
						});
						if (this.options.display.closeTipsButton) new Element('a',{'class' : 'close'}).injectInside(cont);
					new Element('td', {'class' : 'r'}).injectInside(tr2);
				var tr3 = new Element('tr').injectInside(tbody);
					new Element('td', {'class' : 'bl'}).injectInside(tr3);
					new Element('td', {'class' : 'b'}).injectInside(tr3);
					new Element('td', {'class' : 'br'}).injectInside(tr3);
		return table;
	},

	/*
	Function: reinitialize
		Reinitialize form before submit check. You can use this also to remove all tips from a form, passing the argument "forced" ( formcheck.reinitialize('forced'); )
	*/
	reinitialize: function(forced) {
		this.validations.each(function(el) {
			if (el.element) {
				el.errors = [];
				el.isOK = true;
				if(this.options.display.flashTips == 1 || forced == 'forced') {
					el.element.destroy();
					el.element = false;
				}
			}
		}, this);
		if (this.form.element) this.form.element.empty();
		this.alreadyFocused = false;
		this.firstError = false;
		this.elementToRemove = this.alreadyIndicated;
		this.alreadyIndicated = false;
		this.form.isValid = true;
	},

	/*
	Function: submitByAjax
		Private method

		Send the form by ajax, and replace the form with response
	*/

	submitByAjax: function() {
		this.fireEvent('ajaxRequest');
		new Request({
			url: this.form.action,
			method: this.form.method,
			data : this.form.toQueryString(),
			evalScripts: this.options.ajaxEvalScripts,
			onFailure: function(instance){
				this.fireEvent('ajaxFailure', instance);
			}.bind(this),
			onComplete: function(instance){
				this.fireEvent('ajaxComplete', instance);
			}.bind(this),
			onSuccess: function(result){
				this.fireEvent('ajaxSuccess', result);
				if(this.options.ajaxResponseDiv) $(this.options.ajaxResponseDiv).set('html',result);
			}.bind(this)
		}).send();
		return false;
	},

	/*
	Function: onSubmit
		Private method

		Perform check on submit action
	*/
	onSubmit: function(event) {
		this.reinitialize();
		this.fireEvent('onSubmit');
		
		this.validations.each(function(el) {
			var validation = this.manageError(el,'submit');
			if(!validation) this.form.isValid = false;
		}, this);

		if (this.form.isValid) {
			this.fireEvent('validateSuccess');
			//moved above to allow optional settings to this.form.submit and submitByAjax to be triggered by this option
			return (this.options.submitByAjax)? this.submitByAjax():this.options.submit;
			//if this.options.submit is false it can still rely on validateSuccess event
		} else {
			if (this.elementToRemove && this.elementToRemove != this.firstError && this.options.display.indicateErrors == 1) {
				this.removeError(this.elementToRemove);
			}
			this.focusOnError(this.firstError);
			this.fireEvent('validateFailure');
			return false;
		}
	}
});

/**
 * Autocompleter
 *
 * http://digitarald.de/project/autocompleter/
 *
 * @version		1.1.2
 *
 * @license		MIT-style license
 * @author		Harald Kirschner <mail [at] digitarald.de>
 * @copyright	Author
 */

var Autocompleter = new Class({

	Implements: [Options, Events],

	options: {/*
		onOver: $empty,
		onSelect: $empty,
		onSelection: $empty,
		onShow: $empty,
		onHide: $empty,
		onBlur: $empty,
		onFocus: $empty,*/
		minLength: 1,
		markQuery: true,
		width: 'inherit',
		maxChoices: 10,
		injectChoice: null,
		customChoices: null,
		emptyChoices: null,
		visibleChoices: true,
		className: 'autocompleter-choices',
		zIndex: 42,
		delay: 400,
		observerOptions: {},
		fxOptions: {},

		autoSubmit: false,
		overflow: false,
		overflowMargin: 25,
		selectFirst: false,
		filter: null,
		filterCase: false,
		filterSubset: false,
		forceSelect: false,
		selectMode: true,
		choicesMatch: null,

		multiple: false,
		separator: ', ',
		separatorSplit: /\s*[,;]\s*/,
		autoTrim: false,
		allowDupes: false,

		cache: true,
		relative: false
	},

	initialize: function(element, options) {
		this.element = $(element);
		this.setOptions(options);
		this.build();
		this.observer = new Observer(this.element, this.prefetch.bind(this), $merge({
			'delay': this.options.delay
		}, this.options.observerOptions));
		this.queryValue = null;
		if (this.options.filter) this.filter = this.options.filter.bind(this);
		var mode = this.options.selectMode;
		this.typeAhead = (mode == 'type-ahead');
		this.selectMode = (mode === true) ? 'selection' : mode;
		this.cached = [];
	},

	/**
	 * build - Initialize DOM
	 *
	 * Builds the html structure for choices and appends the events to the element.
	 * Override this function to modify the html generation.
	 */
	build: function() {
		if ($(this.options.customChoices)) {
			this.choices = this.options.customChoices;
		} else {
			this.choices = new Element('ul', {
				'class': this.options.className,
				'styles': {
					'zIndex': this.options.zIndex
				}
			}).inject(document.body);
			this.relative = false;
			if (this.options.relative) {
				this.choices.inject(this.element, 'after');
				this.relative = this.element.getOffsetParent();
			}
			this.fix = new OverlayFix(this.choices);
		}
		if (!this.options.separator.test(this.options.separatorSplit)) {
			this.options.separatorSplit = this.options.separator;
		}
		this.fx = (!this.options.fxOptions) ? null : new Fx.Tween(this.choices, $merge({
			'property': 'opacity',
			'link': 'cancel',
			'duration': 200
		}, this.options.fxOptions)).addEvent('onStart', Chain.prototype.clearChain).set(0);
		this.element.setProperty('autocomplete', 'off')
			.addEvent((Browser.Engine.trident || Browser.Engine.webkit) ? 'keydown' : 'keypress', this.onCommand.bind(this))
			.addEvent('click', this.onCommand.bind(this, [false]))
			.addEvent('focus', this.toggleFocus.create({bind: this, arguments: true, delay: 100}))
			.addEvent('blur', this.toggleFocus.create({bind: this, arguments: false, delay: 100}));
	},

	destroy: function() {
		if (this.fix) this.fix.destroy();
		this.choices = this.selected = this.choices.destroy();
	},

	toggleFocus: function(state) {
		this.focussed = state;
		if (!state) this.hideChoices(true);
		this.fireEvent((state) ? 'onFocus' : 'onBlur', [this.element]);
	},

	onCommand: function(e) {
		if (!e && this.focussed) return this.prefetch();
		if (e && e.key && !e.shift) {
			switch (e.key) {
				case 'enter':
					if (this.element.value != this.opted) return true;
					if (this.selected && this.visible) {
						this.choiceSelect(this.selected);
						return !!(this.options.autoSubmit);
					}
					break;
				case 'up': case 'down':
					if (!this.prefetch() && this.queryValue !== null) {
						var up = (e.key == 'up');
						this.choiceOver((this.selected || this.choices)[
							(this.selected) ? ((up) ? 'getPrevious' : 'getNext') : ((up) ? 'getLast' : 'getFirst')
						](this.options.choicesMatch), true);
					}
					return false;
				case 'esc': case 'tab':
					this.hideChoices(true);
					break;
			}
		}
		return true;
	},

	setSelection: function(finish) {
		var input = this.selected.inputValue, value = input;
		var start = this.queryValue.length, end = input.length;
		if (input.substr(0, start).toLowerCase() != this.queryValue.toLowerCase()) start = 0;
		if (this.options.multiple) {
			var split = this.options.separatorSplit;
			value = this.element.value;
			start += this.queryIndex;
			end += this.queryIndex;
			var old = value.substr(this.queryIndex).split(split, 1)[0];
			value = value.substr(0, this.queryIndex) + input + value.substr(this.queryIndex + old.length);
			if (finish) {
				var tokens = value.split(this.options.separatorSplit).filter(function(entry) {
					return this.test(entry);
				}, /[^\s,]+/);
				if (!this.options.allowDupes) tokens = [].combine(tokens);
				var sep = this.options.separator;
				value = tokens.join(sep) + sep;
				end = value.length;
			}
		}
		this.observer.setValue(value);
		this.opted = value;
		if (finish || this.selectMode == 'pick') start = end;
		this.element.selectRange(start, end);
		this.fireEvent('onSelection', [this.element, this.selected, value, input]);
	},

	showChoices: function() {
		var match = this.options.choicesMatch, first = this.choices.getFirst(match);
		this.selected = this.selectedValue = null;
		if (this.fix) {
			var pos = this.element.getCoordinates(this.relative), width = this.options.width || 'auto';
			this.choices.setStyles({
				'left': pos.left,
				'top': pos.bottom,
				'width': (width === true || width == 'inherit') ? pos.width : width
			});
		}
		if (!first) return;
		if (!this.visible) {
			this.visible = true;
			this.choices.setStyle('display', '');
			if (this.fx) this.fx.start(1);
			this.fireEvent('onShow', [this.element, this.choices]);
		}
		if (this.options.selectFirst || this.typeAhead || first.inputValue == this.queryValue) this.choiceOver(first, this.typeAhead);
		var items = this.choices.getChildren(match), max = this.options.maxChoices;
		var styles = {'overflowY': 'hidden', 'height': ''};
		this.overflown = false;
		if (items.length > max) {
			var item = items[max - 1];
			styles.overflowY = 'scroll';
			styles.height = item.getCoordinates(this.choices).bottom;
			this.overflown = true;
		};
		this.choices.setStyles(styles);
		this.fix.show();
		if (this.options.visibleChoices) {
			var scroll = document.getScroll(),
			size = document.getSize(),
			coords = this.choices.getCoordinates();
			if (coords.right > scroll.x + size.x) scroll.x = coords.right - size.x;
			if (coords.bottom > scroll.y + size.y) scroll.y = coords.bottom - size.y;
			window.scrollTo(Math.min(scroll.x, coords.left), Math.min(scroll.y, coords.top));
		}
	},

	hideChoices: function(clear) {
		if (clear) {
			var value = this.element.value;
			if (this.options.forceSelect) value = this.opted;
			if (this.options.autoTrim) {
				value = value.split(this.options.separatorSplit).filter($arguments(0)).join(this.options.separator);
			}
			this.observer.setValue(value);
		}
		if (!this.visible) return;
		this.visible = false;
		if (this.selected) this.selected.removeClass('autocompleter-selected');
		this.observer.clear();
		var hide = function(){
			this.choices.setStyle('display', 'none');
			this.fix.hide();
		}.bind(this);
		if (this.fx) this.fx.start(0).chain(hide);
		else hide();
		this.fireEvent('onHide', [this.element, this.choices]);
	},

	prefetch: function() {
		var value = this.element.value, query = value;
		if (this.options.multiple) {
			var split = this.options.separatorSplit;
			var values = value.split(split);
			var index = this.element.getSelectedRange().start;
			var toIndex = value.substr(0, index).split(split);
			var last = toIndex.length - 1;
			index -= toIndex[last].length;
			query = values[last];
		}
		if (query.length < this.options.minLength) {
			this.hideChoices();
		} else {
			if (query === this.queryValue || (this.visible && query == this.selectedValue)) {
				if (this.visible) return false;
				this.showChoices();
			} else {
				this.queryValue = query;
				this.queryIndex = index;
				if (!this.fetchCached()) this.query();
			}
		}
		return true;
	},

	fetchCached: function() {
		return false;
		if (!this.options.cache
			|| !this.cached
			|| !this.cached.length
			|| this.cached.length >= this.options.maxChoices
			|| this.queryValue) return false;
		this.update(this.filter(this.cached));
		return true;
	},

	update: function(tokens) {
		this.choices.empty();
		this.cached = tokens;
		var type = tokens && $type(tokens);
		if (!type || (type == 'array' && !tokens.length) || (type == 'hash' && !tokens.getLength())) {
			(this.options.emptyChoices || this.hideChoices).call(this);
		} else {
			if (this.options.maxChoices < tokens.length && !this.options.overflow) tokens.length = this.options.maxChoices;
			tokens.each(this.options.injectChoice || function(token){
				var choice = new Element('li', {'html': this.markQueryValue(token)});
				choice.inputValue = token;
				this.addChoiceEvents(choice).inject(this.choices);
			}, this);
			this.showChoices();
		}
	},

	choiceOver: function(choice, selection) {
		if (!choice || choice == this.selected) return;
		if (this.selected) this.selected.removeClass('autocompleter-selected');
		this.selected = choice.addClass('autocompleter-selected');
		this.fireEvent('onSelect', [this.element, this.selected, selection]);
		if (!this.selectMode) this.opted = this.element.value;
		if (!selection) return;
		this.selectedValue = this.selected.inputValue;
		if (this.overflown) {
			var coords = this.selected.getCoordinates(this.choices), margin = this.options.overflowMargin,
				top = this.choices.scrollTop, height = this.choices.offsetHeight, bottom = top + height;
			if (coords.top - margin < top && top) this.choices.scrollTop = Math.max(coords.top - margin, 0);
			else if (coords.bottom + margin > bottom) this.choices.scrollTop = Math.min(coords.bottom - height + margin, bottom);
		}
		if (this.selectMode) this.setSelection();
	},

	choiceSelect: function(choice) {
		if (choice) this.choiceOver(choice);
		this.setSelection(true);
		this.queryValue = false;
		this.hideChoices();
	},

	filter: function(tokens) {
		return (tokens || this.tokens).filter(function(token) {
			return this.test(token);
		}, new RegExp(((this.options.filterSubset) ? '' : '^') + this.queryValue.escapeRegExp(), (this.options.filterCase) ? '' : 'i'));
	},

	/**
	 * markQueryValue
	 *
	 * Marks the queried word in the given string with <span class="autocompleter-queried">*</span>
	 * Call this i.e. from your custom parseChoices, same for addChoiceEvents
	 *
	 * @param		{String} Text
	 * @return		{String} Text
	 */
	markQueryValue: function(str) {
		return (!this.options.markQuery || !this.queryValue) ? str
			: str.replace(new RegExp('(' + ((this.options.filterSubset) ? '' : '^') + this.queryValue.escapeRegExp() + ')', (this.options.filterCase) ? '' : 'i'), '<span class="autocompleter-queried">$1</span>');
	},

	/**
	 * addChoiceEvents
	 *
	 * Appends the needed event handlers for a choice-entry to the given element.
	 *
	 * @param		{Element} Choice entry
	 * @return		{Element} Choice entry
	 */
	addChoiceEvents: function(el) {
		return el.addEvents({
			'mouseover': this.choiceOver.bind(this, [el]),
			'click': this.choiceSelect.bind(this, [el])
		});
	}
});

var OverlayFix = new Class({

	initialize: function(el) {
		if (Browser.Engine.trident) {
			this.element = $(el);
			this.relative = this.element.getOffsetParent();
			this.fix = new Element('iframe', {
				'frameborder': '0',
				'scrolling': 'no',
				'src': 'javascript:false;',
				'styles': {
					'position': 'absolute',
					'border': 'none',
					'display': 'none',
					'filter': 'progid:DXImageTransform.Microsoft.Alpha(opacity=0)'
				}
			}).inject(this.element, 'after');
		}
	},

	show: function() {
		if (this.fix) {
			var coords = this.element.getCoordinates(this.relative);
			delete coords.right;
			delete coords.bottom;
			this.fix.setStyles($extend(coords, {
				'display': '',
				'zIndex': (this.element.getStyle('zIndex') || 1) - 1
			}));
		}
		return this;
	},

	hide: function() {
		if (this.fix) this.fix.setStyle('display', 'none');
		return this;
	},

	destroy: function() {
		if (this.fix) this.fix = this.fix.destroy();
	}

});

Element.implement({

	getSelectedRange: function() {
		if (!Browser.Engine.trident) return {start: this.selectionStart, end: this.selectionEnd};
		var pos = {start: 0, end: 0};
		var range = this.getDocument().selection.createRange();
		if (!range || range.parentElement() != this) return pos;
		var dup = range.duplicate();
		if (this.type == 'text') {
			pos.start = 0 - dup.moveStart('character', -100000);
			pos.end = pos.start + range.text.length;
		} else {
			var value = this.value;
			var offset = value.length - value.match(/[\n\r]*$/)[0].length;
			dup.moveToElementText(this);
			dup.setEndPoint('StartToEnd', range);
			pos.end = offset - dup.text.length;
			dup.setEndPoint('StartToStart', range);
			pos.start = offset - dup.text.length;
		}
		return pos;
	},

	selectRange: function(start, end) {
		if (Browser.Engine.trident) {
			var diff = this.value.substr(start, end - start).replace(/\r/g, '').length;
			start = this.value.substr(0, start).replace(/\r/g, '').length;
			var range = this.createTextRange();
			range.collapse(true);
			range.moveEnd('character', start + diff);
			range.moveStart('character', start);
			range.select();
		} else {
			this.focus();
			this.setSelectionRange(start, end);
		}
		return this;
	}

});

/* compatibility */

Autocompleter.Base = Autocompleter;

/**
 * Autocompleter.Local
 *
 * http://digitarald.de/project/autocompleter/
 *
 * @version		1.1.2
 *
 * @license		MIT-style license
 * @author		Harald Kirschner <mail [at] digitarald.de>
 * @copyright	Author
 */

Autocompleter.Local = new Class({

	Extends: Autocompleter,

	options: {
		minLength: 0,
		delay: 200
	},

	initialize: function(element, tokens, options) {
		this.parent(element, options);
		this.tokens = tokens;
	},

	query: function() {
		this.update(this.filter());
	}

});

/**
 * Autocompleter.Request
 *
 * http://digitarald.de/project/autocompleter/
 *
 * @version		1.1.2
 *
 * @license		MIT-style license
 * @author		Harald Kirschner <mail [at] digitarald.de>
 * @copyright	Author
 */

Autocompleter.Request = new Class({

	Extends: Autocompleter,

	options: {/*
		indicator: null,
		indicatorClass: null,
		onRequest: $empty,
		onComplete: $empty,*/
		postData: {},
		ajaxOptions: {},
		postVar: 'value'

	},

	query: function(){
		var data = $unlink(this.options.postData) || {};
		data[this.options.postVar] = this.queryValue;
		var indicator = $(this.options.indicator);
		if (indicator) indicator.setStyle('display', '');
		var cls = this.options.indicatorClass;
		if (cls) this.element.addClass(cls);
		this.fireEvent('onRequest', [this.element, this.request, data, this.queryValue]);
		this.request.send({'data': data});
	},

	/**
	 * queryResponse - abstract
	 *
	 * Inherated classes have to extend this function and use this.parent()
	 */
	queryResponse: function() {
		var indicator = $(this.options.indicator);
		if (indicator) indicator.setStyle('display', 'none');
		var cls = this.options.indicatorClass;
		if (cls) this.element.removeClass(cls);
		return this.fireEvent('onComplete', [this.element, this.request]);
	}

});

Autocompleter.Request.JSON = new Class({

	Extends: Autocompleter.Request,

	initialize: function(el, url, options) {
		this.parent(el, options);
		this.request = new Request.JSON($merge({
			'url': url,
			'link': 'cancel'
		}, this.options.ajaxOptions)).addEvent('onComplete', this.queryResponse.bind(this));
	},

	queryResponse: function(response) {
		this.parent();
		this.update(response);
	}

});

Autocompleter.Request.HTML = new Class({

	Extends: Autocompleter.Request,

	initialize: function(el, url, options) {
		this.parent(el, options);
		this.request = new Request.HTML($merge({
			'url': url,
			'link': 'cancel',
			'update': this.choices
		}, this.options.ajaxOptions)).addEvent('onComplete', this.queryResponse.bind(this));
	},

	queryResponse: function(tree, elements) {
		this.parent();
		if (!elements || !elements.length) {
			this.hideChoices();
		} else {
			this.choices.getChildren(this.options.choicesMatch).each(this.options.injectChoice || function(choice) {
				var value = choice.innerHTML;
				choice.inputValue = value;
				this.addChoiceEvents(choice.set('html', this.markQueryValue(value)));
			}, this);
			this.showChoices();
		}

	}

});

/* compatibility */

Autocompleter.Ajax = {
	Base: Autocompleter.Request,
	Json: Autocompleter.Request.JSON,
	Xhtml: Autocompleter.Request.HTML
};


/**
 * Observer - Observe formelements for changes
 *
 * - Additional code from clientside.cnet.com
 *
 * @version		1.1
 *
 * @license		MIT-style license
 * @author		Harald Kirschner <mail [at] digitarald.de>
 * @copyright	Author
 */
var Observer = new Class({

	Implements: [Options, Events],

	options: {
		periodical: false,
		delay: 1000
	},

	initialize: function(el, onFired, options){
		this.element = $(el) || $$(el);
		this.addEvent('onFired', onFired);
		this.setOptions(options);
		this.bound = this.changed.bind(this);
		this.resume();
	},

	changed: function() {
		var value = this.element.get('value');
		if ($equals(this.value, value)) return;
		this.clear();
		this.value = value;
		this.timeout = this.onFired.delay(this.options.delay, this);
	},

	setValue: function(value) {
		this.value = value;
		this.element.set('value', value);
		return this.clear();
	},

	onFired: function() {
		this.fireEvent('onFired', [this.value, this.element]);
	},

	clear: function() {
		$clear(this.timeout || null);
		return this;
	},

	pause: function(){
		if (this.timer) $clear(this.timer);
		else this.element.removeEvent('keyup', this.bound);
		return this.clear();
	},

	resume: function(){
		this.value = this.element.get('value');
		if (this.options.periodical) this.timer = this.changed.periodical(this.options.periodical, this);
		else this.element.addEvent('keyup', this.bound);
		return this;
	}

});

var $equals = function(obj1, obj2) {
	return (obj1 == obj2 || JSON.encode(obj1) == JSON.encode(obj2));
};

/*
* FancyForm 0.95
* By Vacuous Virtuoso, lipidity.com
* ---
* Checkbox and radio input replacement script.
* Toggles defined class when input is selected.
*/

var FancyForm = {
	start: function(elements, options){
		if(FancyForm.initing != undefined) return;
		if($type(elements)!='array') elements = $$('input');
		if(!options) options = [];
		FancyForm.onclasses = ($type(options['onClasses']) == 'object') ? options['onClasses'] : {
			checkbox: 'checked',
			radio: 'selected'
		};
		FancyForm.offclasses = ($type(options['offClasses']) == 'object') ? options['offClasses'] : {
			checkbox: 'unchecked',
			radio: 'unselected'
		};
		if($type(options['extraClasses']) == 'object'){
			FancyForm.extra = options['extraClasses'];
		} else if(options['extraClasses']){
			FancyForm.extra = {
				checkbox: 'f_checkbox',
				radio: 'f_radio',
				on: 'f_on',
				off: 'f_off',
				all: 'fancy'
			};
		} else {
			FancyForm.extra = {};
		}
		FancyForm.onSelect = $pick(options['onSelect'], function(el){});
		FancyForm.onDeselect = $pick(options['onDeselect'], function(el){});
		FancyForm.chks = [];
		FancyForm.add(elements);
		$each($$('form'), function(x) {
			x.addEvent('reset', function(a) {
				window.setTimeout(function(){
				  FancyForm.chks.each(function(x){
				    FancyForm.update(x);
				    x.inputElement.blur();
				    }
				  );
				}, 200);
			});
		});
	},
	add: function(elements){
		if($type(elements) == 'element')
			elements = [elements];
		FancyForm.initing = 1;
		var keeps = [];
		var newChks = elements.filter(function(chk){
			if($type(chk) != 'element' || chk.inputElement || (chk.get('tag') == 'input' && chk.getParent().inputElement))
				return false;
			if(chk.get('tag') == 'input' && (FancyForm.onclasses[chk.getProperty('type')])){
				var el = chk.getParent();
				if(el.getElement('input')==chk){
					el.type = chk.getProperty('type');
					el.inputElement = chk;
					this.push(el);
				} else {
					chk.addEvent('click',function(f){
						if(f.event.stopPropagation) f.event.stopPropagation();
					});
				}
			} else if((chk.inputElement = chk.getElement('input')) && (FancyForm.onclasses[(chk.type = chk.inputElement.getProperty('type'))])){
				return true;
			}
			return false;
		}.bind(keeps));
		newChks = newChks.combine(keeps);
		newChks.each(function(chk){
			var c = chk.inputElement;
			c.setStyle('position', 'absolute');
			c.setStyle('left', '-9999px');
			chk.addEvent('selectStart', function(f){f.stop();});
			chk.name = c.getProperty('name');
			FancyForm.update(chk);
		});
		newChks.each(function(chk){
			var c = chk.inputElement;
			chk.addEvent('click', function(f){
				f.stop(); f.type = 'prop';
				c.fireEvent('click', f, 1);
			});
			chk.addEvent('mousedown', function(f){
				if($type(c.onmousedown) == 'function')
					c.onmousedown();
				f.preventDefault();
			});
			chk.addEvent('mouseup', function(f){
				if($type(c.onmouseup) == 'function')
					c.onmouseup();
			});
			c.addEvent('focus', function(f){
				if(FancyForm.focus)
					chk.setStyle('outline', '1px dotted');
			});
			c.addEvent('blur', function(f){
				chk.setStyle('outline', 0);
			});
			c.addEvent('click', function(f){
				if(f.event.stopPropagation) f.event.stopPropagation();
				if(c.getProperty('disabled')) // c.getStyle('position') != 'absolute'
					return;
				if (!chk.hasClass(FancyForm.onclasses[chk.type]))
					c.setProperty('checked', 'checked');
				else if(chk.type != 'radio')
					c.setProperty('checked', false);
				if(f.type == 'prop')
					FancyForm.focus = 0;
				FancyForm.update(chk);
				FancyForm.focus = 1;
				if(f.type == 'prop' && !FancyForm.initing && $type(c.onclick) == 'function')
					 c.onclick();
			});
			c.addEvent('mouseup', function(f){
				if(f.event.stopPropagation) f.event.stopPropagation();
			});
			c.addEvent('mousedown', function(f){
				if(f.event.stopPropagation) f.event.stopPropagation();
			});
			if(extraclass = FancyForm.extra[chk.type])
				chk.addClass(extraclass);
			if(extraclass = FancyForm.extra['all'])
				chk.addClass(extraclass);
		});
		FancyForm.chks.combine(newChks);
		FancyForm.initing = 0;
	},
	update: function(chk){
		if(chk.inputElement.getProperty('checked')) {
			chk.removeClass(FancyForm.offclasses[chk.type]);
			chk.addClass(FancyForm.onclasses[chk.type]);
			if (chk.type == 'radio'){
				FancyForm.chks.each(function(other){
					if (other.name == chk.name && other != chk) {
						other.inputElement.setProperty('checked', false);
						FancyForm.update(other);
					}
				});
			}
			if(extraclass = FancyForm.extra['on'])
				chk.addClass(extraclass);
			if(extraclass = FancyForm.extra['off'])
				chk.removeClass(extraclass);
			if(!FancyForm.initing)
				FancyForm.onSelect(chk);
		} else {
			chk.removeClass(FancyForm.onclasses[chk.type]);
			chk.addClass(FancyForm.offclasses[chk.type]);
			if(extraclass = FancyForm.extra['off'])
				chk.addClass(extraclass);
			if(extraclass = FancyForm.extra['on'])
				chk.removeClass(extraclass);
			if(!FancyForm.initing)
				FancyForm.onDeselect(chk);
		}
		if(!FancyForm.initing)
			chk.inputElement.focus();
	},
	all: function(){
		FancyForm.chks.each(function(chk){
			chk.inputElement.setProperty('checked', 'checked');
			FancyForm.update(chk);
		});
	},
	none: function(){
		FancyForm.chks.each(function(chk){
			chk.inputElement.setProperty('checked', false);
			FancyForm.update(chk);
		});
	}
};

window.addEvent('domready', function(){
	FancyForm.start();
});


/*
---
description: Overlay

authors:
  - David Walsh (http://davidwalsh.name)

license:
  - MIT-style license

requires:
  core/1.2.1: '*'

provides:
  - Overlay
...
*/

var Overlay = new Class({
	
	Implements: [Options, Events],
	
	options: {
		id: 'overlay',
		color: '#000',
		duration: 500,
		opacity: 0.5,
		zIndex: 5000/*,
		onClick: $empty,
		onClose: $empty,
		onHide: $empty,
		onOpen: $empty,
		onShow: $empty
		*/
	},
	
	initialize: function(container, options){
		this.setOptions(options);
		this.container = document.id(container);
		if (Browser.Engine.trident && Browser.Engine.version <= 6) this.ie6 = true;
		
		this.bound = {
			'window': {
				resize: this.resize.bind(this),
				scroll: this.scroll.bind(this)
			},			
			overlayClick: this.overlayClick.bind(this),
			tweenStart: this.tweenStart.bind(this),
			tweenComplete: this.tweenComplete.bind(this)	  
		};
		
		this.build().attach();
	},
	
	build: function(){
	  this.overlay = new Element('div', {
			id: this.options.id,
			opacity: 0,
			styles: {
				position: (this.ie6) ? 'absolute' : 'fixed',
				background: this.options.color,
				left: 0,
				top: 0,
				'z-index': this.options.zIndex
			}
		}).inject(this.container);
		this.tween = new Fx.Tween(this.overlay, { 
			duration: this.options.duration,
			link: 'cancel',
			property: 'opacity'
		});
	 return this;
	}.protect(),
	
	attach: function(){
		window.addEvents(this.bound.window);
		this.overlay.addEvent('click', this.bound.overlayClick);
		this.tween.addEvents({
			onStart: this.bound.tweenStart,
			onComplete: this.bound.tweenComplete
		});
	 return this;
	},
	
	detach: function(){
		var args = Array.prototype.slice.call(arguments);
		args.each(function(item){
			if(item == 'window') window.removeEvents(this.bound.window);
			if(item == 'overlay') this.overlay.removeEvent('click', this.bound.overlayClick);
		}, this);
		return this;
	},
	
	overlayClick: function(){
		this.fireEvent('click');
		return this;
	},
	
	tweenStart: function(){
		this.overlay.setStyles({
			width: '100%',
			height: this.container.getScrollSize().y
		});
	 return this;
	},
	
	tweenComplete: function(){
		this.fireEvent(this.overlay.get('opacity') == this.options.opacity ? 'show' : 'hide');
		return this;
	},
	
	open: function(){
		this.fireEvent('open');
		this.tween.start(this.options.opacity);
		return this;
	},
	
	beThere: function(){
		this.fireEvent('open');
		this.bound.tweenStart();
		this.tween.set(this.options.opacity);
		this.bound.tweenComplete();
		return this;
	},
	
	close: function(){
		this.fireEvent('close');
		this.tween.start(0);
		return this;
	},
	
	resize: function(){
		this.fireEvent('resize');
		this.overlay.setStyle('height', this.container.getScrollSize().y);
		return this;
	},
	
	scroll: function(){
		this.fireEvent('scroll');
		if (this.ie6) this.overlay.setStyle('left', window.getScroll().x);
		return this;
	}
	
});

/**
	SlideItMoo v1.1 - Image slider for MooTools 1.3
	(c) 2007-2010 Constantin Boiangiu <http://www.php-help.ro>
	MIT-style license.
	
	Changes from version 1.0
	- added continuous navigation
	- changed the navigation from Fx.Scroll to Fx.Morph
	- added new parameters: itemsSelector: pass the CSS class for divs
	- itemWidth: for elements with margin/padding pass their width including margin/padding
	
	Updates ( August 4th 2009 )
	- added new parameter 'elemsSlide'. When this is set to a value lower that the actual number of elements in HTML, it will slide at once that number of elements when navigation clicked. Default: null
	- added onChange event that returns the index of the current element
	
	Updates ( January 12th 2010 )
	- vertical sliding available. First, set your HTML to display vertically and set itemHeight:height of individual items ( including padding, border and so on ) and slideVertical:true
	- navigators ( forward/back ) no longer added by script. Instead, add them into overallContainer making their display from CSS and after add the CSS selector class to navs parameter
		IE: navs:{ 
				fwd:'.SlideItMoo_forward', 
				bk:'.SlideItMoo_back' 
			}
	- new method available resetAll(). When called, this will reset the previous settings and restart the script. Useful if you change slider content on-the-fly
	- new method available to stop autoSlide ( stopAutoSlide() ). To start autoslide back, use startAutoSlide()
**/
var SlideItMoo = new Class({
	
	Implements: [Events,Options],
	options: {
		overallContainer: null,/* outer container, contains fwd/back buttons and container for thumbnails */
		elementScrolled: null, /* has a set width/height with overflow hidden to allow sliding of elements */
		thumbsContainer: null,	/* actual thumbnails container */	
		itemsSelector: null, /* css class for inner elements ( ie: .SlideItMoo_element ) */
		itemsVisible:5, /* number of elements visible at once */
		elemsSlide: null, /* number of elements that slide at once */
		itemWidth: null, /* single element width */
		itemHeight: null, /* single element height */
		navs:{ /* starting this version, you'll need to put your back/forward navigators in your HTML */
			fwd:'.SlideItMoo_forward', /* forward button CSS selector */
			bk:'.SlideItMoo_back' /* back button CSS selector */
		},
		slideVertical: false, /* vertical sliding enabled */
		showControls:1, /* show forward/back controls */
		transition: Fx.Transitions.linear, /* transition */
		duration: 800, /* transition duration */
		direction: 1, /* sliding direction ( 1: enter from left/top; -1:enter from right/bottom ) */
		autoSlide: false, /* auto slide - as milliseconds ( ie: 10000 = 10 seconds ) */
		mouseWheelNav: false, /* enable mouse wheel nav */
		startIndex: null
		/*onChange: $empty*/
	},
	
	initialize: function(options){
		this.setOptions(options);
		/* all elements are identified on CSS selector (itemsSelector) */
		this.elements = $(this.options.thumbsContainer).getElements(this.options.itemsSelector);
		this.totalElements = this.elements.length;
		if( this.totalElements <= this.options.itemsVisible ) return;
		// width of thumbsContainer children
		var defaultSize = this.elements[0].getSize();
		this.elementWidth = this.options.itemWidth || defaultSize.x;
		this.elementHeight = this.options.itemHeight || defaultSize.y;
		this.currentElement = 0;
		this.direction = this.options.direction;
		this.autoSlideTotal = this.options.autoSlide + this.options.duration;
		if( this.options.elemsSlide == 1 ) this.options.elemsSlide = null;
		this.begin();		
	},
		
	begin: function(){	
		/* if navigation is needed and enabled, add it */
		this.addControls();
				
		// resizes the container div's according to the number of itemsVisible thumbnails
		this.setContainersSize();
		
		this.myFx = new Fx.Tween(this.options.thumbsContainer, { 
			property: (this.options.slideVertical ? 'margin-top':'margin-left'),
			link: 'ignore', 
			transition: this.options.transition,
			duration: this.options.duration
		});		
				
		/* if autoSlide is not set, scoll on mouse wheel */
		if( this.options.mouseWheelNav && !this.options.autoSlide ){
			$(this.options.thumbsContainer).addEvent('mousewheel', function(ev){
				new Event(ev).stop();
				this.slide(-ev.wheel);								
			}.bind(this));
		}
		
		/* start index element */
		if( this.options.startIndex && this.options.startIndex > 0 && this.options.startIndex < this.elements.length ){
			for( var t = 1; t < this.options.startIndex; t++ )
				this.rearange();
		}
		
		if( this.options.autoSlide && this.elements.length > this.options.itemsVisible )
			this.startAutoSlide();		
	},
	/* resets the whole slider in case content changes */
	resetAll: function(){
		$(this.options.overallContainer).removeProperty('style');
		$(this.options.elementScrolled).removeProperty('style');
		$(this.options.thumbsContainer).removeProperty('style');
		this.stopAutoSlide();
		if( typeOf( this.fwd ) !== null ){
			this.fwd.dispose();
			this.bkwd.dispose();
		}
		this.initialize();
	},
	/* sets the containers width to leave visible only the specified number of elements */
	setContainersSize: function(){
		var overallSize = {};
		var scrollSize = {};
		var thumbsSize = {};
		
		if( this.options.slideVertical ){
			//overallSize.height = this.options.itemsVisible * this.elementHeight + 50 * this.options.showControls;
			scrollSize.height = this.options.itemsVisible * this.elementHeight;
			thumbsSize.height = this.totalElements * (this.elementHeight + 10);			
		}else{
			/* if navigation is enabled, add the width to the overall size */
			var navsSize = 0;
			if( this.options.showControls ){
				var s1 = this.fwd.getSize();
				var s2 = this.bkwd.getSize();
				var navsSize = s1.x+s2.x;
			}
			overallSize.width = this.options.itemsVisible * this.elementWidth + navsSize;
			scrollSize.width = this.options.itemsVisible * this.elementWidth;
			thumbsSize.width = this.totalElements * (this.elementWidth + 10);			
		}
		$(this.options.overallContainer).set({
			styles : overallSize
		});
		$(this.options.elementScrolled).set({
			styles : scrollSize
		});
		$(this.options.thumbsContainer).set({
			styles : thumbsSize
		});
	},
	/* adds forward/back buttons */
	addControls: function(){
		if( !this.options.showControls || this.elements.length <= this.options.itemsVisible ) return;
		
		this.fwd = $(this.options.overallContainer).getElement(this.options.navs.fwd);
		this.bkwd = $(this.options.overallContainer).getElement(this.options.navs.bk);
		
		if( this.fwd )
			this.fwd.addEvent('click', this.slide.pass(1, this));
		if( this.bkwd )
			this.bkwd.addEvent('click', this.slide.pass(-1, this));		
	},
	/* slides elements */
	slide: function( direction ){
		
		if(this.started) return;
		this.direction = direction ? direction : this.direction;
		var currentIndex = this.currentIndex();
		/* if multiple elements are to be skipped (elemsSlide > 1), calculate the ending element */
		if( this.options.elemsSlide && this.options.elemsSlide>1 && this.endingElem==null ){
			this.endingElem = this.currentElement;			
			for(var i = 0; i < this.options.elemsSlide; i++ ){
				this.endingElem += direction;
				if( this.endingElem >= this.totalElements ) this.endingElem = 0;
				if( this.endingElem < 0 ) this.endingElem = this.totalElements-1;
			}
		}	
		
		var s = new Hash();
		var fxDist = 0;
		if( this.options.slideVertical ){
			s.include('margin-top', -this.elementHeight);
			fxDist = this.direction == 1 ? -this.elementHeight : 0;
		}else{
			s.include('margin-left', -this.elementWidth);
			fxDist = this.direction == 1 ? -this.elementWidth : 0;
		}
		
		if( this.direction == -1 ){
			this.rearange();
			$(this.options.thumbsContainer).setStyles(s);			
		}
		this.started = true;
		
		if(!typeOf(this.endingElem))
			this.endingElem = null;
		
		this.myFx.start( fxDist ).chain( function(){			
			this.rearange(true);			
			if(this.options.elemsSlide){
				// if one element slided at once
				if( this.endingElem !== this.currentElement ){ 
					if( this.options.autoSlide )
						this.stopAutoSlide();
					this.slide(this.direction);
				}
				// else if multiple elems are slided at once
				else {
					if( this.options.autoSlide ){
						this.startAutoSlide();
					}
					this.endingElem = null;
				}
			}
		}.bind(this)  );
		
		this.fireEvent('onChange', currentIndex);
		
	},
	/* rearanges elements for continuous navigation */
	rearange: function( rerun ){
		
		if(rerun) this.started = false;
		if( rerun && this.direction == -1 ) return;
		
		this.currentElement = this.currentIndex( this.direction );
		
		// var s = new Hash();
		// 		if( this.options.slideVertical ) s.include('margin-top', 0);
		// 		else s.include('margin-left', 0);
		var s = {};
		if( this.options.slideVertical ){ s = Object.merge({'margin-top': '0' }); }
		else { s = Object.merge({'margin-left': '0' }); }
		
		$(this.options.thumbsContainer).setStyles(s);
		
		if( this.currentElement == 1 && this.direction == 1 ){
			this.elements[0].inject(this.elements[this.totalElements-1], 'after');
			return;
		}
		if( (this.currentElement == 0 && this.direction ==1) || (this.direction==-1 && this.currentElement == this.totalElements-1) ){
			this.rearrangeElement( this.elements.getLast(), this.direction == 1 ? this.elements[this.totalElements-2] : this.elements[0]);
			return;
		}
		
		if( this.direction == 1 ) this.rearrangeElement( this.elements[this.currentElement-1], this.elements[this.currentElement-2]);
		else this.rearrangeElement( this.elements[this.currentElement], this.elements[this.currentElement+1]);			
	},
	/* rearanges a single element for continuous navigation */
	rearrangeElement: function( element , indicator ){
		this.direction == 1 ? element.inject(indicator, 'after') : element.inject(indicator, 'before');
	},
	/* determines the current index in element list */
	currentIndex: function(){
		var elemIndex = null;
		switch( this.direction ){
			/* forward */
			case 1:
				elemIndex = this.currentElement >= this.totalElements-1 ? 0 : this.currentElement + this.direction;				
			break;
			/* backwards */
			case -1:
				elemIndex = this.currentElement == 0 ? this.totalElements - 1 : this.currentElement + this.direction;
			break;
		}
		return elemIndex;
	},
	/* starts auto sliding */
	startAutoSlide: function(){
		this.startIt = this.slide.bind(this).pass(this.direction|1);
		this.autoSlide = this.startIt.periodical(this.autoSlideTotal, this);
		this.isRunning = true;
		this.elements.addEvents({
			'mouseenter':function(){
				clearInterval(this.autoSlide);
				this.isRunning = false;
			}.bind(this),
			'mouseleave':function(){
				this.autoSlide = this.startIt.periodical(this.autoSlideTotal, this);
				this.isRunning = true;
			}.bind(this)
		})
	},
	/* stops auto sliding */
	stopAutoSlide: function(){
		clearInterval(this.autoSlide);
		clearInterval(this.startIt);
		this.isRunning = false;
		this.elements.removeEvents();
	}
})

/**
 * StudioMelipone.UpShot => namespace to manage interactivity on pictures
 * @param {string/Element} picture
 * @param {string/Element} container
 * @param {string/Element} decorator
 * @param {array} options
 *
 * Options:
 *  - {Element} tracer 
 */

if(!$defined(StudioMelipone)){ var StudioMelipone = new Hash(); }

StudioMelipone.UpShot = new Class({
	Implements: [Options, Events],
	
	options: {
		global_container: $empty,  //The div wich indicate the version (current, next or previous)
		user: $empty,
		validation: false,
		id: $empty,
		nexxt: $empty,
		previous: $empty,
		active: $empty
	},
	
	notes: new Hash(),
	
	initialize: function(picture, container, log_container, decorator, options, comment_form){
		this.picture = picture;
		this.container = container;
		this.log_container = log_container;
		this.decorator = decorator;
		this.comment_form = comment_form;	
		
		this.setOptions(options);
		
		this.last_refresh = 0;
		this.z = 1;
		this.notes = new Hash();
		this.new_notes = new Hash();
		this.logs = new Hash();
		this.all_shown = true;
		this.initContainer();
		this.initShowHideButtons();
		this.initCommentForm();
	},
	

	/**
	* Initialize the comment form to do it in Ajax
	*/
	initCommentForm: function(){
		this.comment_form.addEvent('submit', this.createComment.bindWithEvent(this));
		
	},
	/**
	 * Initializes the container.
	 * Set styles, center the picture and init the borders.
	 * Also add the dblclick event to add Notes upon the picture.
	 */
	initContainer: function(){
		this.picture.addEvent('dblclick', this.createNote.bindWithEvent(this));
		
		this.refresh();
		if(this.options.active){
			this.period = this.refresh.periodical(25000, this);
		}
	},
	
	changeActive: function(act){
		this.options.active = act;

		// Get the route
		var url = StudioMelipone.UpShot.Routes.get(StudioMelipone.UpShot.Routes.Upshots.read, { user_id: _upshots[this.options.id]['user'].id, upshot_id: _upshots[this.options.id].id });
		
		if(act){
			this.period = this.refresh.periodical(25000, this);
			// Create the request
			this.read_request = new Request.Auth({
				url: url,
				method: 'get',
				headers:{
					'X-Request' : 'JSON',
					'X-Requested-With' : 'XMLHttpRequest'
				}
			});
			this.read_request.send({});
			
		}else{
			$clear(this.period);
		}
	},
	
	initShowHideButtons: function(){
		$$("a.hide").each(function(a){ a.addEvent('click', this.toggleAll.bindWithEvent(this)); }, this);
	},
	
	/**
	 * Creates a new Note from user dblclick
	 */
	createNote: function(e){
		e.stop();
		
		e.stopPropagation();
		if(this.checkIntersection(e.page.x, e.page.y)){	
			// Calculate the click relative to the picture
			var click_position = this.relativePosition(e.page.x, e.page.y);
			// Correct the position if the click is too near of the right or bottom border
			var corrected_click = this.correctPosition(click_position);
			
			// Add the note
			var note = this.addNote(corrected_click.x-21, corrected_click.y-21, {
				global_container: this.picture, 
				upshot_id: this.options.id,
				"editable": true, 
				user: this.options.user, 
				created_at: _("now"), 
				validation: this.options.validation,
				type:"note",
				picture: this.picture
			});
			note.textarea.focus();
		}
	},
	
	/**
	* Creates a new Comment when post the new comment form
	*/
	createComment: function(e){
		e.stop();
		//greyize the textarea
		area = this.comment_form.getElement('textarea#comment_comment');
		if(area.get("value") != ""){
		  area.setStyle('background-color','#EDEDED');
  		area.set('disabled','true');
		}
		// Add the comment
		var comment = this.addComment({upshot_id: this.options.id, 
			container: this.comment_form,
			user: this.options.user, 
			created_at: _("now"), 
			validation: this.options.validation,
			type:"comment",
			supattachments: _supattachments.getIds()
		});
	},
	
	getAllNotes: function(){
		
		allNotes = this.notes.extend(this.new_notes).filter(function(note, index){
			return note.options.type == "note";
		});
		return allNotes;
	},
	
	relativePosition: function(x, y){
		var picture_position = this.picture.getPosition();
		
		var relative_x = x - picture_position.x - 9; // 9 is for the border
		var relative_y = y - picture_position.y - 9; // 9 is for the border
		
		return { 'x': relative_x, 'y': relative_y };
	},
	
	correctPosition: function(p){
		var s = this.picture.getSize();
		
		if(p.x < 22){
			p.x += 22 - p.x;
		}else{
			var dx = s.x - (p.x + 21);
			if(dx < 0){ p.x += dx; }
		}
		
		if(p.y < 23){
			p.y += 23 - p.y;
		}else{
			var dy = s.y - (p.y + 20);
			if(dy < 0){ p.y += dy; }
		}
		
		return p;
	},
	
	checkIntersection: function(x, y){
		var notes = this.getAllNotes();
		
		var found_an_intersection = notes.some(function(note){ return this.clickedOnComments(x, y, note);	}, this);
		
		return !found_an_intersection;
	},
	
	/**
	 *  Adds a StudioMelipone.UpShot.Note
	 * @param {int} x
	 * @param {int} y
	 * Options:	
	 * {int} number
	 * {date} created_at
	 * {string} author
	 * {string} userType
	 * {string} content
	 * {boolean} editable
	 * {string} state
	 * {array} answers
	 */
	addNote: function(x, y, options){
		// Create the note object
		var note = new StudioMelipone.UpShot.Note(x, y, this.z++, options);
		
		// Attach click to reorder depth
		note.element.addEvent('click', this.reorderDepth.bindWithEvent(this, [note, true]));
		note.addEvent('reply', this.saveReplySuccess.bindWithEvent(this, note));
		
		// Add the note into our storage array
		if(!options.editable){
		  this.notes[options.id] = note;
		}else{
			// Attach save event to move note from new to array
			note.addEvent('save', this.saveSuccess.bindWithEvent(this, note));
			// Attach drag to move and drag to resize events
			note.makeDraggable();
		  this.new_notes.set($time(), note);
		}
		
		// Attach the note to the page
		this.container.adopt(note.element);
		
		return note;
	},
	
	addComment: function(options){
			// Create the comment object
			var comment = new StudioMelipone.UpShot.Comment(options);
			//this.saveSuccess(this, comment);
			// Attach save event to move comment from new to array
			comment.addEvent('save', this.saveSuccess.bindWithEvent(this, comment));
			
			return comment;
	},
	
	addLog: function(options){
		// Create the log object
		var log = new StudioMelipone.UpShot.Log(options);
		
		// Add the log into our storage array
		this.logs[options.id] = log;
		
		// Attach the log to the page (at the top of the list)
		log.element.inject(this.log_container, 'top');
		
		//Adapt the mask height
		if(this.options.active){
			$$('.mask1').setStyle('height', this.options.global_container.offsetHeight);
		}
		
		return log;
	},
	
	addLogReply: function(options){
		var parent = this.logs[options.parent_id];
		
		// Create the log object
		var reply = new StudioMelipone.UpShot.LogReply(parent, options);
		
		// Add the log into our storage array
		//this.logs[options.id] = log;
		
		parent.addReply(options);
		
		//Adapt the mask height
		if(this.options.active){
			$$('.mask1').setStyle('height', this.options.global_container.offsetHeight);
		}
		
		// Attach the log to the page (at the top of the list)
		//log.element.inject(this.log, 'top');
		
		return reply;
	},
	
	
	/*
   * Refreshes Notes from the server
   */
  refresh : function(){
		// Get the route
		var url = StudioMelipone.UpShot.Routes.get(StudioMelipone.UpShot.Routes.Notes.save, { user_id: _current_user.id, upshot_id: this.options.id });
		// Add the since param if we need to
		if(this.last_refresh > 0){ url += "?since=" + this.last_refresh; }

			// var avatemp = $$('.avatemp');
			// if($chk(avatemp)){
			// 	var avarray = new Array();
			// 	avatemp.each(function(temp){
			// 		avarray+=avatemp.id
			// 	});
			// 	url+= "?avatempids=" + avarray;
			// }

			var thumbtemp = new Hash();
			thumbtemp = this.logs.filter(function(value, key){
				var test = (value.options.thumbnail == "/default/note_loader/note_medium.png" ? true : false);
				return test;
			} );

			var tempids = new Array();
			thumbtemp.each(function(n){
				tempids.include(n.options.id);
			});

			// Create the request
			this.index_request = new Request.Auth({
				url: url,
				method: 'get',
				headers:{
					'X-Request' : 'JSON',
					'X-Requested-With' : 'XMLHttpRequest'
				},
				onSuccess: this.processNotes.bindWithEvent(this),
				onFailure: this.failure.bindWithEvent(this)
			});
			this.index_request.send({'thumbtemps': tempids});
  },
	
	processNotes: function(text){
		var data = JSON.decode(text);
	
		// Empty the log the first time
		if(this.last_refresh == 0){ this.log_container.empty(); }
	
		// Keep last updated time
		this.last_refresh = data.time;
		
		// Add new notes and their replys
		data.notes.each(function(note){
			if(note.type == "note"){
				// Add a note
				this.addNote(
					note.x,
					note.y,
					{
						editable: false,
						id: note.id,
						content: note.content,
						h: note.h,
						w: note.w,
						state: note.state,
						user: note.user,
						replys: note.replys,
						created_at: note.created_at,
						thumbnail: note.thumbnail,
						type: note.type,
						after_validation: note.after_validation,
						validation: this.options.validation,
						global_container: this.options.global_container,
						upshot_id: this.options.id,
						status: note.status
					});
				
				// Add a log
				this.addLog({
					id: note.id,
					content: note.content,
					state: note.state,
					user: note.user,
					replys: note.replys,
					created_at: note.created_at,
					thumbnail: note.thumbnail,
					type: note.type,
					after_validation: note.after_validation,
					validation: this.options.validation
				});
			}else if(note.type == "comment"){
				// Add a log
				this.addLog({
					id: note.id,
					content: note.content,
					user: note.user,
					created_at: note.created_at,
					type: note.type,
					after_validation: note.after_validation,
					validation: this.options.validation,
					files: note.files
				});
			}
		}, this);
		
		// Add replys to existing notes
		data.replys.each(function(reply){
			// Add a reply to the notes
			this.notes[reply.parent_id].addReply(reply);
			// Add a reply to the log
			this.logs[reply.parent_id].addReply(reply);
		}, this);
		
		// Change times to time ago in words
		DateHelper.convert_all_times_to_words();
		
		//Update temporary avatars
		if($chk(data.rethumbed)){
			//var notes = this.getAllNotes();
			data.rethumbed.each(function(note){
				(this.logs[note.id]).setThumbnail(note.thumbnail);
			}, this);
		}
	},
	
	saveSuccess: function(e, note){
		this.notes[note.options.id] = note;
		this.new_notes.erase(note);
		
		if(note.options.type == "note"){
			this.addLog({
				id: note.options.id,
				content: note.options.content,
				state: note.options.state,
				user: note.options.user,
				replys: note.options.replys,
				created_at: note.options.created_at,
				thumbnail: note.options.thumbnail,
				type: note.options.type,
				after_validation: note.options.after_validation,
				validation: this.options.validation
			});
		}else if(note.options.type == "comment"){
			this.addLog({
				id: note.options.id,
				content: note.options.content,
				state: note.options.state,
				user: note.options.user,
				created_at: note.options.created_at,
				type: note.options.type,
				after_validation: note.options.after_validation,
				validation: this.options.validation,
				files:note.options.files
			});
			
			//ungreyize the textarea
			area = this.comment_form.getElement('textarea');
			area.setStyle('background-color','');
			area.set('disabled','');
			//Empty the textarea
			area.set('value', '');
		}
	},
	
	saveReplySuccess: function(reply){
		this.addLogReply({
			id: reply.options.id,
			parent_id: reply.options.parent_id,
			content: reply.options.content,
			user: reply.options.user,
			created_at: reply.options.created_at,
			type: reply.options.type,
			after_validation: reply.options.after_validation,
			validation: this.options.validation
		});
	},
	
	failure: function(){
		
	},
	
	toggleAll: function(e){
		e.stop();
		
		if(this.all_shown){
			this.getAllNotes().each(function(n){
				n.hide();
			});
			$$("a.hide").each(function(a){	a.set("text", _("Show all"));	});
			this.all_shown = false;
		}else{
			this.getAllNotes().each(function(n){
				n.show();
			});
			$$("a.hide").each(function(a){ a.set("text", _("Hide all")); });
			this.all_shown = true;
		}
	},

	reorderDepth: function(e, note, global){
		// Check if the click falls on the zone or the comments
		if(this.clickedOnZone(e.page.x, e.page.y, note)){
			var notes = this.getAllNotes().getValues();
			
			var zindex_sort = notes.sort(function(a, b){
				return a.element.getStyle("z-index") - b.element.getStyle("z-index");
			});
			
			var candidates = zindex_sort.filter(function(item, index){
				return this.clickedOnNote(e.page.x, e.page.y, item);
			}, this);
			
			var note = candidates[0];
			var actualIndex = note.getZ();
			var allNotes = this.getAllNotes();
			// max index should be linked to the global number of notes
			var maxIndex = allNotes.getLength();

			// don't bother if the click was made on the uppest note
			if(actualIndex != maxIndex){
				var zI;
				allNotes.each(function(el){
					zI = el.getZ();
					// if the note's index is over the current note: decrement it (make the concerned note go deeper)
					if(zI > actualIndex){
						el.setZ(zI-1);
					}
				}.bind(this));
				// and finally put our note at the top of the others
				note.setZ(maxIndex==0?1:maxIndex);
			}
			
		}else if(this.clickedOnComments(e.page.x, e.page.y, note)){
			var actualIndex = note.getZ();
			var allNotes = this.getAllNotes();
			// max index should be linked to the global number of notes
			var maxIndex = allNotes.getLength();

			// don't bother if the click was made on the uppest note
			if(actualIndex != maxIndex){
				allNotes.each(function(el){
					var zI = el.getZ();
					// if the note's index is over the current note: decrement it (make the concerned note go deeper)
					if(zI > actualIndex){
						el.setZ(zI-1);
					}
				}, this);
				// and finally put our note at the top of the others
				note.setZ(maxIndex==0?1:maxIndex);
			}
		}
		
		e.stop();
  },

	clickedOnNote: function(x, y, note){
		return this.clickedOnZone(x, y, note) || this.clickedOnComments(x, y, note);
	},
	
	clickedOnZone: function(x, y, note){
		return this.clickedOnElement(x, y, note.element.zone);
	},
	
	clickedOnComments: function(x, y, note){
		return this.clickedOnElement(x, y, note.element.comments);
	},
	
	clickedOnElement: function(x, y, element){
		var c = element.getCoordinates();
		return (c.left < x && (c.left + c.width) > x) && (c.top < y && (c.top + c.height) > y);
	}
});

StudioMelipone.UpShot.Routes = new Hash({
	Notes: {
		save: 	"/upshots/{upshot_id}/notes",
		reply: 	"/upshots/{upshot_id}/notes/{note_id}/replys",
		index: 	"/upshots/{upshot_id}/notes",
		change_status: "/upshots/{upshot_id}/notes/{note_id}/change_todo_status"
	},
	Comment: {
		save: "/upshots/{upshot_id}/update_comments"
	},
	Shortcuts: {
		order: 	"/users/{user_id}/shortcuts/order",
		'delete': "/users/{user_id}/shortcuts/{shortcut_id}"
	},
	ShortcutUpshot: {
		save: 	"/users/{user_id}/shortcuts"
	},
	ShortcutSearch: {
		save: 	"/users/{user_id}/searches/create_shortcut"
	},
	Upshots: {
		show: "/upshots/{upshot_id}",
		bulk_update: "/users/{user_id}/upshots/bulk_update",
		read: "/users/{user_id}/upshots/{upshot_id}/read"
	},
	Dashboard: {
		filter: "/dashboard/{tab}/filter/{search}"
	},
	Branding: {
		preview: "/users/{user_id}/branding/preview",
		destroy_picture: "/users/{user_id}/branding/destroy_picture"
	},
	Users: {
		update_gui_data : "/users/{user_id}/update_gui_data"
	},
	Version: {
		change_version: "/upshots/{upshot_id}/change_version"
	},
	
	get: function(key, values){
		return key.substitute(values);
	}
});

if(!$defined(StudioMelipone)){ var StudioMelipone = new Hash(); }

StudioMelipone.Version = new Class({
	Implements: [Options, Events],
	
	options: {
		slider: $empty,
		//active_upshot: $empty,
		global_container: $('all_upshots')
	},
	
	//link: new Hash(),
	//container: new Hash(),
	//upshot_img: new Hash(),
	//upshot: new Hash(),
	//all_upshots: new Hash(),
	//allow: new Hash(),
	overlay: $empty,
	upshots: new Hash(),
	pointers: {
		previous: $empty,
		current: 	$empty,
		nexxt: 		$empty
	},
				
	initialize: function(options){
		this.setOptions(options);
		
		//For the focus
		this.initFadeFocusButtons();

		//		{active_upshot: $$('.current').get('id')[0]}

		// 	
		// 	//To forbid multi click on next or previous
		// 	this.allow["after"] = true;
		// 	this.allow["previous"] = true;

		// 		
		// 	//The previous and next button
		// 		this.link = {
		// 			after: $$('span.next')[0],
		// 			previous: $$('span.prev')[0]
		// 		};
		// 		if(!this.link.after){
		// 			this.link["after"] = new Element('span', {'class':'next', 'text':"next >>"});
		// 		}
		// 		if(!this.link.previous){
		// 			this.link["previous"] = new Element('span', {'class':'prev', 'text':"<< previous"});
		// 		}
		// 
		// 	this.initSwitch();
		// 	
		// 	//The container of each version (current, next and previous)
		// 		this.container = {
		// 			previous: $$('div.previous')[0],
		// 			current:  $$('div.current')[0],
		// 			after:     $$('div.next')[0]
		// 		}
		// 		
		// 
		// 	//The images of each verions container
		// 		this.upshot_img["current"] = this.container["current"].getElement('.image');
		// 		if (this.container["previous"]){
		// 			this.upshot_img["previous"] = this.container["previous"].getElement('.image');	
		// 		}
		// 		if(this.container["after"]){
		// 			this.upshot_img["after"] = this.container["after"].getElement('.image');
		// 		}
		// 	
		// 	//Instanciate the Upshot javascript object			
		// 		["previous", "current", "after"].each(function(direction){
		// 			if($chk(this.upshot_img[direction])){
		// 				if(direction == "current"){
		// 					act = true;
		// 				}else{
		// 					act = false;
		// 				}
		// 				this.upshot[direction] = new StudioMelipone.UpShot(
		// 				  this.upshot_img[direction], 
		// 				  this.upshot_img[direction], 
		// 				  this.container[direction].getElement('.commentlist'), 
		// 				  this.container[direction].getElement('.picture'),
		// 				 	{
		// 				 	  global_container: this.container[direction], 
		// 				 	  user: window._upshots[this.container[direction].get('id')].user, 
		// 				 	  id: this.container[direction].get('id'),
		// 				 		active: act, after: window._upshots[this.container[direction].get('id')].after, 
		// 				 		previous: window._upshots[this.container[direction].get('id')].previous 
		// 				 	}, 
		// 				this.container[direction].getElement('.send_message'));
		// 				this.all_upshots.set(this.upshot[direction].options.id, this.upshot[direction]);
		// 				this.container[direction].setStyle('width', window._upshots[this.upshot[direction].options.id].image.width > 900? window._upshots[this.upshot[direction].options.id].image.width:900);
		// 			}
		// 		}, this);
		//
		var previous 	= this.options.global_container.getElement(".upshot_version .previous");
		var current 	= this.options.global_container.getElement(".upshot_version .current");
		var nexxt 		= this.options.global_container.getElement(".upshot_version .nexxt");
		
		this.pointers.previous 	= this.initExisting(previous, { nexxt: current }, false);
		this.pointers.current 	= this.initExisting(current, { previous: previous, nexxt: nexxt }, true);
		this.pointers.nexxt 		= this.initExisting(nexxt, { previous: current }, false);
	},
	
	initFadeFocusButtons: function(){
 		this.overlay = new Overlay(document.body,{
 			id: 'overlay',
 			zIndex: 0,
 			color: '#000',
 			duration: 300,
 			opacity: 0.8,
 			onClick: function() { this.close(); }
 		});
 		$$(".fade-focus").addEvent('click', function(e){ e.stop(); this.overlay.open(); }.bind(this));
 	},

	initExisting: function(element, siblings, active){
		if(!$chk(element)) return;
		
		var id = ViewHelper.dom_id_data(element.get('id'));
		return this.upshots[id.upshot] = new StudioMelipone.UpShot(
		  element.getElement(".image"),
		  element.getElement(".image"),
		  element.getElement('.comment_list'),
		  element.getElement('.picture'),
		 	{
		 	  //global_container: this.options.global_container,
		 	  user: _current_user,
		 	  id: id.upshot,
		 		active: active,
				previous: siblings.previous,
				nexxt: siblings.nexxt,
				validation: window._validation
				//nexxt: window._upshots[this.container[direction].get('id')].nexxt,
		 		//previous: window._upshots[this.container[direction].get('id')].previous
		 	},
			element.getElement('form')
		);
	}
	
	// //Init the switchEvent
	// initSwitch: function(){
	// 	["previous", "nexxt"].each(function(direction){
	// 		if(this.link[direction]){
	// 			this.link[direction].addEvent('click', this.slide.bindWithEvent(this, direction));
	// 		}
	// 	}, this);
	// },
	
	// //Go to the next version
	// slide: function(e, direction){
	// 	e.stop(); 
	// 	if(this.allow[direction]){
	// 		this.allow[direction] = false;
	// 		this.slide.allow = false;
	// 		
	// 		//The slide effect (noobSlide)
	// 		if(direction == "previous"){
	// 			this.options.slider.walk((this.options.slider.currentIndex>0 ? this.options.slider.currentIndex-1 : this.options.slider.items.length-1),[true]);
	// 		}if(direction == "nexxt"){
	// 			this.options.slider.walk((this.options.slider.currentIndex<this.options.slider.items.length-1 ? this.options.slider.currentIndex+1 : 0),[true]);
	// 		}
	// 		
	// 		//Show the fact that a process is in curse
	// 			this.opacify(0.4, this);
	// 		//Change the next-previous arrows
	// 			this.changeArrows(direction, this);
	// 		
	// 		//Create a new upshot instance if the next upshot have a next version that is not already created
	// 			if(this.upshot[direction].options[direction] && !this.all_upshots[this.upshot[direction].options[direction]]){
	// 				//Search the datas of the next upshot
	// 			    var url = StudioMelipone.UpShot.Routes.get(StudioMelipone.UpShot.Routes.Version.change_version, { user_id: this.upshot[direction].options.user.id, upshot_id: this.upshot[direction].options.id })
	// 			    	// Create the request
	// 						this.index_request = new Request.Auth({
	// 							url: url,
	// 							method: 'get',
	// 							headers:{
	// 								'X-Request' : 'JSON',
	// 								'X-Requested-With' : 'XMLHttpRequest'
	// 							},
	// 							onSuccess: this.addVersion.bindWithEvent(this, direction),
	// 							onFailure: this.failure.bindWithEvent(this)
	// 						});
	// 						this.index_request.send({direction: direction});
	// 			}else{
	// 				this.changeVersion(direction, this);
	// 			}			
	// 
	// 	}
	// 
	// },
	
	
	// //Add the next version instance and html
	// addVersion: function(text, direction){
	// 		
	// 	window._upshots[this.upshot[direction].options[direction]] = JSON.decode(text);
	// 	
	// 
	// 	//Add the html
	// 	this.addUpshot({
	// 		direction: direction,
	// 		id: this.upshot[direction].options[direction],
	// 		image: {url: window._upshots[this.upshot[direction].options[direction]].image.url, height: window._upshots[this.upshot[direction].options[direction]].image.height, width: window._upshots[this.upshot[direction].options[direction]].image.width},
	// 		user: {id: window._upshots[this.upshot[direction].options[direction]].user.id}
	// 	});
	// 	
	// 	this.changeVersion(direction, this);
	// },
	
	// failure: function(e){
	// 	
	// },
	
	// //Create the html for a new upshot
	// addUpshot: function(opt){
	// 	var div = new Element('div', {'class':'upshot_version'}); 
	// 	//The global div that will contain all the new upshot
	// 	var upshot_container = new Element('div', {'class': opt.direction, 'id': opt.id});
	// 	//First level in upshot_container
	// 	var picture = new Element('div', {'class':'picture'});
	// 	var comments = new Element('div', {'class':'comments'});
	// 	//Second level in picture
	// 	var cliquer = new Element('img', {'class':'justclick','src': _('/img/en/just-click_en.png'), 'alt': _("Just double click on the picture below to leave comments!")});
	// 	var image = new Element('div', {'class':'image', 'styles': {'background': 'url('+opt.image.url+')', 'height': opt.image.height, 'width': opt.image.width}});
	// 	//Second level in comments
	// 	var wrapper = new Element('div', {'class':'wrapper', 'styles':{'background': "none repeat scroll 0 0 transparent"} });
	// 	//Third level in wrapper
	// 	var form = new Element('form', {'id':'new_comment', 'class':'new_comment', 'method':'post', 'action':'/'+_('en')+'/users/'+opt.user.id+'/upshots/'+opt.id+'/update_comments' } );
	// 	var title = new Element('h1', {'html':_('Comments')});
	// 	var commentlist = new Element('ol', {'class':'commentlist'});
	// 	//Fourth level in form
	// 	var div1 = new Element('div');
	// 	var div2 = new Element('div');
	// 	var div3 = new Element('div');
	// 	//Fifth level in div1
	// 	var validate = new Element('input', {'class':'validate', 'type':'image', 'name':'commit[accept]', 'src':_('/img/en/btn-validate_en.png')});
	// 	//Fifth level in div2
	// 	var textarea = new Element('textarea', {'class':'area', 'id':'comment_comment', 'rows':6, 'cols':10, 'name':'comment[comment]'});
	// 	var send = new Element('input', {'class':'btn send_message', 'type':'image', 'name':'commit[send]', 'src':_('/img/en/btn-sendmessage_en.png')});
	// 	//Fifth level in div3
	// 	var p = new Element('p');
	// 	var label = new Element('label');
	// 	var required = new Element('span',{'class':'required'});
	// 	var elem = new Element('span', {'class':'element'});
	// 	var fileattach = new Element('a',{'class':'btn btnGrey ', 'id':'file-attach-'+opt.id, 'href':'#'});
	// 	var clear = new Element('span',{'class':'clear'});
	// 	var filelist = new Element('ul',{'id':'file-list-'+opt.id});
	// 	
	// 	//Construct the parentship
	// 	label.set('text', 'File');
	// 	required.set('text','*');
	// 	label.adopt(required);
	// 	fileattach.set('text', 'Select one or more files');
	// 	elem.adopt(fileattach);
	// 	p.adopt(label, elem, clear);
	// 	div1.adopt(validate);
	// 	div2.adopt(textarea, send);
	// 	div3.adopt(p, filelist);
	// 	form.adopt(div1, div2, div3);
	// 	wrapper.adopt(form, title, commentlist);
	// 	comments.adopt(wrapper);
	// 	picture.adopt(cliquer.clone(), image, cliquer);
	// 	upshot_container.adopt(picture, comments);
	// 	div.adopt(upshot_container);
	// 	
	// 	//Add the upshot to the slider
	// 	this.options.slider.addItem(div, opt.direction, (opt.image.width)>900?(opt.image.width)+240:900+240, this.container[opt.direction].offsetHeight);
	// 	
	// 	//Add the elements to the HTML
	// 	if(opt.direction == "nexxt"){
	// 		this.global_container.adopt(div);
	// 	}else if(opt.direction == "previous"){
	// 		this.global_container.grab(div, 'top');
	// 	}
	// 	
	// 	this.uploaderInstance(opt);		
	// 
	// },
	
	
	// uploaderInstance: function(opt){
	// 	var up = new FancyUpload3.Attach('file-list-' + opt.id, '#file-attach-' + opt.id, {
	//     		path: '/Swiff.Uploader.swf',
	//     		url: '/en/users/'+ opt.user.id +'/upshots/handle_swf_file?_upshot_rails_2_3_session=BAh7CjoPc2Vzc2lvbl9pZCIlMDZlOTc1MDdkYmYwMTgzZWJhOWVkNjBmMzlhZDI5M2I6DHVzZXJfaWRpAvcDOgtsb2NhbGUiB2ZyOhBfY3NyZl90b2tlbiIxZ29Uc25CdTBYODJOSlZRVG5xR3BuYitldGErVHVPZlRuaCs0Ui9jMk5rMD0iCmZsYXNoSUM6J0FjdGlvbkNvbnRyb2xsZXI6OkZsYXNoOjpGbGFzaEhhc2h7AAY6CkB1c2VkewA%3D--50289f1185a176595fba72e28eed9961abcd2329&amp;authenticity_token=goTsnBu0X82NJVQTnqGpnb%2Beta%2BTuOfTnh%2B4R%2Fc2Nk0%3D',
	//     		fileList: true,
	//     		multiple: true,
	//     		queued: true,
	//     		verbose: true,
	// 
	//     		onSelectFail: function(files){
	//     			files.each(function(file) {
	//     				new Element('li', {
	//     					'class': 'file-invalid',
	//     					events: {
	//     						click: function() {
	//     							this.destroy();
	//     						}
	//     					}
	//     				}).adopt(
	//     					new Element('span', {html: file.validationErrorMessage || file.validationError})
	//     				).inject(this.list, 'bottom');
	//     			}, this);	
	//     		},
	// 
	//     		onFileRemove: function(file){
	//     		  $('submittrio').getElements('input').each(function(el){
	//     		    el.disabled = 0;
	//     		    el.set("style", "opacity: 1;");
	//   		    });
	//     		},
	// 
	//     		onSelectSuccess: function(files) {
	//     		  $('submittrio').getElements('input').each(function(el){
	//     		    el.disabled = 1;
	//     		    el.set("style", "opacity: 0.3;");
	//   		    });
	//     		},
	// 
	//     		onFileSuccess: function(file) {
	//     		  var result = JSON.decode(file.response.text);
	//           $('submittrio').getElements('input').each(function(el){
	//     		    el.disabled = 0;
	//     		    el.set("style", "opacity: 1;");
	//   		    });
	//           if(result.status == "ok"){
	//             new Element('input', {type: 'checkbox', name: 'comment[file_ids][]', 'checked': true, 'value':result.asset.id }).inject(file.ui.element, 'top');
	//       			file.ui.element.highlight('#e6efc2');
	//           }
	//           else if(result.status == "nok"){
	//             new Element('span', {html: 'This file is not valid has an UpShot attachment'}).inject(file.ui.element, 'bottom');
	//           }
	//     		},
	// 
	//     		onFileError: function(file) {
	//     			file.ui.cancel.set('html', 'Retry').removeEvents().addEvent('click', function() {
	//     				file.requeue();
	//     				return false;
	//     			});
	//           $('submittrio').getElements('input').each(function(el){
	//     		    el.disabled = 0;
	//     		    el.set("style", "opacity: 1;");
	//   		    });
	// 
	//     			new Element('span', {
	//     				html: file.errorMessage,
	//     				'class': 'file-error'
	//     			}).inject(file.ui.cancel, 'nexxt');
	//     		},
	// 
	//     		onFileRequeue: function(file) {
	//     			file.ui.element.getElement('.file-error').destroy();
	// 
	//           $('submittrio').getElements('input').each(function(el){
	//     		    el.disabled = 0;
	//     		    el.set("style", "opacity: 1;");
	//   		    });
	// 
	//     			file.ui.cancel.set('html', 'Cancel').removeEvents().addEvent('click', function() {
	//     				file.remove();
	//     				return false;
	//     			});
	// 
	//     			this.start();
	//     		}
	//     	});
	// },
	// 
	
	
	// //Change the javascript data
	// changeVersion: function(direction){
	// 	reverse = this.reverse(direction);
	// 	//Into the slide
	// 		//change the active parameter	
	// 			this.changeActive(direction, this);
	// 		//Change the div class
	// 			this.changeDiv(direction, reverse, this);
	// 		//Change the container
	// 			this.changeContainer(direction, reverse, this);
	// 		//Change the img container
	// 			this.changeImgContainer(direction, reverse, this);
	// 		//Change the pointer to the three main upshots	
	// 			this.changePointer(direction, reverse, this);
	// 		//Show the fact that the process end
	// 			this.opacify(1, this);
	// 		//Re allow the click
	// 			this.allow[direction] = true;
	// 			this.slide.allow = true;
	// 	//Into the top
	// 		//Change the title
	// 			this.changeTitle(this);
	// 		//Change preview image
	// 			this.changePreviewImg(this);
	// 		//Change the tags
	// 			this.changeTags(this);
	// 		//Change the url of the actions
	// 			this.changeActions(this);
	// 		//Change users tab
	// 			this.changeUserTab(this);
	// 		//Change the files tab
	// 			this.changeFilesTab(this);
	// },
	
	// //Change the files tab
	// changeFilesTab: function(){
	// 	//Change the action form
	// 	$('file_form').set('action', "/"+_('en')+"/users/"+window._upshots[this.upshot.current.options.id].owner.id+"/upshots/"+this.upshot.current.options.id+"/forward");
	// 	
	// 	//The table that contain the users informations
	// 	grid = $('files').getElement('table.grid');
	// 	//Remove the content of this table
	// 	grid.getElement('tbody').dispose();
	// 	if(this.fbody){
	// 		this.fbody.dispose();
	// 	}
	// 
	// 	//Then recreate the users informations
	// 	this.fbody = new Element('tbody');
	// 	
	// 	attach = window._upshots[this.upshot.current.options.id].asset;
	// 	content = 	{
	// 					'owner':{
	// 						'checkbox':{'markup':'input', 'id':'files_to_forward_upshot_asset', 'type':'checkbox','value':attach.id, 'checked':'checked'},
	// 						'icon':{'markup':'img', 'src':attach.icon, 'alt':'Icon-image'},
	// 						'name':{'markup':'td', 'textContent':TextHelper.truncate(attach.name)},
	// 						'size':{'markup':'td', 'textContent':TextHelper.number_to_human_size(attach.size)},
	// 						'link':{'markup':'a', 'href':attach.link ,'textContent':_("Download")}
	// 					}
	// 				};
	// 
	// for(i in window._upshots[this.upshot.current.options.id].supattachments){
	// 	attach = window._upshots[this.upshot.current.options.id].supattachments[i];
	// 	content[i] = 	{
	// 						'checkbox':{'markup':'input', 'id':'files_to_forward_upshot_asset', 'type':'checkbox','value':attach.id, 'checked':'checked'},
	// 						'icon':{'markup':'img', 'src':attach.icon, 'alt':'Icon-image'},
	// 						'name':{'markup':'td', 'textContent':TextHelper.truncate(attach.name)},
	// 						'size':{'markup':'td', 'textContent':TextHelper.number_to_human_size(attach.size)},
	// 						'link':{'markup':'a', 'href':attach.link ,'textContent':attach.ok?_("Download"):_("Deleted")}
	// 					};
	// }
	// 		
	// 	HtmlHelper.generateTable(content, this.fbody);
	// 		
	// 	grid.adopt(this.fbody);
	// },
	
	// //Change users tab
	// changeUserTab: function(){
	// 	//The table that contain the users informations
	// 	grid = $('users').getElement('table.grid');
	// 	//Remove the content of this table
	// 	grid.getElement('tbody').dispose();
	// 	grid.getElement('thead').dispose();
	// 	if(this.ubody){
	// 		this.ubody.dispose();
	// 	}if(this.uhead){
	// 		this.uhead.dispose();
	// 	}
	// 	
	// 	//Then recreate the users informations
	// 	this.ubody = new Element('tbody');
	// 	this.uhead = new Element('thead');
	// 	
	// 	head = {
	// 				'head':{
	// 					'icon':{'markup':'th', 'className':'icon'},
	// 					'name':{'markup':'th', 'textContent':_("Name")},
	// 					'description':{'markup':(window._upshots[this.upshot.current.options.id].is_user?'th':'EMPTY'), 'textContent':'Description'},
	// 					'creation':{'markup':'th', 'className':'dates', 'textContent':_("Date")},
	// 					'validated':{'markup':'th', 'className':'dates', 'textContent':_("Validated on")}
	// 				}
	// 			};
	// 	HtmlHelper.generateTable(head, this.uhead, 'th');
	// 	
	// 	
	// 	owner = window._upshots[this.upshot.current.options.id].owner;
	// 	content = 	{
	// 					'owner':{
	// 						'image':{'markup':'img', 'src':owner.profile_picture, 'alt':'Avatar_Smaller'},
	// 						'name':{'markup':'td', 'className':'owner_name', 'textContent':owner.display_name},
	// 						'description':{'markup':(window._upshots[this.upshot.current.options.id].is_user?'td':'EMPTY'), 'textContent':''},
	// 						'creation':{'markup':'td', 'textContent':window._upshots[this.upshot.current.options.id].creation_date},
	// 						'validated':{'markup':'td', 'className':(window._upshots[this.upshot.current.options.id].validation?'validated':''), 'textContent':window._upshots[this.upshot.current.options.id].validation_date} 
	// 					}
	// 				};
	// 	
	// 	for(i in window._upshots[this.upshot.current.options.id].customers){
	// 		cust = window._upshots[this.upshot.current.options.id].customers[i];
	// 		content[i] = 	{
	// 							'image':{'markup':'img', 'src':cust.profile_picture, 'alt':'Avatar_Smaller'},
	// 							'name':{'markup':'td', 'className':'customer_name', 'textContent':cust.display_name},
	// 							'description':{'markup':(window._upshots[this.upshot.current.options.id].is_user?'td':'EMPTY'), 'textContent':cust.comment},
	// 							'creation':{'markup':'td', 'textContent':window._upshots[this.upshot.current.options.id].creation_date},
	// 							'validated':{'markup':'td', 'className':(cust.validation?'validated':''), 'textContent':cust.validation_date}
	// 						};
	// 	}
	// 	HtmlHelper.generateTable(content, this.ubody);
	// 	
	// 	grid.adopt(this.uhead, this.ubody);
	// 
	// },
	// //Change the tag
	// changeTags: function(){
	// 	$('tags').set({'text':window._upshots[this.upshot.current.options.id].tags});
	// },
	
	// //Change the url of the actions
	// changeActions: function(){
	// 	//Change edit url
	// 	$$('li.edit').getElement('a').set('href', "/"+_('en')+"/users/"+window._upshots[this.upshot.current.options.id].owner.id+"/upshots/"+this.upshot.current.options.id+"/edit");
	// 	//Change archived url
	// 		if(window._upshots[this.upshot.current.options.id].is_archived == true){
	// 			$$('li.archive').set('class', 'unarchive');
	// 			$$('li.unarchive').getElement('a').set('text', _('Unarchive'));
	// 			$$('li.unarchive').getElement('a').set('href', "/"+_('en')+"/users/"+window._upshots[this.upshot.current.options.id].owner.id+"/upshots/"+this.upshot.current.options.id+"/unarchive");
	// 		}
	// 		else{
	// 			$$('li.unarchive').set('class', 'archive');
	// 			$$('li.archive').getElement('a').set('text', _('Archive'));
	// 			$$('li.archive').getElement('a').set('href', "/"+_('en')+"/users/"+window._upshots[this.upshot.current.options.id].owner.id+"/upshots/"+this.upshot.current.options.id+"/archive");				
	// 		}
	// 	//Change export pdf url
	// 	$$('li.pdf').getElement('a').set('href', "/"+_('en')+"/users/"+window._upshots[this.upshot.current.options.id].owner.id+"/upshots/"+this.upshot.current.options.id+".pdf");
	// 	//Change the rss feed url
	// 	$$('li.rss').getElement('a').set('href', "/rss/"+window._upshots[this.upshot.current.options.id].rss_hash);
	// 	//Change the move_to url
	// 	$$('.move_to').getElement('form').set('action', "/"+_('en')+"/users/"+window._upshots[this.upshot.current.options.id].owner.id+"/upshots/"+this.upshot.current.options.id+"/move_to");
	// 	//Change the send email url
	// 	$$('form.flow').set('action', "/"+_('en')+"/users/"+window._upshots[this.upshot.current.options.id].owner.id+"/upshots/"+this.upshot.current.options.id+"/forward");
	// 	//Create or delete the "new version" icon
	// 		//If there is actually the icon and if the actual upshot have a next version... 
	// 		if($$('li.version')[0] && window._upshots[this.upshot.current.options.id].children_count > 0){
	// 			//.. then we can't add a new version
	// 			$$('li.version')[0].dispose();
	// 		}//If there isn't the li.version but the actual upshot is th last one...
	// 		else if(!$$('li.version')[0] && !window._upshots[this.upshot.current.options.id].children_count){
	// 			//.. then we add the new version icon
	// 			link = new Element('a', {'href':"/"+_('en')+"/users/"+window._upshots[this.upshot.current.options.id].owner.id+"/upshots/"+this.upshot.current.options.id+"/new_version",
	// 										'text':_("New Version")});
	// 			vers = new Element('li', {'class':'version'});
	// 			vers.adopt(link);
	// 			$('actions1').adopt(vers);
	// 		}
	// },
	
	// //Change the preview image in the top
	// changePreviewImg: function(){
	// 	$('preview_img').set('src', window._upshots[this.upshot.current.options.id].image.large)
	// },
	
	// //Change the title in the top
	// changeTitle: function(){
	// 	$('title').getElement('h1').set('text', window._upshots[this.upshot.current.options.id].title);
	// },
	
	// //Change the next-previous arrows
	// changeArrows: function(direction){
	// 	if(!this.upshot[direction].options[direction]){
	// 		this.link[direction] = this.link[direction].dispose();
	// 	}
	// 	if(!$defined($$('span.next')[0]) && this.upshot[direction].options["nexxt"]){
	// 		$$('p.buttons8').adopt(this.link["nexxt"]);
	// 	}
	// 	if(!$defined($$('span.prev')[0]) && this.upshot[direction].options["previous"]){
	// 		$$('p.buttons8').grab(this.link["previous"], "top");
	// 	}	
	// },
	
	// //Change opacity of the arrows
	// opacify: function(n){
	// 	if(this.upshot.nexxt){
	// 		this.link["nexxt"].get('tween').start('opacity', n);
	// 	}
	// 	if(this.upshot.previous){
	// 		this.link["previous"].get('tween').start('opacity', n);
	// 	}
	// },
	
	// //Calculate the inverse direction of the direction
	// reverse: function(direction){
	// 	if(direction == "previous"){
	// 		reverse = "nexxt";
	// 	}else if(direction == "nexxt"){
	// 		reverse = "previous";
	// 	}
	// 	
	// 	return reverse;
	// },
	
	// //change the active parameter
	// changeActive: function(direction){
	// 	this.upshot["current"].changeActive(false, this.upshot["current"]);		//The active upshot is now unactive
	// 	this.upshot[direction].changeActive(true, this.upshot[direction]);		//The next upshot is now active
	// }, 
	
	// //Change the div class
	// changeDiv: function(direction, reverse){
	// 	this.upshot["current"].options.global_container.set('class', reverse);	//Current to previous
	// 	this.upshot[direction].options.global_container.set('class', "current");	//Next to current
	// 	if(this.all_upshots[this.upshot[direction].options[direction]]){
	// 		this.all_upshots[this.upshot[direction].options[direction]].options.global_container.set('class', direction);
	// 	}
	// 
	// 	if(this.upshot[reverse]){
	// 		this.upshot[reverse].options.global_container.set('class', "");			//Previous to nothing
	// 	}
	// }, 
	
	// //Change the container
	// changeContainer: function(direction, reverse){
	// 	this.container[reverse]	= this.container["current"];
	// 	this.container["current"] 	= this.container[direction];
	// 	if(this.upshot[direction].options[direction]){
	// 		this.container[direction] = $$('div.'+direction)[0];
	// 	}
	// }, 
	
	// //Change the img container
	// changeImgContainer: function(direction, reverse){
	// 	this.upshot_img[reverse]	= this.upshot_img["current"];
	// 	this.upshot_img["current"]	= this.upshot_img[direction];	
	// 	if(this.upshot[direction].options[direction]){
	// 		this.upshot_img[direction]	= this.container[direction].getElement('.image');
	// 	}
	// },
	
	// //Change the pointer to the three main upshots	
	// changePointer: function(direction, reverse){
	// 	this.upshot[reverse] = this.upshot["current"]; 
	// 	this.upshot["current"] = this.upshot[direction]; //The next became the current
	// 	//If the new current upshot has a next upshot and is not already in the upshot instance hash...
	// 	if(this.upshot["current"].options[direction] && !this.all_upshots[this.upshot["current"].options[direction]]){
	// 		//... Then we create the upshot instance 
	// 		this.createUpshotInstance(direction, window._upshots[this.upshot[direction].options[direction]]);
	// 	}//If the new current upshot has a next upshot that is already created... 
	// 	else if(this.upshot["current"].options[direction] && this.all_upshots[this.upshot["current"].options[direction]]){
	// 		//...Then we change the next upshot pointer to the right insctance in the all_upshot array
	// 		this.upshot[direction] = this.all_upshots[this.upshot["current"].options[direction]];
	// 	}else{
	// 		this.upshot[direction] = null;
	// 	}
	// },

	// //Create the javascript instance of the upshot
	// createUpshotInstance: function(direction, opt){
	// 	this.upshot[direction] =  new StudioMelipone.UpShot(this.upshot_img[direction], this.upshot_img[direction], this.container[direction].getElement('.commentlist'), this.container[direction].getElement('.picture'),
	// 	 						{global_container: this.container[direction], user: opt.user, id: opt.id, active: false, nexxt: opt.nexxt, previous: opt.previous }, 
	// 							this.container[direction].getElement('.send_message'));
	// 	this.all_upshots.set(this.upshot[direction].options.id, this.upshot[direction]);
	// 	this.container[direction].setStyle('width', window._upshots[this.upshot[direction].options.id].image.width > 900? window._upshots[this.upshot[direction].options.id].image.width:900);		
	// }
});


if(!$defined(StudioMelipone)){ var StudioMelipone = new Hash(); }
if(!$defined(StudioMelipone.UpShot)){ StudioMelipone.UpShot = new Hash(); }

StudioMelipone.UpShot.Reply = new Class({
	Implements: [Options, Events],
	
	options: {
		id: 				$empty,
		created_at: $empty,
		user: 			$empty,
		content: 		"",
		editable: 	true,
		after_validation: false,
		parent_id: 	0,
		validation:   false,
		global_container: $empty,
		upshot_id: $empty
	},
	// note dom element
	comment: $empty,
	
	initialize: function(parent, options){
		this.setOptions(options);
		
		this.parent_note = parent;
		this.options.parent_id = parent.options.id;
		
		this.comment = this.createComment(/*{ user: this.options.user, created_at: this.options.created_at }*/);
	},
	
	setDate: function(date){
		this.options.created_at = date;
		this.comment.header.getElement('.date_to_convert').set('time', date);
	},

	colorFromStatus: function(){
		if(this.options.after_validation) return '#DF8615';
		if(this.options.validation != false && (this.options.created_at == 'now' || this.options.created_at == 'maintenant')) return '#DF8615';

		return this.options.user.type == 'user' ? '#c66ecc' : '#5AB661';
	},

	createClearDiv: function() {
		return new Element('div',
		{
			'class': "clear_both",
			'html': '&nbsp;'
		});
	},
	
	createComment: function(){
		var comment = new Element('div',
		{
			'class': 'comment alt',
			'html': '<div class="ds-r"></div><div class="ds-b"></div><div class="ds-br"></div>'
		});
		
		if(this.options.editable){ comment.addClass('respond'); }
		
		comment.header = this.createCommentHeader(); comment.adopt(comment.header);
		comment.content = this.createContent(); comment.adopt(comment.content);
		
		if(this.options.editable){
			// Means it's comment created by the user
			comment.save_button = this.createSaveButton(); comment.adopt(comment.save_button);
			comment.cancel_button = this.createCancelButton(); comment.adopt(comment.cancel_button);
		}
		
		comment.clear_div = this.createClearDiv();
		comment.adopt(comment.clear_div);
		
		return comment;
	},
	
	createCommentHeader: function(){
		// var header = new Element('div',
		// {
		// 	'class': 'profile',
		// 	'html': '<a class="avatar" href="#"><img src="' + this.options.user.avatar.smaller + '" alt="' + this.options.user.name + '" /></a><p class="name" style="color:'+ (( this.options.after_validation || this.options.validation || (this.options.validation != false && (this.options.created_at == 'now' || this.options.created_at == 'maintenant'))) ? '#DF8615' : (this.options.user.type == 'user' ? '#c66ecc' : '#5AB661')) +'">' + this.options.user.name + '</p><p class="date date_to_convert" time="' + this.options.created_at + '">' + this.options.created_at + '</p><div style="clear:both;"></div>'
		// });
		
		var header = new Element('div',
		{
			'class': 'profile',
			'html': '<a class="avatar" href="#"><img src="' + this.options.user.avatar.smaller + '" alt="' + this.options.user.name + '" /></a><p class="name" style="color:'+ this.colorFromStatus() +'">' + this.options.user.name + '<br/><small class="date date_to_convert" time="' + this.options.created_at + '">' + this.options.created_at + '</small></p><div style="clear:both;"></div>'
		});
		
		
		return header;
	},
	
	createContent: function(){
		var content = new Element('div',
		{
			'class': 'text'
		});
		
		// We create a this.textarea because there should be only one textarea on a note at a time
		// and it's easier to always have a link to it
		if(this.options.editable){
			this.textarea = content.textarea = new Element('textarea'); content.adopt(content.textarea);
			// Backlink to easy delete
			this.textarea.content = content;
		}else{
			content.set('html', this.options.content);
		}
		
		if(this.options.user.id==0){
			content.set('html', "Vous devez être connecté pour laisser une note");
		}else if(this.options.user.type=="admin"){
			content.set('html', "Vous ne pouvez pas laisser de note si vous n'êtes pas client ou createur de l'UpShot");
		}
		
		return content;
	},
	
	createSaveButton: function(){
		return this.createButton(_("Send"), this.save, 'reply green');
	},
	
	createCancelButton: function(){
		return this.createLink(_("Cancel"), this.cancel, 'delete red');
	},
	
	createButton: function(label, callback, css_class, img){
		var css_class = $pick(css_class, "reply");
		
		var button = new Element('div',
		{
			'class': css_class
		});
		
		if(this.options.user.id==0 || this.options.user.type=="admin"){
			css_class += " disabled"
		}
		
		if($chk(img)){
			button.set('html', '<a href="#" class="button ' + css_class + '">' + label + img + '</a>');
		}else{
			button.set('html', '<a href="#" class="button ' + css_class + '">' + label + '</a>');
		}
		
		if(this.options.user.id!=0 && this.options.user.type!="admin"){
			button.addEvent('click', callback.bindWithEvent(this, button));
		}
		
		return button;
	},

	createLink: function(label, callback, css_class, img){
		var css_class = $pick(css_class, "reply");

		var button = new Element('div',
		{
			'class': css_class
		});

		if($chk(img)){
			button.set('html', '<a href="#" class="' + css_class + '">' + label + img + '</a>');
		}else{
			button.set('html', '<a href="#" class="' + css_class + '">' + label + '</a>');
		}

		button.addEvent('click', callback.bindWithEvent(this, button));

		return button;
	},
	
	cancel: function(e, cancel_button){
		e.stop();
		cancel_button.removeEvents('click');
		
		this.comment.get('tween').start('opacity', 0).chain(function() { this.element.dispose(); });

		this.parent_note.replys.erase(this);
		var rb = this.parent_note.showReplyButton();
		this.parent_note.element.comments.comment.clear_div.inject(rb, 'after');
	},
	
	save: function(e, save_button){
		e.stop();
		var content = this.textarea.get('value');
		// Should never be empty
		if(content == ""){
			alert(_("Please enter some text"));
		}else{
			// Remove the click to avoid double requests
			save_button.removeEvents('click');
		
			this.comment.cancel_button.get('tween').start('opacity', 0).chain(function() { this.element.dispose(); });
		
			// Show the user we are doing sth
			save_button.fade(0.3);
			// Request the note save
			this.save_request = $pick(
				this.save_request, 
				new Request.Auth({
					url: StudioMelipone.UpShot.Routes.get(StudioMelipone.UpShot.Routes.Notes.reply, { user_id:  _upshots[this.options.upshot_id]['user'].id, 
																									upshot_id: _upshots[this.options.upshot_id].id, note_id: this.parent_note.options.id }),
					headers:{
						'X-Request' : 'JSON',
						'X-Requested-With' : 'XMLHttpRequest'
					},
					onSuccess: this.saveSuccess.bindWithEvent(this, save_button),
					onFailure: this.failure.bindWithEvent(this, save_button)
				})
			);
			this.save_request.send({'content': content});
		}
	},
		
	saveSuccess: function(text, save_button){
		// Decode the JSON
		var datas = JSON.decode(text);
		
		// Fill the object
		this.options.id 				= datas.id;
		this.setDate(datas.created_at); // easier for the js time_ago_in_words
		this.options.user				= datas.user;
		this.options.content		= datas.content;
		this.options.editable		= false; //TODO create a setEditable() function that handles element cleaning
		this.options.parent_id	= datas.parent_id;
		this.options.after_validation = datas.after_validation;

		// Notify that the note should move from Melipone-Upshot.new_notes to Melipone-Upshot.notes
		this.parent_note.fireEvent("reply", [this]);

		// Remove the save button
		save_button.get('tween').start('opacity', 0).chain(function() { save_button.dispose(); });
		
		// Change the textarea for a div
		var myFx = new Fx.Tween(this.textarea);
		myFx.start('opacity', 0).chain(
			function(){
				var content = this.textarea.content;
				// Remove the textarea
				this.textarea.dispose(); this.textarea = $empty;
				// Add the newly created content
				content = this.createContent(this.options.content).replaces(content);
				// Add the answer button
				content.reply_button = this.parent_note.createReplyButton(); content.reply_button.injectBefore(this.comment.clear_div);
				// Nice effect
				content.setStyle('opacity', 0); content.fade('in');
			}.bind(this)
		);
	},
	
	failure: function(){
		
	}
	
});

if(!$defined(StudioMelipone)){ var StudioMelipone = new Hash(); }
if(!$defined(StudioMelipone.UpShot)){ StudioMelipone.UpShot = new Hash(); }
var timer;
StudioMelipone.UpShot.Note = new Class({
	Implements: [Options, Events],
	
	options: {
		id: 				$empty,
		picture: 		$empty,	//$$('.current').getElement('.image')[0],
		h: 					35,
		w: 					35,
		created_at: 		$empty,
		user: 				$empty,
		content: 			"",
		editable: 			true,
		state: 				"shown",
		replys: 			new Hash(),
		thumbnail: 			$empty,
		type: 				$empty,
		after_validation: 	false,
		validation:   		false,
		current_container: 	$empty,
		upshot_id: 			$empty,
		status: "neutral"

	},
	// note dom element
	element: $empty,
	
	replys: new Array(),
	
	initialize: function(x, y, z, opt){
		this.setOptions(opt);
		
		this.position = { 'x': x-1, 'y': y-2, 'z': z };
		
		this.element = this.createArea();
		this.element.zone = this.createZone(); this.element.adopt(this.element.zone);
		this.element.comments = this.createComments({ user: this.options.user, created_at: this.options.created_at }); this.element.adopt(this.element.comments);
	},
		
	setZ: function(z){
		this.position.z = z;
		this.element.setStyle('z-index', z);
	},
	
	getZ: function(){
		return this.position.z;
	},
	
	colorFromStatus: function(){
		if(this.options.after_validation) return '#DF8615';
		if(this.options.validation != false && (this.options.created_at == 'now' || this.options.created_at == 'maintenant')) return '#DF8615';
		
		return this.options.user.type == 'user' ? '#c66ecc' : '#5AB661';
	},
	
	setDate: function(date){
		this.options.created_at = date;
		this.element.comments.comment.header.getElement('.date_to_convert').set('time', date);
	},
	
	updatePosition: function(note){
	  var current_image = $$('.current .image')[0];
		var p = note.getPosition(current_image);
		this.position.x = p.x+1;
		this.position.y = p.y+2;
	},
	
	makeDraggable: function(){
		if(this.options.editable){
			var size = this.options.picture.getSize();
			var rel_coords = this.options.picture.getCoordinates(this.element);
			
			this.resizable = this.element.zone.makeResizable({
				snap: 0,
				limit: { x: [35, rel_coords.right-8], y: [35, rel_coords.bottom-25] },
				handle: this.element.resize,
				preventDefault: true,
				onStart: function(el){ // $$('.image')
				  var curr_image = $$(".current .image")[0];
				  var parent = el.getParent();
					var rel_gr_coords = curr_image.getCoordinates(parent);
					this.limit = { x: [35, rel_gr_coords.right-8], y: [35, rel_gr_coords.bottom-25+17] };
				},
				onDrag: function(el){
					var parent = el.getParent();
					parent.getLast().set("styles", {
						"left": this.value.now.x + 20
					});
					
					var size = el.getSize();
					el.maximise.setStyles({
						"width": size.x-2,
						"height": size.y-2
					});
				}
			});
			this.draggable = this.element.makeDraggable({
				limit: {
					x: [0, size.x-43],
					y: [0, size.y-43]
				},
				handle: this.element.zone,
				onStart: function(el){
				  var drag_im = $$('.current .image')[0];
					var size = drag_im.getSize();
					var elsize = el.getSize();
					this.limit = { x: [0, size.x - elsize.x - 18], y: [0, size.y - elsize.y - 18] };
				},
				onComplete: this.updatePosition.bindWithEvent(this)
			});
		}
	},
	
	createClearDiv: function() {
		return new Element('div',
		{
			'class': "clear_both",
			'html': '&nbsp;'
		});
	},
	
	createArea: function(){
		var area = new Element('div',
		{
			'class': 'area',
			'styles': {
				'border-color': this.colorFromStatus(),
				'left': this.position.x,
				'top': this.position.y,
				'z-index': this.position.z
			}
		});
		
		if(this.options.editable){
			area.resize = new Element('div',
			{
				'styles': {
					'position': 'absolute',
					'right': 1,
					'bottom': -3,
					'z-index': 1000
				},
				html: '<img alt="Resize" src="/img/icon-resize.gif" class="resize"/>',
				events: {
					'click': function(e){ e.stop(); }
				}
			});	area.adopt(area.resize);
		}
		
		return area;
	},
	
	createZone: function(){
		var zone = new Element('a',
		{
			'href': '#',
			'class': 'click',
			'styles': {
				'height': this.options.h,
				'width': this.options.w
			},
			'html': '<img src="/images/site/clear.gif" alt="Empty pixel" />'
		});
		
		zone.maximise = new Element('div',
		{
			'styles': {
				'height': this.options.h-2,
				'width': this.options.w-2,
				'background-color': "transparent",
				'position': 'absolute',
				'left': 1,
				'top': 1
			},
			'events': {
				'click': this.show.bindWithEvent(this, true)
			}
		}); zone.adopt(zone.maximise);
		
		return zone;
	},
	
	createComments: function(){
		var comments = new Element('div',
		{
			'class': 'comments',
			'styles': {
				'left': 20 + this.options.w,
				'top': -3
			}
		});
		
		// If comment is empty create a comment with a textarea (meaning it's a new note)
		// or creates a comment from comment datas
		comments.comment = this.createComment(); comments.adopt(comments.comment);
		
		// Now take care of the possible answers
		var replys = $pick(this.options.replys, []);
		replys.each(function(r){
			// Creates a comment with the answer's datas
			var reply = new StudioMelipone.UpShot.Reply(this, { editable: false, id: r.id, created_at: r.created_at, user: r.user, content: r.content, after_validation: r.after_validation, global_container: r.global_container, upshot_id: r.upshot_id }); 
			comments.adopt(reply.comment);
			// Add it to the this.comments Array
			this.replys.push(reply);
		}.bind(this));
		
		// Creates the minimize handle
		comments.minimize = new Element('div',
		{
			'styles': {
				'position': 'absolute',
				'right': 5,
				'top': 5
			},
			'html': '<img alt="Close" src="/img/icon-close.gif"/>',
			'events': {
				'click': this.hide.bindWithEvent(this, true)
			}
		});	comments.adopt(comments.minimize);
		
		comments.comment.clear_div = this.createClearDiv();
		comments.comment.adopt(comments.comment.clear_div);
		
		if(this.options.editable){
			// Means it's comment created by the user
			comments.comment.save_button = this.createSaveButton(); comments.comment.save_button.injectBefore(comments.comment.clear_div);
			comments.comment.cancel_button = this.createCancelButton(); comments.comment.cancel_button.injectBefore(comments.comment.clear_div);
		}else{
			// Means we need to be able to reply to the last comment
			var last = $pick(this.replys.getLast(), comments);
			last.reply_button = this.createReplyButton(); last.reply_button.injectBefore(last.comment.clear_div); // last.comment.adopt(last.reply_button);
			
			if(_current_user.type=="customer"){
				// Creates the todo status bullet
				comments.todo = new Element('div',
				{
					'styles': {
						'position': 'absolute',
						'right': 20,
						'top': 5
					},
					'html': this.getImageFromStatus(),
					'class': this.options.status
				});
			}else{
				// Creates the todo status bullet
				comments.todo = new Element('div',
				{
					'styles': {
						'position': 'absolute',
						'right': 20,
						'top': 5,
						'cursor': 'pointer'
					},
					'html': this.getImageFromStatus(),
					'events': {
						'click': this.changeTodoStatus.bindWithEvent(this, true)
					}, 
					'class': this.options.status
				});	
			}
			comments.adopt(comments.todo);
			
		}
		
		return comments;
	},
	
	createComment: function(){
		var comment = new Element('div',
		{
			'class': 'comment',
			'html': '<div class="arrow"></div><div class="ds-r"></div><div class="ds-b"></div><div class="ds-br"></div>'
		});
		
		if(this.options.editable){ comment.addClass('respond'); }
		
		comment.header = this.createCommentHeader(); comment.adopt(comment.header);
		comment.content = this.createContent(); comment.adopt(comment.content);
		
		return comment;
	},
	
	createCommentHeader: function(){
		var header = new Element('div',
		{
			'class': 'profile',
			'html': '<a class="avatar" href="#"><img src="' + this.options.user.avatar.smaller + '" alt="' + this.options.user.name + '" /></a><p class="name" style="color:'+ this.colorFromStatus() +'">' + this.options.user.name + '<br/><small class="date date_to_convert" time="' + this.options.created_at + '">' + this.options.created_at + '</small></p><div style="clear:both;"></div>'
		});
		
		return header;
	},
	
	createContent: function(){
		var content = new Element('div',
		{
			'class': 'text'
		});
		
		// We create a this.textarea because there should be only one textarea on a note at a time
		// and it's easier to always have a link to it
		if(this.options.editable){
			this.textarea = content.textarea = new Element('textarea'); content.adopt(content.textarea);
			// Backlink to easy delete
			this.textarea.content = content;
		}else{
			content.set('html', this.options.content);
		}
		
		if(this.options.user.id==0){
			content.set('html', "Vous devez être connecté pour laisser une note");
		}else if(this.options.user.type=="admin"){
			content.set('html', "Vous ne pouvez pas laisser de note si vous n'êtes pas client ou createur de l'UpShot");
		}
		
		return content;
	},
	
	createSaveButton: function(){
		return this.createButton(_("Send"), this.save, 'reply green');
	},
	
	createCancelButton: function(){
		return this.createLink(_("Cancel"), this.cancel, 'delete red');
	},
	
	createReplyButton: function(){
		return this.createButton(_("Reply"), this.addReplyField);
	},
	
	createButton: function(label, callback, css_class, img){
		var css_class = $pick(css_class, "reply");
		
		var button = new Element('div',
		{
			'class': css_class
		});
		
		if(this.options.user.id==0 || this.options.user.type=="admin"){
			css_class += " disabled"
		}
		
		if($chk(img)){
			button.set('html', '<a href="#" class="button ' + css_class + '">' + label + img + '</a>');
		}else{
			button.set('html', '<a href="#" class="button ' + css_class + '">' + label + '</a>');
		}
		
		if(this.options.user.id!=0 && this.options.user.type!="admin"){
			button.addEvent('click', callback.bindWithEvent(this, button));
		}
		
		return button;
	},
	
	createLink: function(label, callback, css_class, img){
		var css_class = $pick(css_class, "reply");
		
		var button = new Element('div',
		{
			'class': css_class
		});
		
		if($chk(img)){
			button.set('html', '<a href="#" class="' + css_class + '">' + label + img + '</a>');
		}else{
			button.set('html', '<a href="#" class="' + css_class + '">' + label + '</a>');
		}
		
		button.addEvent('click', callback.bindWithEvent(this, button));
		
		return button;
	},
	
	save: function(e, save_button){
		e.stop();
		// Get the text
		var content = this.textarea.get('value');
		// Should never be empty
		if(content == ""){
			alert(_("Please enter some text"));
		}else{
			// Remove the click to avoid double requests
			save_button.removeEvents('click');
		
			this.element.comments.comment.cancel_button.get('tween').start('opacity', 0).chain(function() { this.element.dispose(); });
		
			// Show the user we are doing sth
			save_button.fade(0.3);
			// Request the note save
			this.save_request = $pick(
				this.save_request, 
				new Request.Auth({
					url: StudioMelipone.UpShot.Routes.get(StudioMelipone.UpShot.Routes.Notes.save, { user_id: _current_user.id, upshot_id: this.options.upshot_id }),
					headers:{
						'X-Request' : 'JSON',
						'X-Requested-With' : 'XMLHttpRequest'
					},
					onSuccess: this.saveSuccess.bindWithEvent(this, save_button),
					onFailure: this.failure.bindWithEvent(this, save_button)
				})
			);
			var size = this.element.zone.getCoordinates();
			this.save_request.send({ 'content': content,'x' : this.position.x, 'y' : this.position.y, 'w': size.width - 2 , 'h': size.height - 2 });
		}
	},
	
	cancel: function(e, cancel_button){
		e.stop();
		cancel_button.removeEvents('click');
		
		this.element.get('tween').start('opacity', 0).chain(function() { this.element.dispose(); });
	},
	
	addReplyField: function(e, reply_button){
		e.stop();
		
		// Nicely hide the reply button
		reply_button.get('tween').start('opacity', 0).chain(function() { reply_button.dispose(); });
		
		// Create a new editable answer
		var reply = new StudioMelipone.UpShot.Reply(this, {global_container: this.options.global_container, upshot_id: this.options.upshot_id, user: window._upshots[this.options.upshot_id]['user'], created_at: _("now"), validation: window._validation }); this.element.comments.adopt(reply.comment);
		reply.comment.setStyle('opacity', 0);	reply.comment.get('tween').start('opacity', 0, 1).chain(function() { reply.textarea.focus(); });
		
		// Add it to the this.comments Array
		this.replys.push(reply);
	},
	
	addReply: function(r){
		var reply = new StudioMelipone.UpShot.Reply(this, { editable: false, id: r.id, created_at: r.created_at, user: r.user, content: r.content, after_validation: r.after_validation, global_container: r.global_container, upshot_id: r.upshot_id }); this.element.comments.adopt(reply.comment);
		
		// Add it to the this.comments Array
		this.replys.push(reply);
	},
	
	showReplyButton: function(){
		var last = $pick(this.replys.getLast(), this.element.comments);
		last.comment.reply_button = this.createReplyButton(); last.comment.adopt(last.comment.reply_button);
		return last.comment.reply_button;
	},
	
	saveSuccess: function(text, save_button){
		// Decode the JSON
		var datas = JSON.decode(text);
		
		// Fill the object
		this.options.id 				= datas.id;
		this.options.number 		=	datas.number;
		this.setDate(datas.created_at); // cause we need a nice format to use js time_ago_in_words
		this.options.user				= datas.user;
		this.options.content		= datas.content;
		this.options.editable		= false;
		this.options.state			= datas.state;
		this.options.replys			= datas.replys;
		this.options.thumbnail	= datas.thumbnail;
		this.options.after_validation = datas.after_validation;
		this.options.type = datas.type;
		
		// Notify that the note should move from Melipone-Upshot.new_notes to Melipone-Upshot.notes
		this.fireEvent("save", [this]);
		
		// Remove darg and resize
		this.draggable.detach();
		this.resizable.detach();
		this.element.resize.get('tween').start('opacity', 0).chain(function() { this.element.dispose(); });

		// Remove the save button
		save_button.get('tween').start('opacity', 0).chain(function() { save_button.dispose(); });
		
		// add the todo bullet
		this.element.comments.comment.todo = new Element('div',
		{
			'styles': {
				'position': 'absolute',
				'right': 20,
				'top': 5
			},
			'html': '<img alt="" src="/images/icons/bullet_grey.png" />',
			'class': 'neutral'
		});
		this.element.comments.comment.adopt(this.element.comments.comment.todo);
		
		// Change the textarea for a div
		var myFx = new Fx.Tween(this.textarea);
		myFx.start('opacity', 0).chain(
			function(){
				var content = this.textarea.content;
				// Remove the textarea
				this.textarea.dispose(); this.textarea = $empty;
				// Add the newly created content
				content = this.createContent(this.options.content).replaces(content);
				// Add the answer button
				content.reply_button = this.createReplyButton(); content.reply_button.injectBefore(this.element.comments.comment.clear_div); //this.element.comments.comment.adopt(content.reply_button);
				// Nice effect
				content.setStyle('opacity', 0); content.fade('in');
				content.reply_button.setStyle('opacity', 0); content.reply_button.fade('in');
			}.bind(this)
		);

	},
	
	failure: function(){
		
	},
	
	hide: function(with_effect){
		if(with_effect){
			this.element.comments.get('tween').start('opacity', 0).chain(function(){
				this.element.setStyle("display", "none");
			});
		}else{
			this.element.comments.setStyles({
				'opacity': 0,
				'display': 'none'
			});
			//this.element.zone.maximise.setStyles('opacity', 1);
		}

		this.options.state = "hidden";
	},
	
	show: function(with_effect){
		if(with_effect){
			if(this.element.comments.get('opacity') == 0){
				this.element.comments.setStyle("display", "inline");
				this.element.comments.get('tween').start('opacity', 1);
				this.options.state = "shown";
			}
		}else{
			this.element.comments.setStyles({
				'opacity': 1,
				'display': 'inline'
			});
			//this.element.zone.maximise.setStyle('opacity', 0);
		}

		this.options.state = "shown";
	},
	
	getImageFromStatus: function(){
		if(this.options.status=="neutral"){
			return '<img alt="" src="/images/icons/bullet_grey.png" />';
		}else if(this.options.status=="todo"){
			return '<img alt="" src="/images/icons/bullet_red.png" />';
		}else if(this.options.status=="on_it"){
			return '<img alt="" src="/images/icons/bullet_yellow.png" />';
		}else if(this.options.status=="done"){
			return '<img alt="" src="/images/icons/bullet_green.png" />';
		}
	},
	
	changeTodoStatus: function(){
		if(timer!=null && timer!=undefined){
			clearTimeout(timer);
		}
		
		var todo = this.element.comments.todo
		
		if( todo.getProperty('class')=='neutral' ){
			this.element.comments.todo.set('class', 'todo');
			this.element.comments.todo.getElement('img').set('alt','Todo');
			this.element.comments.todo.getElement('img').set('src','/images/icons/bullet_red.png');
			this.element.comments.todo.getElement('img').set('title','Todo');
		} else if( todo.getProperty('class')=='todo' ){
			this.element.comments.todo.set('class', 'on_it');
			this.element.comments.todo.getElement('img').set('alt','Working on it');
			this.element.comments.todo.getElement('img').set('src','/images/icons/bullet_yellow.png');
			this.element.comments.todo.getElement('img').set('title','Working on it');
		}else if( todo.getProperty('class')=='on_it' ){
			this.element.comments.todo.set('class', 'done');
			this.element.comments.todo.getElement('img').set('alt','Done');
			this.element.comments.todo.getElement('img').set('src','/images/icons/bullet_green.png');
			this.element.comments.todo.getElement('img').set('title','Done');
		}else if( todo.getProperty('class')=='done' ){
			this.element.comments.todo.set('class', 'neutral');
			this.element.comments.todo.getElement('img').set('alt','');
			this.element.comments.todo.getElement('img').set('src','/images/icons/bullet_grey.png');
			this.element.comments.todo.getElement('img').set('title','');
		}
		
		var change_request = new Request.Auth({
			url: StudioMelipone.UpShot.Routes.get(StudioMelipone.UpShot.Routes.Notes.change_status, { upshot_id: this.options.upshot_id, note_id: this.options.id }),
			method: 'put',
			headers:{
				'X-Request' : 'JSON',
				'X-Requested-With' : 'XMLHttpRequest'
			},
			onSuccess: function(){}
		});
		timer = setTimeout(function() {
			change_request.send({user_id: _current_user.id, note_status: todo.getProperty('class')});
    }, 1000);
	}
	
});

if(!$defined(StudioMelipone)){ var StudioMelipone = new Hash(); }
if(!$defined(StudioMelipone.UpShot)){ StudioMelipone.UpShot = new Hash(); }

StudioMelipone.UpShot.Comment = new Class({
	Implements: [Options, Events],
	
	options: {
		id: 			$empty,
		created_at: 	$empty,
		user: 			$empty,
		content: 		"",
		state: 			"shown",
		type: 			$empty,
		after_validation:  false,
		validation:   	false,
		container: $empty,
		upshot_id: 		$empty,
		files: 			$empty,
		supattachments: $empty
	},
	// note dom element
	element: $empty,
	
	replys: new Array(),
	
	initialize: function(opt){
		this.setOptions(opt);
				
		this.save(opt);
	},
	
	save: function(opt){
		this.textarea = this.options.container.getElement('textarea#comment_comment');
		var content = this.textarea.get('value');
		this.files = []; 
		// this.options.global_container.getElement('ul#file-list-' + this.options.upshot_id).getElements('.file').each(function(li, index){
		// 	this.files.push(li.getElement('input[type=checkbox]').get('value'));
		// }.bind(this));
		// Should never be empty
		if(content == ""){
			alert(_("Please enter some text"));
		}else{
			// Request the note save
			this.save_request = $pick(
				this.save_request, 
				new Request.Auth({
					url: StudioMelipone.UpShot.Routes.get(StudioMelipone.UpShot.Routes.Comment.save, { user_id: _current_user.id, upshot_id: this.options.upshot_id}),
					method: 'put',
					headers:{
						'X-Request' : 'JSON',
						'X-Requested-With' : 'XMLHttpRequest'
					},
					onSuccess: this.saveSuccess.bindWithEvent(this),
					onFailure: this.failure.bindWithEvent(this)
				})
			);
			this.save_request.send({ "comment": {"comment" : content, "supattachments": this.options.supattachments}});
			_supattachments.removeAllBits();
		}
	},
	
	saveSuccess: function(text){
		// Decode the JSON
		var datas = JSON.decode(text);
		
		// Fill the object
		this.options.id 			= datas.id;
		this.options.number 		=	datas.number;
		this.options.user			= datas.user;
		this.options.content		= datas.content;
		this.options.state			= datas.state;
		this.options.after_validation = datas.after_validation;
		this.options.type = datas.type;
		this.options.files = datas.files;
		
		// Notify that the note should move from Melipone-Upshot.new_notes to Melipone-Upshot.notes
		this.fireEvent("save", [this]);
		
		//Delete the files in the life-list
    // $('ul#file-list-'+_upshots[this.options.upshot_id].id).empty();
		
	},
	
	failure: function(){
	}

	

});


if(!$defined(StudioMelipone)){ var StudioMelipone = new Hash(); }
if(!$defined(StudioMelipone.UpShot)){ StudioMelipone.UpShot = new Hash(); }

StudioMelipone.UpShot.Log = new Class({
	Implements: [Options, Events],
	
	options: {
		id: 				$empty,
		created_at: $empty,
		user: 			$empty,
		content: 		"",
		state: 			"shown",
		replys: 		new Hash(),
		type: $empty,
		thumbnail: 	$empty,
		after_validation: false,
		validation: false,
		files: $empty
	},
	// note dom element
	element: $empty,
	
	replys: new Array(),
	
	initialize: function(opt){
		this.setOptions(opt);
		
		this.element = this.createArea();
		this.element.content = this.createContent({ user: this.options.user, created_at: this.options.created_at }); this.element.adopt(this.element.content);
		this.element.clear = this.createClear('left'); this.element.adopt(this.element.clear);
		this.element.files = this.createFilesLink(); this.element.adopt(this.element.files);
	},

	
	createArea: function(){
		if(this.options.type == "note"){
			var area = new Element('li', {
				'id': "log_note_" + this.options.id,
				'class':"comment_li",
				'html': '<div class="first column unitx1 c"><a class="thumb" href="#"><img style="border-color:'+ (( this.options.after_validation || (this.options.validation != false && (this.options.created_at == 'now' || this.options.created_at == 'maintenant'))) ? '#DF8615' : (this.options.user.type == 'user' ? '#c66ecc' : '#5AB661')) +';" src="' + this.options.thumbnail  + '" alt="Thumb" /></a></div>'
			});
		}else if(this.options.type == "comment"){
			var area = new Element('li', {'class':"comment_li"});
		}
		return area;
	},
	
	createContent: function(){
		var content = new Element('div', {
			'class': 'content column unitx7'
		});
		
		content.header = this.createHeader(); content.adopt(content.header);
		content.comment = this.createComment(); content.adopt(content.comment);
		if(this.options.type == "note"){
			content.replys = this.createReplys(); content.adopt(content.replys);
		}
		
		return content;
	},
	
	createFilesLink: function(){
		if(this.options.type == "comment"){
			var content = new Element('ul', {'class':'log-files'});
			if($chk(this.options.files)){
				this.options.files.each(function(file){
					var list = new Element('li', {'id': file.id});
					var name = new Element('a', {'text': file.name, 'href': file.link, 'class': 'extra-file'});
					list.adopt(name);
					content.adopt(list);
				});
			}
		}
		return content;
	},
	
	createHeader: function(){
		var header = new Element('div',
		{
			'class': 'author',
			'html': '<h5><a style="color:'+ (( this.options.after_validation || (this.options.validation != false && (this.options.created_at == 'now' || this.options.created_at == 'maintenant'))) ? '#DF8615' : (this.options.user.type == 'user' ? '#c66ecc' : '#5AB661')) +';" href="#"><img src="' + this.options.user.avatar.smallest + '" alt="' + this.options.user.name + '" /></a><a style="color:'+ (( this.options.after_validation || (this.options.validation != false && (this.options.created_at == 'now' || this.options.created_at == 'maintenant'))) ? '#DF8615' : (this.options.user.type == 'user' ? '#c66ecc' : '#5AB661')) +';" href="#" class="ml4"> ' + this.options.user.name + '</a> <span class="yellow">&gt;&gt;</span><small class="date ml4"><span class="time date_to_convert" time="' + this.options.created_at + '">' + this.options.created_at + '</span></small></h5>'
		});
		
		return header;
	},
	
	createComment: function(){
		var comment = new Element('div',
		{
			'class': 'text mt9',
			'html': this.options.content
		});
		
		return comment;
	},
	
	createReplys: function(){
		var replys = new Element('div', {
			'class': 'answers',
			'html': '<ol></ol>',
			'styles': {
				'display': 'none'
			}
		});
			
		// Now take care of the possible answers
		var rs = $pick(this.options.replys, []);
		rs.each(function(r){
			replys.show();
			// Creates a comment with the answer's datas
			var reply = new StudioMelipone.UpShot.LogReply(this, { id: r.id, created_at: r.created_at, user: r.user, content: r.content, after_validation: r.after_validation }); 
			replys.getFirst().adopt(reply.comment);
			// Add it to the this.replys Array
			this.replys.push(reply);
		}.bind(this));
		
		return replys;
	},
	
	createClear: function(side){
		return new Element('div', {
			styles: {
				clear: side
			}
		});
	},
	
	addReply: function(r){
		var reply = new StudioMelipone.UpShot.LogReply(this, { id: r.id, created_at: r.created_at, user: r.user, content: r.content, after_validation: r.after_validation }); this.element.content.replys.show(); this.element.content.replys.adopt(reply.comment);
		
		// Add it to the this.comments Array
		this.replys.push(reply);
	}, 
	
	setThumbnail: function(thumbnail){
		this.options.thumbnail = thumbnail;
		this.element.getElement('img').set('src', thumbnail);
		this.element.highlight();
	}
	
});


if(!$defined(StudioMelipone)){ var StudioMelipone = new Hash(); }
if(!$defined(StudioMelipone.UpShot)){ StudioMelipone.UpShot = new Hash(); }

StudioMelipone.UpShot.LogReply = new Class({
	Implements: [Options, Events],
	
	options: {
		id: 				$empty,
		created_at: $empty,
		user: 			$empty,
		content: 		"",
		after_validation: false,
		parent_id:  0
	},
	// note dom element
	comment: $empty,
	
	initialize: function(parent, options){
		this.setOptions(options);
		
		this.parent_log = parent;
		
		this.comment = this.createArea();
		this.comment.header = this.createHeader(); this.comment.adopt(this.comment.header);
		this.comment.comment = this.createComment(); this.comment.adopt(this.comment.comment);
	},
	
	createArea: function(){
		var area = new Element('li');
		
		return area;
	},
	
	createHeader: function(){
		var header = new Element('div',
		{
			'class': 'author',
//			'html': '<a style="color:'+ (( this.options.after_validation || (this.options.validation != false && (this.options.created_at == 'now' || this.options.created_at == 'maintenant'))) ? '#DF8615' : (this.options.user.type == 'user' ? '#c66ecc' : '#5AB661')) +'" href="#"><img src="' + this.options.user.avatar.smallest + '" alt="' + this.options.user.name + '" /> ' + this.options.user.name + '</a> <span class="time date_to_convert" time="' + this.options.created_at + '">' + this.options.created_at + '</span>'
			'html': '<h5><a style="color:'+ (( this.options.after_validation || (this.options.validation != false && (this.options.created_at == 'now' || this.options.created_at == 'maintenant'))) ? '#DF8615' : (this.options.user.type == 'user' ? '#c66ecc' : '#5AB661')) +';" href="#"><img src="' + this.options.user.avatar.smallest + '" alt="' + this.options.user.name + '" /></a><a style="color:'+ (( this.options.after_validation || (this.options.validation != false && (this.options.created_at == 'now' || this.options.created_at == 'maintenant'))) ? '#DF8615' : (this.options.user.type == 'user' ? '#c66ecc' : '#5AB661')) +';" href="#" class="ml4"> ' + this.options.user.name + '</a> <span class="yellow">&gt;&gt;</span><small class="date ml4"><span class="time date_to_convert" time="' + this.options.created_at + '">' + this.options.created_at + '</span></small></h5>'
		});
		
		return header;
	},
	
	createComment: function(){
		var comment = new Element('div',
		{
			'class': 'text',
			'html': '<p>' + this.options.content + '</p>'
		});
		
		return comment;
	}
});


if(!$defined(StudioMelipone)){ var StudioMelipone = new Hash(); }
if(!$defined(StudioMelipone.UpShot)){ StudioMelipone.UpShot = new Hash(); }

StudioMelipone.UpShot.Shortcut = new Class({
	Implements: [Options, Events],
	
	options: {
		id: 				$empty,
		title: 			$empty,
		content: 		$empty,
		user: 			$empty,
		position: 	0,
		shortcutable_type: 			$empty,
		shortcutable_id: 				0,
		shortcutable_thumbnail: $empty,
		shortcutable_thumbnails: $empty,
		link_path: $empty
	},
	// note dom element
	element: $empty,
	
	initialize: function(opt){
		this.setOptions(opt);
		
		this.element = this.createArea();
		
    // this.element.getElement('.toolbox .zoom').addEvent('click', this.zoom.bindWithEvent(this, this.element));  /////////////////////////////  DISABLE ZOOM ///////////////////////////////
	},
	
	createArea: function(){
		var area = new Element('li');
		
		var the_html = "";
		if(this.options.shortcutable_type == "Search"){
      // var i = 0;
			the_html += '<a class="thumb fl" href="' + this.options.link_path + '">';
			
      // this.options.shortcutable_thumbnails.each(function(thumb){
        // while(i<4){
          
				the_html += '<img src="' + this.options.shortcutable_thumbnails[0].small + '" alt="Image" />';
          // i += 1;
          // if(i==2){
          //  the_html += '<br/>'
          // }
        // }
      // });
			the_html += '</a>';
		}
		else{
			the_html += '<a class="thumb fl" href="' + this.options.link_path + '"><img src="' + this.options.shortcutable_thumbnail + '" alt="Image" /></a>';
		}
		
		area.box = new Element('div',{
			'class' : 'box',
			'html': the_html
		}); area.adopt(area.box);
		
		area.box.content = new Element('div',{
			'class': 'text',
			'html': '<h5 class="blue">' + this.options.title + '</h5><p><small>' + this.options.content + '</small></p>'
		}); area.box.adopt(area.box.content);
		
		area.box.toolbox = new Element('div',{
			'class': 'toolbox '+ _locale,
			'html': '      <a class="move" href="#"><img src="/img/shortcut-icon-move.png" alt="desc" /></a><a class="delete" href="#"><img src="/img/shortcut-icon-delete.png" alt="desc" /></a>'
		}); area.box.adopt(area.box.toolbox);//<a class="zoom" href="#"><img src="/img/shortcut-icon-zoom.png" alt="desc" /></a>
		
		area.box.cb = new Element('div', {
		  'class': 'cb'
		}); area.box.adopt(area.box.cb);
		
		area.meta = new Element('div',{
			'class': "h meta",
			'html': '<span class="type">Shortcut</span><span class="id">' + this.options.id + '</span><span class="shortcutable_type">' + this.options.shortcutable_type + '</span><span class="shortcutable_id">' + this.options.shortcutable_id + '</span>'
		}); area.adopt(area.meta);
		
		return area;
	},
	
  // zoom: function(e, li){
  //  e.stop();
  //  
  //  var c = li.getCoordinates($('myupshots'));
  //  
  //  var type = li.getElement(".meta .shortcutable_type").get("text");
  //  var id = li.getElement(".meta .shortcutable_id").get("text");
  //  var midblock_class = ViewHelper.dom_id(type, id);
  //  
  //  var midblock = $$('div.lightbox.' + midblock_class)[0];
  //  
  //  if(midblock.hasClass("h")){
  //    midblock.removeClass('h');
  //    midblock.get('tween').start('opacity', 0, 1);
  //  }else{
  //    midblock.fade('toggle');
  //  }
  //  
  //  midblock.set('styles',{
  //    'top': c.top+c.height+30,
  //    'left': c.left-415
  //  });
  // }
});

/**
 * StudioMelipone.UpShot => namespace to manage interactivity on pictures
 * @param {string/Element} picture
 * @param {string/Element} container
 * @param {string/Element} decorator
 * @param {array} options
 *
 * Options:
 *  - {Element} tracer 
 */

if(!$defined(StudioMelipone)){ var StudioMelipone = new Hash(); }
if(!$defined(StudioMelipone.UpShot)){ StudioMelipone.UpShot = new Hash(); }

StudioMelipone.UpShot.Dashboard = new Class({
	Implements: [Options, Events],
	
	options: {
		user: $empty
	},
	
	initialize: function(shortcut_list, options){
		this.setOptions(options);
		this.shortcut_list = $(shortcut_list);
		
		this.shortcut_sortable = this.initSortable();
		
		this.initAddShortcutButtons();
	},
	
	initSortable: function(){
		var sortable = new Sortables(this.shortcut_list, {
	    revert: { duration: 300 },
	    handle: '.toolbox .move',
	    opacity: 0.5,
	    clone: true,
	    onComplete: this.orderSortable.bindWithEvent(this)
	  });
	
		// Init the other toolbox buttons
		this.shortcut_list.getElements("li").each(function(li){
			// Init the remove shortcut button
			this.initRemoveShortcutButton(li);
			
			// Init the midblock button
      // this.initZoomButton(li); /////////////////////////////////// Uncomment this line to enable zoom buttons on shortcuts ////////////////////////////
		}, this);
	
		return sortable;
	},
	
	initAddShortcutButtons: function(){
		$$('a.add_shortcut').each(function(a){
	    this.initAddShortcutButton(a);
	  }, this);
	},
	
	initAddShortcutButton: function(button){
	  var par = button.getParent('div.search');
	  var elem = par.getElement('span.type');
    var the_type = elem.get('text');
    if(the_type == "Search"){
  		var shortcut_search = new StudioMelipone.UpShot.Dashboard.Shortcut.Search(this);
  		button.addEvent('click', shortcut_search.addShorcut.bindWithEvent(shortcut_search, button));
    }
    else{
  		var shortcut_upshot = new StudioMelipone.UpShot.Dashboard.Shortcut.Upshot(this);
  		button.addEvent('click', shortcut_upshot.addShorcut.bindWithEvent(shortcut_upshot, button));
    }
	},
	
	initRemoveShortcutButton: function(li){
		var remove = li.getElement(".toolbox a.delete");
		if($chk(remove)){
			remove.addEvent("click", this.removeShortcut.bindWithEvent(this, [li, remove]));
		}
		
	},
	
  // initZoomButton: function(li){
  //  var zoom = li.getElement(".toolbox a.zoom");
  //  zoom.addEvent("click", this.zoom.bindWithEvent(this, li));
  // },
	
	orderSortable: function(el){
		this.shortcut_order_request = $pick(
			this.shortcut_order_request,
			new Request.Auth.JSON({
				url: StudioMelipone.UpShot.Routes.get(StudioMelipone.UpShot.Routes.Shortcuts.order, { user_id: this.options.user.id })
			})
		);
		
		this.shortcut_order_request.send({
  	  buttons_order: this.shortcut_sortable.serialize(function(el){ return el.getElement('.meta .id').get('text'); })
  	});
  },

	removeShortcut: function(e, li, button){
    e.stop();
    
    button.removeEvents('click');
    li.fade(0.5);

    var shortcut_id = li.getElement(".meta .id").get('text');

    li.remove_shortcut_request = $pick(
			li.remove_shortcut_request, 
			new Request.Auth.JSON({
				method: 'delete',
				url: StudioMelipone.UpShot.Routes.get(StudioMelipone.UpShot.Routes.Shortcuts['delete'], { 'user_id': this.options.user.id, 'shortcut_id': shortcut_id }),
				onSuccess: this.removeShortcutSuccess.bindWithEvent(this, [li, button])
			})
		);
		
		li.remove_shortcut_request.send({});
  },
	
	removeShortcutSuccess: function(text, li, button){
		// Decode the JSON
		var datas = JSON.decode(text);

		// Remove the list element button
		li.get('tween').start('opacity', 0).chain(function() { this.element.dispose(); });
		
		// Add and "add" link back in the element's li
		var type = li.getElement(".meta .shortcutable_type").get("text");
		var id = li.getElement(".meta .shortcutable_id").get("text");
		// var li_class = ViewHelper.dom_id(type, id);
		
		// $$('.' + li_class).each(function(new_li){	
			//var a = this.addShortcutButton(new_li);
			
			var a = $('save_search');
			if($chk(a)){
			  a.setProperty("style","opacity:1;");
			  a.show().fade('in');
			}
			//a.get('tween').start('opacity', 0, 1);
		// }, this);
		
    // var midblock = $$('div.lightbox.' + li_class).each(function(el){ el.dispose() });
		
		// Remove el from the sortable list
		this.shortcut_sortable.removeItems(li);
	}
	
  // zoom: function(e, li){
  //  e.stop();
  //  
  //  var c = li.getCoordinates($('myupshots'));
  //  
  //  var type = li.getElement(".meta .shortcutable_type").get("text");
  //  var id = li.getElement(".meta .shortcutable_id").get("text");
  //  var midblock_class = ViewHelper.dom_id(type, id);
  //  
  //  var midblock = $$('div.lightbox.' + midblock_class)[0];
  //  
  //  if(midblock.hasClass("h")){
  //    midblock.removeClass('h');
  //    midblock.get('tween').start('opacity', 0, 1);
  //  }else{
  //    midblock.fade('toggle');
  //  }
  //  
  //  midblock.set('styles',{
  //    'top': c.top+c.height+30,
  //    'left': c.left-415
  //  });
  // }
});


if(!$defined(StudioMelipone)){ var StudioMelipone = new Hash(); }
if(!$defined(StudioMelipone.UpShot)){ StudioMelipone.UpShot = new Hash(); }
if(!$defined(StudioMelipone.UpShot.Dashboard)){ StudioMelipone.UpShot.Dashboard = new Hash(); }
if(!$defined(StudioMelipone.UpShot.Dashboard.Shortcut)){ StudioMelipone.UpShot.Dashboard.Shortcut = new Hash(); }

StudioMelipone.UpShot.Dashboard.Shortcut.Search = new Class({
	Implements: [Options, Events],
	
	options: {

	},
	
	initialize: function(dashboard){
		this.dashboard = dashboard;
	},

	addShorcut: function(e, a){
    e.stop();
    
    var search_field = $('search_tags');
    //a.removeEvents('click');
    a.fade(0.5);

    a.add_shortcut_request = $pick(
			a.add_shortcut_request, 
			new Request.Auth.JSON({
				url: StudioMelipone.UpShot.Routes.get(StudioMelipone.UpShot.Routes.ShortcutSearch.save, { user_id: this.dashboard.options.user.id }),
				onSuccess: this.saveShortcutSuccess.bindWithEvent(this.dashboard, a)
			})
		);

		var li = a.getParent("div.search");//.getParent();
		var type = li.getElement(".meta .type").get("text");
		var search = li.getElement(".meta .search").get("text");

		a.add_shortcut_request.send({'search': search_field.value});
  },

  saveShortcutSuccess: function(text, add_button){

		// Decode the JSON
		var datas = JSON.decode(text);
		if(datas.shortcut.shortcutable_thumbnails.length==0){
			datas.shortcut.shortcutable_thumbnails = [{
				small: "/default/note_loader/note_small.png",
				tiny: "/default/note_loader/note_tiny.png"
			}];
			datas.shortcut.content = "archived upshots";
		}
		
		// Create the element and inject it to our list
		var shortcut = new StudioMelipone.UpShot.Shortcut(datas.shortcut);
		shortcut.element.inject(this.shortcut_list, 'bottom');
		shortcut.element.get('tween').start('opacity', 0, 1);

		// Hide the save buttons
		var li_class = ViewHelper.dom_id(datas.shortcut.shortcutable_type, datas.shortcut.shortcutable_id);
		// $$('div.rest').each(function(s){s.addClass(li_class); });
		add_button.getParent('div.search').addClass(li_class);
    // $$('div.search.'+ li_class + ' .toolbox').each(function(a){ a.fade('out');});
		
		$$('div.tags span.toolbox').removeProperty('style');
		var save_button = $('save_search');
		save_button.fade('out').hide();

    // var midblock = new Element('div',{'html': datas.midblock });
    // $('midblocks').adopt(midblock.getFirst());

		// Initialize the added element
		this.shortcut_sortable.addItems(shortcut.element);
		this.initRemoveShortcutButton(shortcut.element);
	}

});


if(!$defined(StudioMelipone)){ var StudioMelipone = new Hash(); }
if(!$defined(StudioMelipone.UpShot)){ StudioMelipone.UpShot = new Hash(); }
if(!$defined(StudioMelipone.UpShot.Dashboard)){ StudioMelipone.UpShot.Dashboard = new Hash(); }
if(!$defined(StudioMelipone.UpShot.Dashboard.Shortcut)){ StudioMelipone.UpShot.Dashboard.Shortcut = new Hash(); }

StudioMelipone.UpShot.Dashboard.Shortcut.Upshot = new Class({
	Implements: [Options, Events],
	
	options: {

	},
	
	initialize: function(dashboard){
		this.dashboard = dashboard;
	},

	addShorcut: function(e, a){
    e.stop();

    //a.removeEvents('click');
    a.fade(0.5);

    a.add_shortcut_request = $pick(
			a.add_shortcut_request, 
			new Request.Auth.JSON({
				url: StudioMelipone.UpShot.Routes.get(StudioMelipone.UpShot.Routes.ShortcutUpshot.save, { user_id: this.dashboard.options.user.id }),
				onSuccess: this.saveShortcutSuccess.bindWithEvent(this.dashboard, a)
			})
		);

		var li = a.getParent("div.search");//.getParent();
		var type = li.getElement(".meta .type").get("text");
		var id = li.getElement(".meta .search").get("text");

		a.add_shortcut_request.send({shortcut: { shortcutable_type: type, shortcutable_id: id}});
  },

  saveShortcutSuccess: function(text, add_button){
		// Decode the JSON
		var datas = JSON.decode(text);

		// Create the element and inject it to our list
		var shortcut = new StudioMelipone.UpShot.Shortcut(datas.shortcut);
		shortcut.element.inject(this.shortcut_list, 'bottom');
		shortcut.element.get('tween').start('opacity', 0, 1);

		// Hide the save buttons
		var li_class = ViewHelper.dom_id(datas.shortcut.shortcutable_type, datas.shortcut.shortcutable_id);
    // $$('li.' + li_class + ' .toolbox .add_shortcut').each(function(a){ a.fade('out');  });
    
    $$('div.tags span.toolbox').removeProperty('style');
    $('save_search').fade('out');

		var midblock = new Element('div',{'html': datas.midblock });
		$('midblocks').adopt(midblock.getFirst());

		// Initialize the added element
		this.shortcut_sortable.addItems(shortcut.element);
		this.initRemoveShortcutButton(shortcut.element);
	}

});

window.addEvent('domready', function() {

	// FAQ Accordion
	var acc = $('accordion');
	if($chk(acc)){
		var accordion = new Accordion($$('#accordion .toggler'),$$('#accordion .element'), {  
			// opacity: 0,
			show: -1,
			alwaysHide: true,
			onActive: function(toggler) {
				toggler.addClass('open');
			},
			onBackground: function(toggler) {
				toggler.removeClass('open');
			}
		});
	} // End FAQ Accordion
});
	
	var TextHelper = {
		//Truncate a string
		truncate: function(text, length){
			//The default value
			length = typeof(length) != 'undefined' ? length : 70;
			
			return text.substring(0, length);
		},
		
		//Change a number of byte in a more understandable format
		number_to_human_size: function(bytes) {
			var s = ['Bytes', 'Ko', 'Mo', 'Go', 'To', 'Po'];
			var e = Math.floor(Math.log(bytes)/Math.log(1024));
			return (bytes/Math.pow(1024, Math.floor(e))).toFixed(2)+" "+s[e];
		}
	};
	
	var HtmlHelper = {
		//Create an HTML table with a hash and a container to inject the rows. lineType is the markup for a line (td or th generally)
		generateTable: function(datas, container, lineType){
			//The default value
			lineType = typeof(lineType) != 'undefined' ? lineType : 'td';
			
			//The tr
			for(i in datas){
				tr = new Element('tr');	
				//The td
				for(j in datas[i]){
					//If the markup is 'EMPTY' then we skip this turn (usefull to have conditinal presence)
					if(datas[i][j].markup != "EMPTY"){
						//If a tr is specified, we don't have to create a new Element
						if(datas[i][j].markup != "tr"){
							//If the type is a td, we have no need to create an extra td
							if(datas[i][j].markup != lineType){
								td = new Element(lineType);
							}
							//The type (img, a ....)
							content = new Element(datas[i][j].markup);
						}else{
							content = tr;
						}

						for(k in datas[i][j]){
							if(k != 'markup'){
								content[k] = datas[i][j][k];
							}
						}

						if(datas[i][j].markup != lineType && datas[i][j].markup != "tr"){
							td.adopt(content);
							tr.adopt(td);
						} else if (datas[i][j].markup != "tr"){
							tr.adopt(content);
						}
					}
				}
				container.adopt(tr);
			}	
			
		}
	};
	
	// var Cycle = function(){
	//     var cycles, that, thru, reset;
	// 
	//     cycles = {};
	//     that = {};
	// 
	//     thru = function(){
	//         var values, i, cycle, options, name, nextValue;
	// 
	//         values = Array.prototype.slice.call(arguments);
	//         options = typeof(values.slice(-1)[0]) === 'object' ? values.pop() : {};
	// 
	//         name = options['name'] || 'default';
	// 
	//         if(!cycles[name]) {
	//             cycles[name] = {
	//               values: values,
	//               index: 0
	//             };
	//         };
	//         cycle = cycles[name];
	//         nextValue = cycle.values[cycle.index];
	//         cycle.index = (cycle.index === cycle.values.length -1) ? 0 : (cycle.index +1);
	//         return nextValue;
	//     };
	//     that.thru = thru;
	// 
	//     reset = function(name) {
	//         if(cycles[name]) {
	//             cycles[name].index = 0;
	//         }
	//     };
	//     that.reset = reset;
	// 
	//     return that;
	// 
	// };

	var DateHelper = {
		// Takes the format of "Jan 15, 2007 15:45:00 GMT" and converts it to a relative time
		// Ruby strftime: %b %d, %Y %H:%M:%S GMT
		time_ago_in_words_with_parsing: function(from) {
      var date = new Date(from * 1000); 
      // date.setTime(Date.parse(from));
			return this.time_ago_in_words(date);
		},

		time_ago_in_words: function(from) {
			return this.distance_of_time_in_words(new Date().getTime(), from.getTime());
		},

		distance_of_time_in_words: function(to, from) {
			var distance_in_seconds = ((to - from) / 1000);
			var distance_in_minutes = (distance_in_seconds / 60).floor();

			if (distance_in_minutes == 0) { return _('less than a minute ago'); }
			if (distance_in_minutes == 1) { return _('a minute ago'); }
			if (distance_in_minutes < 45) { return sprintf(_('%s minutes ago'), distance_in_minutes); }
			if (distance_in_minutes < 90) { return _('about 1 hour ago'); }
			if (distance_in_minutes < 1440) { return sprintf(_('about %s hours ago'), (distance_in_minutes / 60).floor()); }
			if (distance_in_minutes < 2880) { return _('1 day ago'); }
			if (distance_in_minutes < 43200) { return sprintf(_('%s days ago'), (distance_in_minutes / 1440).floor()); }
			if (distance_in_minutes < 86400) { return _('about 1 month ago'); }
			if (distance_in_minutes < 525960) { return sprintf(_('%s months ago'), (distance_in_minutes / 43200).floor()); }
			if (distance_in_minutes < 1051199) { return _('about 1 year ago'); }

			return sprintf('over %s years ago', (distance_in_minutes / 525960).floor());
		},

		convert_element_times_to_words: function(e){
			e.getElements('.date_to_convert').each(function(e) { 
				var time = e.get('time');
				if(time != "now" && time != "maintenant"){ e.set('html', DateHelper.time_ago_in_words_with_parsing(time)); }
			});
		},

		convert_all_times_to_words: function(){
			$$('.date_to_convert').each(function(e) { 
				var time = e.get('time');
				if(time != "now" && time != "maintenant"){ e.set('html', DateHelper.time_ago_in_words_with_parsing(time)); }
			});
		}
	};

	Request.Auth = new Class({
		Extends: Request,

		send: function(data){
			data.authenticity_token = window._token;
			this.parent(Hash.toQueryString(data));
		}
	});

	Request.Auth.JSON = new Class({
		Extends: Request.Auth,

		initialize: function(options){
			this.parent(options);
			Object.append(this.headers, {'Accept': 'application/json', 'X-Request': 'JSON', 'Content-type': 'application/json',	'X-Requested-With' : 'XMLHttpRequest'});
		}
	});

	var ViewHelper = {
		dom_id: function(type, id){
			return type.toLowerCase() + "_" + id;
		},
		
		dom_id_data: function(id){
			var rough_data = id.split("_");	var data = new Hash();
			for(i = 0; i < rough_data.length; i++){ if(i%2 == 0) data[rough_data[i]] = rough_data[i+1]; }
			return data;
		}
	};

	window.addEvent('domready', function() {
		
		window.addCustomer = function(newLine, email, first_name, last_name, comment){
			if(!$chk(newLine)){
				var newLine = formLine.clone();
				newLine.getElements("input").each(function(input){
					if(input.hasClass("email"))
					input.value = email;

					if(input.hasClass("first_name"))
					input.value = first_name;

					if(input.hasClass("last_name"))
					input.value = last_name;
				});
				newLine.getElement("textarea").value = comment;
			}

			newLine.id = "";
			newLine.addClass("bgLightGrey");
			newLine.addClass("bot5");

			newLine.fade('out');

			var deleter = new Element('div',{
				'events': {
					'click': function(e){
						e = new Event(e);
						e.stop();

						this.get('tween').start('opacity', 1, 0).chain(
							function(){
								this.element.dispose();
							}
						);
					}.bind(newLine)
				},
				'class': 'bgWhite negative abs deleter',
				'href': ''
			});
			deleter.set('html','<p class="empty"><span class="element"><input type="image" src="' + _('/img/en/btn-remove-customer_en.png') + '" class="addCustomer" /></span></p>');

			deleter.injectBottom(newLine);
			newLine.injectBefore(formLine);
			newLine.fade('in');

			formLine.getElements("input").each(function(input){
				input.value = "";
			});
			formLine.getElement("textarea").value = "";

			return newLine;
		};

		// used to be addFile but files were replaced by FancyUpload
		window.addFileLink = function(newLine){
			var id_like = $time();

			var file = newLine.getElement(".file_external_path");
			file.set('name', 'upshot[supattachments_attributes][' + id_like + '][external_path]');

			newLine.id = "";
			newLine.addClass("bgLightGrey");
			newLine.addClass("bot5");

			newLine.fade('out');

			var deleter = new Element('div',{
				'events': {
					'click': function(e){
						e = new Event(e);
						e.stop();

						this.get('tween').start('opacity', 1, 0).chain(
							function(){
								this.element.dispose();
							}
						);
					}.bind(newLine)
				},
				'class': 'bgWhite negative abs deleter',
				'href': ''
			});
			deleter.set('html','<p class="empty"><span class="element"><input type="image" src="' + _('/img/en/btn-remove-file_en.png') + '" class="removeCustomer" /></span></p>');

			deleter.injectBottom(newLine);
			newLine.injectBefore(formFileLine);
			newLine.fade('in');
		};

		window.addAgencyUser = function(newLine){

			// var id_like = $time();

			// var email = newLine.getElement(".user_email");
			// email.set('name', 'agency[users_attributes][][email]');
			// 
			// var first_name = newLine.getElement(".user_first_name");
			// first_name.set('name', 'agency[users_attributes][][first_name]');
			// 
			// var last_name = newLine.getElement(".user_last_name");
			// last_name.set('name', 'agency[users_attributes][][last_name]');
			// 
			// var admin = newLine.getElement(".user_admin");
			// admin.set('name', 'agency[users_attributes][][admin]');

			newLine.id = "";
			newLine.addClass("bgLightGrey");
			newLine.addClass("bot5");

			newLine.fade('out');

			var deleter = new Element('a',{
				'events': {
					'click': function(e){
						e = new Event(e);
						e.stop();

						this.get('tween').start('opacity', 1, 0).chain(
							function(){
								this.element.dispose();
							}
						);
					}.bind(newLine)
				},
				'class': 'bgWhite negative abs deleter',
				'href': ''
			});
			deleter.set('html','<p class="empty"><span class="element"><input type="image" src="' + _('/img/en/btn-remove-collaborator_en.png') + '" class="removeCollaborator" /></span></p>');

			deleter.injectBottom(newLine);
			newLine.injectBefore(formAddAgencyUser);
			newLine.fade('in');
		};

		// $$('.customer-deleteable').each(function(c){
			// 	var deleter = new Element('a',{
				//     'events': {
					//       'click': function(e){
						//         e = new Event(e);
						//         e.stop();
						// 
						//         this.get('tween').start('opacity', 1, 0).chain(
							//           function(){
								//             this.element.dispose();
								//           }
								//         );
								//       }.bind(c)
								//     },
								//     'class': 'bgWhite negative abs deleter',
								//     'href': ''
								//   });
								//   deleter.set('html','<p class="empty"><span class="element"><input type="image" src="' + _('/img/en/btn-remove-collaborator_en.png') + '" class="removeCollaborator" /></span></p>');
								// 
								// 	c.adopt(deleter);
								// });

		var formLine = $('form-customer-fields');
		

		if($chk(formLine)){
			var btnadd = formLine.getParent().getElement('.addCustomer');
			btnadd.addEvent('click',  function(ev) {
				ev=new Event(ev);
				ev.stop();

				var newLine = formLine.clone();
				newLine.getElement("textarea").value = formLine.getElement("textarea").value;

				addCustomer(newLine, null, null, null, null);

		formCouponCodeLink.addEvent('click', function(ev) {
			ev = new Event(ev);
			myEffect.toggle();
			ev.stop();
			
		});
	});
}
	
	var informationBoxCloseButton = $$('.to_nix');
	if($chk(informationBoxCloseButton)){
		informationBoxCloseButton.each(function(button){
			informationBoxCloseButton.getElements('.nix_handle').each(function(e){
				e.addEvent('click', function(ev){
					ev = new Event(ev);
					//informationBoxCloseButton.nix({duration: 1000});

					var nox = button.hasClass('nox');
					var chkNox = nox;
					var notChkNox = !chkNox;
					var mtype = $type(nox);

					if(notChkNox){
						var request = new Request.Auth.JSON({
							url: StudioMelipone.UpShot.Routes.get(StudioMelipone.UpShot.Routes.Users.update_gui_data, { user_id: _user.id}),
							onSuccess: function(){
								informationBoxCloseButton.nix({duration: 1000});
							}
						});
						
						var metatype = informationBoxCloseButton.getElement('.meta .type');
						request.send({'gui_action': metatype[0].get('text') });
						
					}else{
						informationBoxCloseButton.nix({duration: 1000});
					}
				});
			});
		});
	}	
		
	var formFileLine = $('form-file-fields');
	if($chk(formFileLine)){
		var btnadd = formFileLine.getParent().getElement('.addFileLink');
		btnadd.addEvent('click',  function(ev) {
			ev=new Event(ev);
			ev.stop();

			var newLine = formFileLine.clone();

			addFileLink(newLine);

			formFileLine.getElements("input").each(function(input){
				input.value = "";
			});
		});
	}

	var formCouponCodeLink = $('form-coupon-code-link');
	if ($chk(formCouponCodeLink)){

		var formCouponCode = $('form-coupon-code');
		formCouponCode.removeClass('h');

		var myEffect = new Fx.Slide(formCouponCode);
		myEffect.hide();

		formCouponCodeLink.addEvent('click', function(ev) {
			ev = new Event(ev);
			myEffect.toggle();
			ev.stop();

		});
	}

	var formAddAgencyUser = $('form-agency-user-fields');
	if($chk(formAddAgencyUser)){
		var btnadd = formAddAgencyUser.getParent().getElement('.addAgencyUser');
		btnadd.addEvent('click',  function(ev) {
			ev=new Event(ev);
			ev.stop();

			var newLine = formAddAgencyUser.clone();

			addAgencyUser(newLine);

			formAddAgencyUser.getElements("input").each(function(input){
				if(input.get('type') == "checkbox"){
					input.value = "true";
				}
				else{
					input.value = "";
				}
				input.checked = "";
			});
		});
	}
});

window.addEvent('domready', function() {
	var date = new Date();
	var offset = $("offset");
	if ($chk(offset)){
		offset.value = date.getTimezoneOffset();
	}
});

// window.addEvent('domready', function(){
// 	// Do this only if our brwoser doesn't support placeholders
// 	var i = document.createElement('input'); 
// 	if(!('placeholder' in i)){
// 		$$('form').each(function(f){
// 			var phs = f.getElements('input[placeholder]');
// 			if(phs.length > 0){
// 				phs.each(function(el){
// 					new PlaceholderInput(el);
// 				});
// 				f.addEvent('submit', function() {
// 					this.getElements('input[placeholder]').each(function(input) {
// 						if (input.get('value', true) == input.get('placeholder')) {
// 							input.set('value', '', true);
// 						}
// 					})
// 				});
// 			}
// 		});
// 	}
// });

window.addEvent('domready', function() {
	$$('.to_dropdown').each(function(e){
		var accounts = e.getElements('li');
		accounts.each(function(a){
			if(!a.hasClass('selected')) a.hide();
		});
		
		e.addEvent('mouseover', function(e) {
			this.addClass('dropdowned');
			accounts.each(function(a){
				if(!a.hasClass('selected')) a.show();
			});
		});
		e.addEvent('mouseout', function(e) {
			this.removeClass('dropdowned');
			accounts.each(function(a){
				if(!a.hasClass('selected')) a.hide();
			});
		});
		e.removeClass('horizontal');
	})
});


(function(){var a=function(b,c){typeof b!=="string"?a.original?a.original.apply(window,arguments):(console.error("dropping module because define wasn't a string."),console.trace()):(define.modules||(define.modules={}),define.modules[b]=c)};window.define&&(a.original=window.define),window.define=a;var b=function(a,d){if(Object.prototype.toString.call(a)==="[object Array]"){var e=[];for(var f=0,g=a.length;f<g;++f){var h=c(a[f]);if(!h&&b.original)return b.original.apply(window,arguments);e.push(h)}d&&d.apply(null,e)}if(typeof a==="string"){var i=c(a);if(!i&&b.original)return b.original.apply(window,arguments);d&&d();return i}};window.require&&(b.original=window.require),window.require=b,require.packaged=!0;var c=function(a){var b=define.modules[a];if(b==null){console.error("Missing module: "+a);return null}if(typeof b==="function"){var c={};b(require,c,{id:a,uri:""}),define.modules[a]=c;return c}return b}})(),define("pilot/fixoldbrowsers",function(a,b,c){Function.prototype.bind||(Function.prototype.bind=function(a){var b=[].slice,c=b.call(arguments,1),d=this,e=function(){};if(arguments.length==1)var f=function(){return d.apply(this instanceof e?this:a,arguments)};else var f=function(){return d.apply(this instanceof e?this:a||{},c.concat(b.call(arguments)))};e.prototype=d.prototype,f.prototype=new e,f.name=this.name,f.displayName=this.displayName,f.length=this.length,f.unbound=d;return f});var d=function(){},e=Function.prototype.call,f=e.bind(Object.prototype.hasOwnProperty),g,h,i,j;g=h=i=j=d,Object.prototype.__lookupGetter__&&(g=e.bind(Object.prototype.__lookupGetter__)),Object.prototype.__lookupSetter__&&(h=e.bind(Object.prototype.__lookupSetter__)),Object.prototype.__defineGetter__&&(i=e.bind(Object.prototype.__defineGetter__)),Object.prototype.__defineSetter__&&(j=e.bind(Object.prototype.__defineSetter__)),Array.isArray||(Array.isArray=function(a){return a&&Object.prototype.toString.call(a)==="[object Array]"}),Array.prototype.indexOf||(Array.prototype.indexOf=function(a){if(this===void 0||this===null)throw new TypeError;var b=Object(this),c=b.length>>>0;if(c===0)return-1;var d=0,e=d;arguments.length>0&&(d=Number(arguments[1]),d!==d?d=0:d!==0&&d!==1/e&&d!==-(1/e)&&(d=(d>0||-1)*Math.floor(Math.abs(d))));if(d>=c)return-1;var f=d>=0?d:Math.max(c-Math.abs(d),0);for(;f<c;f++)if(f in b&&b[f]===a)return f;return-1}),Array.prototype.lastIndexOf||(Array.prototype.lastIndexOf=function(a){"use strict";if(this===void 0||this===null)throw new TypeError;var b=Object(this),c=b.length>>>0;if(c===0)return-1;var d=c,e=!1|0;arguments.length>0&&(d=Number(arguments[1]),d!==d?d=0:d!==0&&d!==1/e&&d!==-(1/e)&&(d=(d>0||-1)*Math.floor(Math.abs(d))));var f=d>=0?Math.min(d,c-1):c-Math.abs(d);while(f>=0)if(f in b&&b[f]===a)return f;return-1}),Array.prototype.map||(Array.prototype.map=function(a){if(this===void 0||this===null)throw new TypeError;var b=Object(this),c=b.length>>>0;if(typeof a!=="function")throw new TypeError;res=Array(c);var d=arguments[1];for(var e=0;e<c;e++)e in b&&(res[e]=a.call(d,b[e],e,b));return res}),Array.prototype.forEach||(Array.prototype.forEach=function(a){if(this===void 0||this===null)throw new TypeError;var b=Object(this),c=b.length>>>0;if(typeof a!=="function")throw new TypeError;var d=arguments[1];for(var e=0;e<c;e++)e in b&&a.call(d,b[e],e,b)}),Array.prototype.filter||(Array.prototype.filter=function k(a,b){var c=[],d,e;for(d=0,e=this.length;d<e;d++)a.call(b,this[d])&&c.push(this[d]);return c}),Array.prototype.every||(Array.prototype.every=function l(a,b){var c,d;for(c=0,d=this.length;c<d;c++)if(!a.call(b,this[c]))return!1;return!0}),Array.prototype.some||(Array.prototype.some=function(a,b){var c,d;for(c=0,d=this.length;c<d;c++)if(a.call(b,this[c]))return!0;return!1}),Array.prototype.reduce||(Array.prototype.reduce=function(a){var b=this.length>>>0;if(typeof a!="function")throw new TypeError;if(b==0&&arguments.length==1)throw new TypeError;var c=0;if(arguments.length<2){do{if(c in this){d=this[c++];break}if(++c>=b)throw new TypeError}while(!0)}else var d=arguments[1];for(;c<b;c++)c in this&&(d=a.call(null,d,this[c],c,this));return d}),Array.prototype.reduceRight||(Array.prototype.reduceRight=function(a){var b=this.length>>>0;if(typeof a!="function")throw new TypeError;if(b==0&&arguments.length==1)throw new TypeError;var c=b-1;if(arguments.length<2){do{if(c in this){d=this[c--];break}if(--c<0)throw new TypeError}while(!0)}else var d=arguments[1];for(;c>=0;c--)c in this&&(d=a.call(null,d,this[c],c,this));return d}),Object.keys||(Object.keys=function m(a){var b,c=[];for(b in a)f(a,b)&&c.push(b);return c}),Object.getOwnPropertyNames||(Object.getOwnPropertyNames=Object.keys);var n="Object.getOwnPropertyDescriptor called on a non-object";Object.getOwnPropertyDescriptor||(Object.getOwnPropertyDescriptor=function o(a,b){var c,d,e;if(typeof a!=="object"&&typeof a!=="function"||a===null)throw new TypeError(n);f(a,b)&&(c={configurable:!0,enumerable:!0},d=c.get=g(a,b),e=c.set=h(a,b),!d&&!e&&(c.writeable=!0,c.value=a[b]));return c}),Object.getPrototypeOf||(Object.getPrototypeOf=function p(a){return a.__proto__||a.constructor.prototype}),Object.create||(Object.create=function q(a,b){var c;if(a===null)c={"__proto__":null};else{if(typeof a!=="object")throw new TypeError(a+" is not an object or null");d.prototype=a,c=new d}typeof b!=="undefined"&&Object.defineProperties(c,b);return c}),Object.defineProperty||(Object.defineProperty=function r(a,b,c){var d,e,f;if("object"!==typeof a&&"function"!==typeof a)throw new TypeError(a+"is not an object");if(c&&"object"!==typeof c)throw new TypeError("Property descriptor map must be an object");if("value"in c){if("get"in c||"set"in c)throw new TypeError('Invalid property. "value" present on property with getter or setter.');if(d=a.__proto__)a.__proto__=Object.prototype;delete a[b],a[b]=c.value,d&&(a.__proto__=d)}else(f=c.get)&&i(a,f),(e=c.set)&&j(a,e);return a}),Object.defineProperties||(Object.defineProperties=function s(a,b){Object.getOwnPropertyNames(b).forEach(function(c){Object.defineProperty(a,c,b[c])});return a});var t=function(a){return a};Object.seal||(Object.seal=t),Object.freeze||(Object.freeze=t),Object.preventExtensions||(Object.preventExtension=t);var u=function(){return!1},v=function(){return!0};Object.isSealed||(Object.isSealed=u),Object.isFrozen||(Object.isFrozen=u),Object.isExtensible||(Object.isExtensible=v),String.prototype.trim||(String.prototype.trim=function(){return this.trimLeft().trimRight()}),String.prototype.trimRight||(String.prototype.trimRight=function(){return this.replace(/[\t\v\f\s\u00a0\ufeff]+$/,"")}),String.prototype.trimLeft||(String.prototype.trimLeft=function(){return this.replace(/^[\t\v\f\s\u00a0\ufeff]+/,"")}),b.globalsLoaded=!0}),define("pilot/index",function(a,b,c){b.startup=function(b,c){a("pilot/fixoldbrowsers"),a("pilot/types/basic").startup(b,c),a("pilot/types/command").startup(b,c),a("pilot/types/settings").startup(b,c),a("pilot/commands/settings").startup(b,c),a("pilot/commands/basic").startup(b,c),a("pilot/settings/canon").startup(b,c),a("pilot/canon").startup(b,c)},b.shutdown=function(b,c){a("pilot/types/basic").shutdown(b,c),a("pilot/types/command").shutdown(b,c),a("pilot/types/settings").shutdown(b,c),a("pilot/commands/settings").shutdown(b,c),a("pilot/commands/basic").shutdown(b,c),a("pilot/settings/canon").shutdown(b,c),a("pilot/canon").shutdown(b,c)}}),define("pilot/types/basic",function(a,b,c){function m(a){if(a instanceof e)this.subtype=a;else{if(typeof a!=="string")throw new Error("Can' handle array subtype");this.subtype=d.getType(a);if(this.subtype==null)throw new Error("Unknown array subtype: "+a)}}function l(a){if(typeof a.defer!=="function")throw new Error("Instances of DeferredType need typeSpec.defer to be a function that returns a type");Object.keys(a).forEach(function(b){this[b]=a[b]},this)}function j(a){if(!Array.isArray(a.data)&&typeof a.data!=="function")throw new Error("instances of SelectionType need typeSpec.data to be an array or function that returns an array:"+JSON.stringify(a));Object.keys(a).forEach(function(b){this[b]=a[b]},this)}var d=a("pilot/types"),e=d.Type,f=d.Conversion,g=d.Status,h=new e;h.stringify=function(a){return a},h.parse=function(a){if(typeof a!="string")throw new Error("non-string passed to text.parse()");return new f(a)},h.name="text";var i=new e;i.stringify=function(a){if(!a)return null;return""+a},i.parse=function(a){if(typeof a!="string")throw new Error("non-string passed to number.parse()");if(a.replace(/\s/g,"").length===0)return new f(null,g.INCOMPLETE,"");var b=new f(parseInt(a,10));isNaN(b.value)&&(b.status=g.INVALID,b.message="Can't convert \""+a+'" to a number.');return b},i.decrement=function(a){return a-1},i.increment=function(a){return a+1},i.name="number",j.prototype=new e,j.prototype.stringify=function(a){return a},j.prototype.parse=function(a){if(typeof a!="string")throw new Error("non-string passed to parse()");if(!this.data)throw new Error("Missing data on selection type extension.");var b=typeof this.data==="function"?this.data():this.data,c=!1,d,e=[];b.forEach(function(b){a==b?(d=this.fromString(b),c=!0):b.indexOf(a)===0&&e.push(this.fromString(b))},this);if(c)return new f(d);this.noMatch&&this.noMatch();if(e.length>0){var h="Possibilities"+(a.length===0?"":" for '"+a+"'");return new f(null,g.INCOMPLETE,h,e)}var h="Can't use '"+a+"'.";return new f(null,g.INVALID,h,e)},j.prototype.fromString=function(a){return a},j.prototype.decrement=function(a){var b=typeof this.data==="function"?this.data():this.data,c;if(a==null)c=b.length-1;else{var d=this.stringify(a),c=b.indexOf(d);c=c===0?b.length-1:c-1}return this.fromString(b[c])},j.prototype.increment=function(a){var b=typeof this.data==="function"?this.data():this.data,c;if(a==null)c=0;else{var d=this.stringify(a),c=b.indexOf(d);c=c===b.length-1?0:c+1}return this.fromString(b[c])},j.prototype.name="selection",b.SelectionType=j;var k=new j({name:"bool",data:["true","false"],stringify:function(a){return""+a},fromString:function(a){return a==="true"?!0:!1}});l.prototype=new e,l.prototype.stringify=function(a){return this.defer().stringify(a)},l.prototype.parse=function(a){return this.defer().parse(a)},l.prototype.decrement=function(a){var b=this.defer();return b.decrement?b.decrement(a):undefined},l.prototype.increment=function(a){var b=this.defer();return b.increment?b.increment(a):undefined},l.prototype.name="deferred",b.DeferredType=l,m.prototype=new e,m.prototype.stringify=function(a){return a.join(" ")},m.prototype.parse=function(a){return this.defer().parse(a)},m.prototype.name="array",b.startup=function(){d.registerType(h),d.registerType(i),d.registerType(k),d.registerType(j),d.registerType(l),d.registerType(m)},b.shutdown=function(){d.unregisterType(h),d.unregisterType(i),d.unregisterType(k),d.unregisterType(j),d.unregisterType(l),d.unregisterType(m)}}),define("pilot/types",function(a,b,c){function i(a,b){if(a.substr(-2)==="[]"){var c=a.slice(0,-2);return new g.array(c)}var d=g[a];typeof d==="function"&&(d=new d(b));return d}function f(){}function e(a,b,c,e){this.value=a,this.status=b||d.VALID,this.message=c,this.predictions=e||[]}var d={VALID:{toString:function(){return"VALID"},valueOf:function(){return 0}},INCOMPLETE:{toString:function(){return"INCOMPLETE"},valueOf:function(){return 1}},INVALID:{toString:function(){return"INVALID"},valueOf:function(){return 2}},combine:function(a){var b=d.VALID;for(var c=0;c<arguments;c++)arguments[c]>b&&(b=arguments[c]);return b}};b.Status=d,b.Conversion=e,f.prototype={stringify:function(a){throw new Error("not implemented")},parse:function(a){throw new Error("not implemented")},name:undefined,increment:function(a){return undefined},decrement:function(a){return undefined},getDefault:function(){return this.parse("")}},b.Type=f;var g={};b.registerType=function(a){if(typeof a==="object"){if(!(a instanceof f))throw new Error("Can't registerType using: "+a);if(!a.name)throw new Error("All registered types must have a name");g[a.name]=a}else{if(typeof a!=="function")throw new Error("Unknown type: "+a);if(!a.prototype.name)throw new Error("All registered types must have a name");g[a.prototype.name]=a}},b.registerTypes=function h(a){Object.keys(a).forEach(function(c){var d=a[c];d.name=c,b.registerType(d)})},b.deregisterType=function(a){delete g[a.name]},b.getType=function(a){if(typeof a==="string")return i(a);if(typeof a==="object"){if(!a.name)throw new Error("Missing 'name' member to typeSpec");return i(a.name,a)}throw new Error("Can't extract type from "+a)}}),define("pilot/types/command",function(a,b,c){var d=a("pilot/canon"),e=a("pilot/types/basic").SelectionType,f=a("pilot/types"),g=new e({name:"command",data:function(){return d.getCommandNames()},stringify:function(a){return a.name},fromString:function(a){return d.getCommand(a)}});b.startup=function(){f.registerType(g)},b.shutdown=function(){f.unregisterType(g)}}),define("pilot/canon",function(a,b,c){function x(a){a=a||{},this.command=a.command,this.args=a.args,this.typed=a.typed,this._begunOutput=!1,this.start=new Date,this.end=null,this.completed=!1,this.error=!1}function u(a,b,c,d){typeof a==="string"&&(a=n[a]);if(!a)return!1;var e=new x({command:a,args:c,typed:d});a.exec(b,c||{},e);return!0}function t(){return o}function s(a){return n[a]}function r(a){var b=typeof a==="string"?a:a.name;delete n[b],k.arrayRemove(o,b)}function q(a,b){var c=b.type;b.type=j.getType(c);if(b.type==null)throw new Error("In "+a+"/"+b.name+": can't find type for: "+JSON.stringify(c))}function p(a){if(!a.name)throw new Error("All registered commands must have a name");a.params==null&&(a.params=[]);if(!Array.isArray(a.params))throw new Error("command.params must be an array in "+a.name);a.params.forEach(function(b){if(!b.name)throw new Error("In "+a.name+": all params must have a name");q(a.name,b)},this),n[a.name]=a,o.push(a.name),o.sort()}var d=a("pilot/console"),e=a("pilot/stacktrace").Trace,f=a("pilot/oop"),g=a("pilot/event_emitter").EventEmitter,h=a("pilot/catalog"),i=a("pilot/types").Status,j=a("pilot/types"),k=a("pilot/lang"),l={name:"command",description:"A command is a bit of functionality with optional typed arguments which can do something small like moving the cursor around the screen, or large like cloning a project from VCS.",indexOn:"name"};b.startup=function(a,b){h.addExtensionSpec(l)},b.shutdown=function(a,b){h.removeExtensionSpec(l)};var m={name:"thing",description:"thing is an example command",params:[{name:"param1",description:"an example parameter",type:"text",defaultValue:null}],exec:function(a,b,c){thing()}},n={},o=[];b.removeCommand=r,b.addCommand=p,b.getCommand=s,b.getCommandNames=t,b.exec=u,b.upgradeType=q,f.implement(b,g);var v=[],w=100;f.implement(x.prototype,g),x.prototype._beginOutput=function(){this._begunOutput=!0,this.outputs=[],v.push(this);while(v.length>w)v.shiftObject();b._dispatchEvent("output",{requests:v,request:this})},x.prototype.doneWithError=function(a){this.error=!0,this.done(a)},x.prototype.async=function(){this._begunOutput||this._beginOutput()},x.prototype.output=function(a){this._begunOutput||this._beginOutput(),typeof a!=="string"&&!(a instanceof Node)&&(a=a.toString()),this.outputs.push(a),this._dispatchEvent("output",{});return this},x.prototype.done=function(a){this.completed=!0,this.end=new Date,this.duration=this.end.getTime()-this.start.getTime(),a&&this.output(a),this._dispatchEvent("output",{})},b.Request=x}),define("pilot/console",function(a,b,c){var d=function(){},e=["assert","count","debug","dir","dirxml","error","group","groupEnd","info","log","profile","profileEnd","time","timeEnd","trace","warn"];typeof window==="undefined"?e.forEach(function(a){b[a]=function(){var b=Array.prototype.slice.call(arguments),c={op:"log",method:a,args:b};postMessage(JSON.stringify(c))}}):e.forEach(function(a){window.console&&window.console[a]?b[a]=Function.prototype.bind.call(window.console[a],window.console):b[a]=d})}),define("pilot/stacktrace",function(a,b,c){function i(){}function g(a){for(var b=0;b<a.length;++b){var c=a[b];typeof c=="object"?a[b]="#object":typeof c=="function"?a[b]="#function":typeof c=="string"&&(a[b]='"'+c+'"')}return a.join(",")}var d=a("pilot/useragent"),e=a("pilot/console"),f=function(){return d.isGecko?"firefox":d.isOpera?"opera":"other"}(),h={chrome:function(a){var b=a.stack;if(!b){e.log(a);return[]}return b.replace(/^.*?\n/,"").replace(/^.*?\n/,"").replace(/^.*?\n/,"").replace(/^[^\(]+?[\n$]/gm,"").replace(/^\s+at\s+/gm,"").replace(/^Object.<anonymous>\s*\(/gm,"{anonymous}()@").split("\n")},firefox:function(a){var b=a.stack;if(!b){e.log(a);return[]}b=b.replace(/(?:\n@:0)?\s+$/m,""),b=b.replace(/^\(/gm,"{anonymous}(");return b.split("\n")},opera:function(a){var b=a.message.split("\n"),c="{anonymous}",d=/Line\s+(\d+).*?script\s+(http\S+)(?:.*?in\s+function\s+(\S+))?/i,e,f,g;for(e=4,f=0,g=b.length;e<g;e+=2)d.test(b[e])&&(b[f++]=(RegExp.$3?RegExp.$3+"()@"+RegExp.$2+RegExp.$1:c+"()@"+RegExp.$2+":"+RegExp.$1)+" -- "+b[e+1].replace(/^\s+/,""));b.splice(f,b.length-f);return b},other:function(a){var b="{anonymous}",c=/function\s*([\w\-$]+)?\s*\(/i,d=[],e=0,f,h,i=10;while(a&&d.length<i){f=c.test(a.toString())?RegExp.$1||b:b,h=Array.prototype.slice.call(a.arguments),d[e++]=f+"("+g(h)+")";if(a===a.caller&&window.opera)break;a=a.caller}return d}};i.prototype={sourceCache:{},ajax:function(a){var b=this.createXMLHTTPObject();if(b){b.open("GET",a,!1),b.setRequestHeader("User-Agent","XMLHTTP/1.0"),b.send("");return b.responseText}},createXMLHTTPObject:function(){var a,b=[function(){return new XMLHttpRequest},function(){return new ActiveXObject("Msxml2.XMLHTTP")},function(){return new ActiveXObject("Msxml3.XMLHTTP")},function(){return new ActiveXObject("Microsoft.XMLHTTP")}];for(var c=0;c<b.length;c++)try{a=b[c](),this.createXMLHTTPObject=b[c];return a}catch(d){}},getSource:function(a){a in this.sourceCache||(this.sourceCache[a]=this.ajax(a).split("\n"));return this.sourceCache[a]},guessFunctions:function(a){for(var b=0;b<a.length;++b){var c=/{anonymous}\(.*\)@(\w+:\/\/([-\w\.]+)+(:\d+)?[^:]+):(\d+):?(\d+)?/,d=a[b],e=c.exec(d);if(e){var f=e[1],g=e[4];if(f&&g){var h=this.guessFunctionName(f,g);a[b]=d.replace("{anonymous}",h)}}}return a},guessFunctionName:function(a,b){try{return this.guessFunctionNameFromLines(b,this.getSource(a))}catch(c){return"getSource failed with url: "+a+", exception: "+c.toString()}},guessFunctionNameFromLines:function(a,b){var c=/function ([^(]*)\(([^)]*)\)/,d=/['"]?([0-9A-Za-z_]+)['"]?\s*[:=]\s*(function|eval|new Function)/,e="",f=10;for(var g=0;g<f;++g){e=b[a-g]+e;if(e!==undefined){var h=d.exec(e);if(h)return h[1];h=c.exec(e);if(h&&h[1])return h[1]}}return"(?)"}};var j=new i,k=[/http:\/\/localhost:4020\/sproutcore.js:/];b.ignoreFramesMatching=function(a){k.push(a)},b.Trace=function l(a,b){this._ex=a,this._stack=h[f](a),b&&(this._stack=j.guessFunctions(this._stack))},b.Trace.prototype.log=function(a){a<=0&&(a=999999999);var b=0;for(var c=0;c<this._stack.length&&b<a;c++){var d=this._stack[c],f=!0;k.forEach(function(a){a.test(d)&&(f=!1)}),f&&(e.debug(d),b++)}}}),define("pilot/useragent",function(a,b,c){var d=(navigator.platform.match(/mac|win|linux/i)||["other"])[0].toLowerCase(),e=navigator.userAgent,f=navigator.appVersion;b.isWin=d=="win",b.isMac=d=="mac",b.isLinux=d=="linux",b.isIE=!+"1",b.isGecko=b.isMozilla=window.controllers&&window.navigator.product==="Gecko",b.isOldGecko=b.isGecko&&/rv\:1/.test(navigator.userAgent),b.isOpera=window.opera&&Object.prototype.toString.call(window.opera)=="[object Opera]",b.isWebKit=parseFloat(e.split("WebKit/")[1])||undefined,b.isAIR=e.indexOf("AdobeAIR")>=0,b.isIPad=e.indexOf("iPad")>=0,b.OS={LINUX:"LINUX",MAC:"MAC",WINDOWS:"WINDOWS"},b.getOS=function(){return b.isMac?b.OS.MAC:b.isLinux?b.OS.LINUX:b.OS.WINDOWS}}),define("pilot/oop",function(a,b,c){b.inherits=function(){var a=function(){};return function(b,c){a.prototype=c.prototype,b.super_=c.prototype,b.prototype=new a,b.prototype.constructor=b}}(),b.mixin=function(a,b){for(var c in b)a[c]=b[c]},b.implement=function(a,c){b.mixin(a,c)}}),define("pilot/event_emitter",function(a,b,c){var d={};d._emit=d._dispatchEvent=function(a,b){this._eventRegistry=this._eventRegistry||{};var c=this._eventRegistry[a];if(c&&c.length){var b=b||{};b.type=a;for(var d=0;d<c.length;d++)c[d](b)}},d.on=d.addEventListener=function(a,b){this._eventRegistry=this._eventRegistry||{};var c=this._eventRegistry[a];if(!c)var c=this._eventRegistry[a]=[];c.indexOf(b)==-1&&c.push(b)},d.removeListener=d.removeEventListener=function(a,b){this._eventRegistry=this._eventRegistry||{};var c=this._eventRegistry[a];if(c){var d=c.indexOf(b);d!==-1&&c.splice(d,1)}},d.removeAllListeners=function(a){this._eventRegistry&&(this._eventRegistry[a]=[])},b.EventEmitter=d}),define("pilot/catalog",function(a,b,c){var d={};b.addExtensionSpec=function(a){d[a.name]=a},b.removeExtensionSpec=function(a){typeof a==="string"?delete d[a]:delete d[a.name]},b.getExtensionSpec=function(a){return d[a]},b.getExtensionSpecs=function(){return Object.keys(d)}}),define("pilot/lang",function(a,b,c){b.stringReverse=function(a){return a.split("").reverse().join("")},b.stringRepeat=function(a,b){return Array(b+1).join(a)},b.copyObject=function(a){var b={};for(var c in a)b[c]=a[c];return b},b.arrayToMap=function(a){var b={};for(var c=0;c<a.length;c++)b[a[c]]=1;return b},b.arrayRemove=function(a,b){for(var c=0;c<=a.length;c++)b===a[c]&&a.splice(c,1)},b.escapeRegExp=function(a){return a.replace(/([.*+?^${}()|[\]\/\\])/g,"\\$1")},b.deferredCall=function(a){var b=null,c=function(){b=null,a()};return{schedule:function(a){b||(b=setTimeout(c,a||0));return this},call:function(){this.cancel(),a();return this},cancel:function(){clearTimeout(b),b=null;return this}}}}),define("pilot/types/settings",function(a,b,c){var d=a("pilot/types/basic").SelectionType,e=a("pilot/types/basic").DeferredType,f=a("pilot/types"),g=a("pilot/settings").settings,h,i=new d({name:"setting",data:function(){return k.settings.getSettingNames()},stringify:function(a){h=a;return a.name},fromString:function(a){h=g.getSetting(a);return h},noMatch:function(){h=null}}),j=new e({name:"settingValue",defer:function(){return h?h.type:f.getType("text")},getDefault:function(){var a=this.parse("");if(h){var b=h.get();if(a.predictions.length===0)a.predictions.push(b);else{var c=!1;while(!0){var d=a.predictions.indexOf(b);if(d===-1)break;a.predictions.splice(d,1),c=!0}c&&a.predictions.push(b)}}return a}}),k;b.startup=function(a,b){k=a.env,f.registerType(i),f.registerType(j)},b.shutdown=function(a,b){f.unregisterType(i),f.unregisterType(j)}}),define("pilot/settings",function(a,b,c){function n(){}function k(a){this._deactivated={},this._settings={},this._settingNames=[],a&&this.setPersister(a)}function j(a,b){this._settings=b,Object.keys(a).forEach(function(b){this[b]=a[b]},this),this.type=f.getType(this.type);if(this.type==null)throw new Error("In "+this.name+": can't find type for: "+JSON.stringify(a.type));if(!this.name)throw new Error("Setting.name == undefined. Ignoring.",this);if(!this.defaultValue===undefined)throw new Error("Setting.defaultValue == undefined",this);this.onChange&&this.on("change",this.onChange.bind(this)),this.set(this.defaultValue)}var d=a("pilot/console"),e=a("pilot/oop"),f=a("pilot/types"),g=a("pilot/event_emitter").EventEmitter,h=a("pilot/catalog"),i={name:"setting",description:"A setting is something that the application offers as a way to customize how it works",register:"env.settings.addSetting",indexOn:"name"};b.startup=function(a,b){h.addExtensionSpec(i)},b.shutdown=function(a,b){h.removeExtensionSpec(i)},j.prototype={get:function(){return this.value},set:function(a){this.value!==a&&(this.value=a,this._settings.persister&&this._settings.persister.persistValue(this._settings,this.name,a),this._dispatchEvent("change",{setting:this,value:a}))},resetValue:function(){this.set(this.defaultValue)}},e.implement(j.prototype,g),k.prototype={addSetting:function(a){var b=new j(a,this);this._settings[b.name]=b,this._settingNames.push(b.name),this._settingNames.sort()},addSettings:function l(a){Object.keys(a).forEach(function(b){var c=a[b];"name"in c||(c.name=b),this.addSetting(c)},this)},removeSetting:function(a){var b=typeof a==="string"?a:a.name;a=this._settings[b],delete this._settings[b],util.arrayRemove(this._settingNames,b),settings.removeAllListeners("change")},removeSettings:function m(a){Object.keys(a).forEach(function(b){var c=a[b];"name"in c||(c.name=b),this.removeSettings(c)},this)},getSettingNames:function(){return this._settingNames},getSetting:function(a){return this._settings[a]},setPersister:function(a){this._persister=a,a&&a.loadInitialValues(this)},resetAll:function(){this.getSettingNames().forEach(function(a){this.resetValue(a)},this)},_list:function(){var a=[];this.getSettingNames().forEach(function(b){a.push({key:b,value:this.getSetting(b).get()})},this);return a},_loadDefaultValues:function(){this._loadFromObject(this._getDefaultValues())},_loadFromObject:function(a){for(var b in a)if(a.hasOwnProperty(b)){var c=this._settings[b];if(c){var d=c.type.parse(a[b]);this.set(b,d)}else this.set(b,a[b])}},_saveToObject:function(){return this.getSettingNames().map(function(a){return this._settings[a].type.stringify(this.get(a))}.bind(this))},_getDefaultValues:function(){return this.getSettingNames().map(function(a){return this._settings[a].spec.defaultValue}.bind(this))}},b.settings=new k,n.prototype={loadInitialValues:function(a){a._loadDefaultValues();var b=cookie.get("settings");a._loadFromObject(JSON.parse(b))},persistValue:function(a,b,c){try{var e=JSON.stringify(a._saveToObject());cookie.set("settings",e)}catch(f){d.error("Unable to JSONify the settings! "+f);return}}},b.CookiePersister=n}),define("pilot/commands/settings",function(a,b,c){var d={name:"set",params:[{name:"setting",type:"setting",description:"The name of the setting to display or alter",defaultValue:null},{name:"value",type:"settingValue",description:"The new value for the chosen setting",defaultValue:null}],description:"define and show settings",exec:function(a,b,c){var d;if(b.setting)b.value===undefined?d="<strong>"+setting.name+"</strong> = "+setting.get():(b.setting.set(b.value),d="Setting: <strong>"+b.setting.name+"</strong> = "+b.setting.get());else{var e=a.settings.getSettingNames();d="",e.sort(function(a,b){return a.localeCompare(b)}),e.forEach(function(b){var c=a.settings.getSetting(b),e="https://wiki.mozilla.org/Labs/Skywriter/Settings#"+c.name;d+='<a class="setting" href="'+e+'" title="View external documentation on setting: '+c.name+'" target="_blank">'+c.name+"</a> = "+c.value+"<br/>"})}c.done(d)}},e={name:"unset",params:[{name:"setting",type:"setting",description:"The name of the setting to return to defaults"}],description:"unset a setting entirely",exec:function(a,b,c){var d=a.settings.get(b.setting);d?(d.reset(),c.done("Reset "+d.name+" to default: "+a.settings.get(b.setting))):c.doneWithError("No setting with the name <strong>"+b.setting+"</strong>.")}},f=a("pilot/canon");b.startup=function(a,b){f.addCommand(d),f.addCommand(e)},b.shutdown=function(a,b){f.removeCommand(d),f.removeCommand(e)}}),define("pilot/commands/basic",function(require,exports,module){var checks=require("pilot/typecheck"),canon=require("pilot/canon"),helpMessages={plainPrefix:'<h2>Welcome to Skywriter - Code in the Cloud</h2><ul><li><a href="http://labs.mozilla.com/projects/skywriter" target="_blank">Home Page</a></li><li><a href="https://wiki.mozilla.org/Labs/Skywriter" target="_blank">Wiki</a></li><li><a href="https://wiki.mozilla.org/Labs/Skywriter/UserGuide" target="_blank">User Guide</a></li><li><a href="https://wiki.mozilla.org/Labs/Skywriter/Tips" target="_blank">Tips and Tricks</a></li><li><a href="https://wiki.mozilla.org/Labs/Skywriter/FAQ" target="_blank">FAQ</a></li><li><a href="https://wiki.mozilla.org/Labs/Skywriter/DeveloperGuide" target="_blank">Developers Guide</a></li></ul>',plainSuffix:'For more information, see the <a href="https://wiki.mozilla.org/Labs/Skywriter">Skywriter Wiki</a>.'},helpCommandSpec={name:"help",params:[{name:"search",type:"text",description:"Search string to narrow the output.",defaultValue:null}],description:"Get help on the available commands.",exec:function(a,b,c){var d=[],e=canon.getCommand(b.search);if(e&&e.exec)d.push(e.description?e.description:"No description for "+b.search);else{var f=!1;!b.search&&helpMessages.plainPrefix&&d.push(helpMessages.plainPrefix),e?(d.push("<h2>Sub-Commands of "+e.name+"</h2>"),d.push("<p>"+e.description+"</p>")):b.search?(b.search=="hidden"&&(b.search="",f=!0),d.push("<h2>Commands starting with '"+b.search+"':</h2>")):d.push("<h2>Available Commands:</h2>");var g=canon.getCommandNames();g.sort(),d.push("<table>");for(var h=0;h<g.length;h++){e=canon.getCommand(g[h]);if(!f&&e.hidden)continue;if(e.description===undefined)continue;if(b.search&&e.name.indexOf(b.search)!==0)continue;if(!b.search&&e.name.indexOf(" ")!=-1)continue;if(e&&e.name==b.search)continue;d.push("<tr>"),d.push('<th class="right">'+e.name+"</th>"),d.push("<td>"+e.description+"</td>"),d.push("</tr>")}d.push("</table>"),!b.search&&helpMessages.plainSuffix&&d.push(helpMessages.plainSuffix)}c.done(d.join(""))}},evalCommandSpec={name:"eval",params:[{name:"javascript",type:"text",description:"The JavaScript to evaluate"}],description:"evals given js code and show the result",hidden:!0,exec:function(env,args,request){var result,javascript=args.javascript;try{result=eval(javascript)}catch(e){result="<b>Error: "+e.message+"</b>"}var msg="",type="",x;if(checks.isFunction(result))msg=(result+"").replace(/\n/g,"<br>").replace(/ /g,"&#160"),type="function";else if(checks.isObject(result)){Array.isArray(result)?type="array":type="object";var items=[],value;for(x in result)result.hasOwnProperty(x)&&(checks.isFunction(result[x])?value="[function]":checks.isObject(result[x])?value="[object]":value=result[x],items.push({name:x,value:value}));items.sort(function(a,b){return a.name.toLowerCase()<b.name.toLowerCase()?-1:1});for(x=0;x<items.length;x++)msg+="<b>"+items[x].name+"</b>: "+items[x].value+"<br>"}else msg=result,type=typeof result;request.done("Result for eval <b>'"+javascript+"'</b> (type: "+type+"): <br><br>"+msg)}},versionCommandSpec={name:"version",description:"show the Skywriter version",hidden:!0,exec:function(a,b,c){var d="Skywriter "+skywriter.versionNumber+" ("+skywriter.versionCodename+")";c.done(d)}},skywriterCommandSpec={name:"skywriter",hidden:!0,exec:function(a,b,c){var d=Math.floor(Math.random()*messages.length);c.done("Skywriter "+messages[d])}},messages=["really wants you to trick it out in some way.","is your Web editor.","would love to be like Emacs on the Web.","is written on the Web platform, so you can tweak it."],canon=require("pilot/canon");exports.startup=function(a,b){canon.addCommand(helpCommandSpec),canon.addCommand(evalCommandSpec),canon.addCommand(skywriterCommandSpec)},exports.shutdown=function(a,b){canon.removeCommand(helpCommandSpec),canon.removeCommand(evalCommandSpec),canon.removeCommand(skywriterCommandSpec)}}),define("pilot/typecheck",function(a,b,c){var d=Object.prototype.toString;b.isString=function(a){return a&&d.call(a)==="[object String]"},b.isBoolean=function(a){return a&&d.call(a)==="[object Boolean]"},b.isNumber=function(a){return a&&d.call(a)==="[object Number]"&&isFinite(a)},b.isObject=function(a){return a!==undefined&&(a===null||typeof a=="object"||Array.isArray(a)||b.isFunction(a))},b.isFunction=function(a){return a&&d.call(a)==="[object Function]"}}),define("pilot/settings/canon",function(a,b,c){var d={name:"historyLength",description:"How many typed commands do we recall for reference?",type:"number",defaultValue:50};b.startup=function(a,b){a.env.settings.addSetting(d)},b.shutdown=function(a,b){a.env.settings.removeSetting(d)}}),define("pilot/plugin_manager",function(a,b,c){var d=a("pilot/promise").Promise;b.REASONS={APP_STARTUP:1,APP_SHUTDOWN:2,PLUGIN_ENABLE:3,PLUGIN_DISABLE:4,PLUGIN_INSTALL:5,PLUGIN_UNINSTALL:6,PLUGIN_UPGRADE:7,PLUGIN_DOWNGRADE:8},b.Plugin=function(a){this.name=a,this.status=this.INSTALLED},b.Plugin.prototype={NEW:0,INSTALLED:1,REGISTERED:2,STARTED:3,UNREGISTERED:4,SHUTDOWN:5,install:function(b,c){var e=new d;if(this.status>this.NEW){e.resolve(this);return e}a([this.name],function(a){a.install&&a.install(b,c),this.status=this.INSTALLED,e.resolve(this)}.bind(this));return e},register:function(b,c){var e=new d;if(this.status!=this.INSTALLED){e.resolve(this);return e}a([this.name],function(a){a.register&&a.register(b,c),this.status=this.REGISTERED,e.resolve(this)}.bind(this));return e},startup:function(c,e){e=e||b.REASONS.APP_STARTUP;var f=new d;if(this.status!=this.REGISTERED){f.resolve(this);return f}a([this.name],function(a){a.startup&&a.startup(c,e),this.status=this.STARTED,f.resolve(this)}.bind(this));return f},shutdown:function(b,c){this.status==this.STARTED&&(pluginModule=a(this.name),pluginModule.shutdown&&pluginModule.shutdown(b,c))}},b.PluginCatalog=function(){this.plugins={}},b.PluginCatalog.prototype={registerPlugins:function(a,c,e){var f=[];a.forEach(function(a){var d=this.plugins[a];d===undefined&&(d=new b.Plugin(a),this.plugins[a]=d,f.push(d.register(c,e)))}.bind(this));return d.group(f)},startupPlugins:function(a,b){var c=[];for(var e in this.plugins){var f=this.plugins[e];c.push(f.startup(a,b))}return d.group(c)}},b.catalog=new b.PluginCatalog}),define("pilot/promise",function(a,b,c){var d=a("pilot/console"),e=a("pilot/stacktrace").Trace,f=-1,g=0,h=1,i=0,j=!1,k=[],l=[];Promise=function(){this._status=g,this._value=undefined,this._onSuccessHandlers=[],this._onErrorHandlers=[],this._id=i++,k[this._id]=this},Promise.prototype.isPromise=!0,Promise.prototype.isComplete=function(){return this._status!=g},Promise.prototype.isResolved=function(){return this._status==h},Promise.prototype.isRejected=function(){return this._status==f},Promise.prototype.then=function(a,b){typeof a==="function"&&(this._status===h?a.call(null,this._value):this._status===g&&this._onSuccessHandlers.push(a)),typeof b==="function"&&(this._status===f?b.call(null,this._value):this._status===g&&this._onErrorHandlers.push(b));return this},Promise.prototype.chainPromise=function(a){var b=new Promise;b._chainedFrom=this,this.then(function(c){try{b.resolve(a(c))}catch(d){b.reject(d)}},function(a){b.reject(a)});return b},Promise.prototype.resolve=function(a){return this._complete(this._onSuccessHandlers,h,a,"resolve")},Promise.prototype.reject=function(a){return this._complete(this._onErrorHandlers,f,a,"reject")},Promise.prototype._complete=function(a,b,c,f){if(this._status!=g){d.group("Promise already closed"),d.error("Attempted "+f+"() with ",c),d.error("Previous status = ",this._status,", previous value = ",this._value),d.trace(),this._completeTrace&&(d.error("Trace of previous completion:"),this._completeTrace.log(5)),d.groupEnd();return this}j&&(this._completeTrace=new e(new Error)),this._status=b,this._value=c,a.forEach(function(a){a.call(null,this._value)},this),this._onSuccessHandlers.length=0,this._onErrorHandlers.length=0,delete k[this._id],l.push(this);while(l.length>20)l.shift();return this},Promise.group=function(a){a instanceof Array||(a=Array.prototype.slice.call(arguments));if(a.length===0)return(new Promise).resolve([]);var b=new Promise,c=[],d=0,e=function(e){return function(g){c[e]=g,d++,b._status!==f&&(d===a.length&&b.resolve(c))}};a.forEach(function(a,c){var d=e(c),f=b.reject.bind(b);a.then(d,f)});return b},b.Promise=Promise,b._outstanding=k,b._recent=l}),define("pilot/environment",function(a,b,c){function e(){return{settings:d}}var d=a("pilot/settings").settings;b.create=e}),define("ace/editor",function(a,b,c){a("pilot/fixoldbrowsers");var d=a("pilot/oop"),e=a("pilot/event"),f=a("pilot/lang"),g=a("pilot/useragent"),h=a("ace/keyboard/textinput").TextInput,i=a("ace/mouse_handler").MouseHandler,j=a("ace/keyboard/keybinding").KeyBinding,k=a("ace/edit_session").EditSession,l=a("ace/search").Search,m=a("ace/background_tokenizer").BackgroundTokenizer,n=a("ace/range").Range,o=a("pilot/event_emitter").EventEmitter,p=function(a,b){var c=a.getContainerElement();this.container=c,this.renderer=a,this.textInput=new h(a.getTextAreaContainer(),this),this.keyBinding=new j(this),g.isIPad||(this.$mouseHandler=new i(this)),this.$blockScrolling=0,this.$search=(new l).set({wrap:!0}),this.setSession(b||new k(""))};(function(){d.implement(this,o),this.$forwardEvents={gutterclick:1,gutterdblclick:1},this.$originalAddEventListener=this.addEventListener,this.$originalRemoveEventListener=this.removeEventListener,this.addEventListener=function(a,b){return this.$forwardEvents[a]?this.renderer.addEventListener(a,b):this.$originalAddEventListener(a,b)},this.removeEventListener=function(a,b){return this.$forwardEvents[a]?this.renderer.removeEventListener(a,b):this.$originalRemoveEventListener(a,b)},this.setKeyboardHandler=function(a){this.keyBinding.setKeyboardHandler(a)},this.getKeyboardHandler=function(){return this.keyBinding.getKeyboardHandler()},this.setSession=function(a){if(this.session!=a){if(this.session){var b=this.session;this.session.removeEventListener("change",this.$onDocumentChange),this.session.removeEventListener("changeMode",this.$onDocumentModeChange),this.session.removeEventListener("changeTabSize",this.$onDocumentChangeTabSize),this.session.removeEventListener("changeWrapLimit",this.$onDocumentChangeWrapLimit),this.session.removeEventListener("changeWrapMode",this.$onDocumentChangeWrapMode),this.session.removeEventListener("changeFrontMarker",this.$onChangeFrontMarker),this.session.removeEventListener("changeBackMarker",this.$onChangeBackMarker),this.session.removeEventListener("changeBreakpoint",this.$onDocumentChangeBreakpoint),this.session.removeEventListener("changeAnnotation",this.$onDocumentChangeAnnotation);var c=this.session.getSelection();c.removeEventListener("changeCursor",this.$onCursorChange),c.removeEventListener("changeSelection",this.$onSelectionChange),this.session.setScrollTopRow(this.renderer.getScrollTopRow())}this.session=a,this.$onDocumentChange=this.onDocumentChange.bind(this),a.addEventListener("change",this.$onDocumentChange),this.renderer.setSession(a),this.$onDocumentModeChange=this.onDocumentModeChange.bind(this),a.addEventListener("changeMode",this.$onDocumentModeChange),this.$onDocumentChangeTabSize=this.renderer.updateText.bind(this.renderer),a.addEventListener("changeTabSize",this.$onDocumentChangeTabSize),this.$onDocumentChangeWrapLimit=this.onDocumentChangeWrapLimit.bind(this),a.addEventListener("changeWrapLimit",this.$onDocumentChangeWrapLimit),this.$onDocumentChangeWrapMode=this.onDocumentChangeWrapMode.bind(this),a.addEventListener("changeWrapMode",this.$onDocumentChangeWrapMode),this.$onChangeFrontMarker=this.onChangeFrontMarker.bind(this),this.session.addEventListener("changeFrontMarker",this.$onChangeFrontMarker),this.$onChangeBackMarker=this.onChangeBackMarker.bind(this),this.session.addEventListener("changeBackMarker",this.$onChangeBackMarker),this.$onDocumentChangeBreakpoint=this.onDocumentChangeBreakpoint.bind(this),this.session.addEventListener("changeBreakpoint",this.$onDocumentChangeBreakpoint),this.$onDocumentChangeAnnotation=this.onDocumentChangeAnnotation.bind(this),this.session.addEventListener("changeAnnotation",this.$onDocumentChangeAnnotation),this.selection=a.getSelection(),this.$onCursorChange=this.onCursorChange.bind(this),this.selection.addEventListener("changeCursor",this.$onCursorChange),this.$onSelectionChange=this.onSelectionChange.bind(this),this.selection.addEventListener("changeSelection",this.$onSelectionChange),this.onDocumentModeChange(),this.bgTokenizer.setDocument(a.getDocument()),this.bgTokenizer.start(0),this.onCursorChange(),this.onSelectionChange(),this.onChangeFrontMarker(),this.onChangeBackMarker(),this.onDocumentChangeBreakpoint(),this.onDocumentChangeAnnotation(),this.renderer.scrollToRow(a.getScrollTopRow()),this.renderer.updateFull(),this._dispatchEvent("changeSession",{session:a,oldSession:b})}},this.getSession=function(){return this.session},this.getSelection=function(){return this.selection},this.resize=function(){this.renderer.onResize()},this.setTheme=function(a){this.renderer.setTheme(a)},this.setStyle=function(a){this.renderer.setStyle(a)},this.unsetStyle=function(a){this.renderer.unsetStyle(a)},this.$highlightBrackets=function(){this.$bracketHighlight&&(this.session.removeMarker(this.$bracketHighlight),this.$bracketHighlight=null);if(!this.$highlightPending){var a=this;this.$highlightPending=!0,setTimeout(function(){a.$highlightPending=!1;var b=a.session.findMatchingBracket(a.getCursorPosition());if(b){var c=new n(b.row,b.column,b.row,b.column+1);a.$bracketHighlight=a.session.addMarker(c,"ace_bracket")}},10)}},this.focus=function(){var a=this;setTimeout(function(){a.textInput.focus()}),this.textInput.focus()},this.blur=function(){this.textInput.blur()},this.onFocus=function(){this.renderer.showCursor(),this.renderer.visualizeFocus(),this._dispatchEvent("focus")},this.onBlur=function(){this.renderer.hideCursor(),this.renderer.visualizeBlur(),this._dispatchEvent("blur")},this.onDocumentChange=function(a){var b=a.data,c=b.range;this.bgTokenizer.start(c.start.row);if(c.start.row==c.end.row&&b.action!="insertLines"&&b.action!="removeLines")var d=c.end.row;else d=Infinity;this.renderer.updateLines(c.start.row,d),this.renderer.updateCursor(this.getCursorPosition(),this.$overwrite)},this.onTokenizerUpdate=function(a){var b=a.data;this.renderer.updateLines(b.first,b.last)},this.onCursorChange=function(a){this.renderer.updateCursor(this.getCursorPosition(),this.$overwrite),this.$blockScrolling||this.renderer.scrollCursorIntoView(),this.renderer.moveTextAreaToCursor(this.textInput.getElement()),this.$highlightBrackets(),this.$updateHighlightActiveLine()},this.$updateHighlightActiveLine=function(){var a=this.getSession();a.$highlightLineMarker&&a.removeMarker(a.$highlightLineMarker),a.$highlightLineMarker=null;if(this.getHighlightActiveLine()&&(this.getSelectionStyle()!="line"||!this.selection.isMultiLine())){var b=this.getCursorPosition(),c=new n(b.row,0,b.row+1,0);a.$highlightLineMarker=a.addMarker(c,"ace_active_line","line")}},this.onSelectionChange=function(a){var b=this.getSession();b.$selectionMarker&&b.removeMarker(b.$selectionMarker),b.$selectionMarker=null;if(!this.selection.isEmpty()){var c=this.selection.getRange(),d=this.getSelectionStyle();b.$selectionMarker=b.addMarker(c,"ace_selection",d)}this.onCursorChange(a)},this.onChangeFrontMarker=function(){this.renderer.updateFrontMarkers()},this.onChangeBackMarker=function(){this.renderer.updateBackMarkers()},this.onDocumentChangeBreakpoint=function(){this.renderer.setBreakpoints(this.session.getBreakpoints())},this.onDocumentChangeAnnotation=function(){this.renderer.setAnnotations(this.session.getAnnotations())},this.onDocumentModeChange=function(){var a=this.session.getMode();if(this.mode!=a){this.mode=a;var b=a.getTokenizer();if(this.bgTokenizer)this.bgTokenizer.setTokenizer(b);else{var c=this.onTokenizerUpdate.bind(this);this.bgTokenizer=new m(b,this),this.bgTokenizer.addEventListener("update",c)}this.renderer.setTokenizer(this.bgTokenizer)}},this.onDocumentChangeWrapLimit=function(){this.renderer.updateCursor(this.getCursorPosition(),this.$overwrite),this.renderer.updateFull()},this.onDocumentChangeWrapMode=function(){this.renderer.onResize(!0)},this.getCopyText=function(){return this.selection.isEmpty()?"":this.session.getTextRange(this.getSelectionRange())},this.onCut=function(){this.$readOnly||(this.selection.isEmpty()||(this.session.remove(this.getSelectionRange()),this.clearSelection()))},this.insert=function(a){if(!this.$readOnly){var b=this.getCursorPosition();a=a.replace("\t",this.session.getTabString());if(this.selection.isEmpty()){if(this.$overwrite){var c=new n.fromPoints(b,b);c.end.column+=a.length,this.session.remove(c)}}else{var b=this.session.remove(this.getSelectionRange());this.clearSelection()}this.clearSelection();var d=this.bgTokenizer.getState(b.row),e=this.mode.checkOutdent(d,this.session.getLine(b.row),a),f=this.session.getLine(b.row),g=this.mode.getNextLineIndent(d,f.slice(0,b.column),this.session.getTabString()),h=this.session.insert(b,a);this.moveCursorToPosition(h);var d=this.bgTokenizer.getState(b.row);if(b.row!==h.row){var i=this.session.getTabSize(),j=Number.MAX_VALUE;for(var k=b.row+1;k<=h.row;++k){var l=0;f=this.session.getLine(k);for(var m=0;m<f.length;++m)if(f.charAt(m)=="\t")l+=i;else if(f.charAt(m)==" ")l+=1;else break;/[^\s]/.test(f)&&(j=Math.min(l,j))}for(var k=b.row+1;k<=h.row;++k){var o=j;f=this.session.getLine(k);for(var m=0;m<f.length&&o>0;++m)f.charAt(m)=="\t"?o-=i:f.charAt(m)==" "&&(o-=1);this.session.remove(new n(k,0,k,m))}this.session.indentRows(b.row+1,h.row,g)}else e&&this.mode.autoOutdent(d,this.session,b.row)}},this.onTextInput=function(a){this.keyBinding.onTextInput(a)},this.onCommandKey=function(a,b,c){this.keyBinding.onCommandKey(a,b,c)},this.$overwrite=!1,this.setOverwrite=function(a){this.$overwrite!=a&&(this.$overwrite=a,this.$blockScrolling+=1,this.onCursorChange(),this.$blockScrolling-=1,this._dispatchEvent("changeOverwrite",{data:a}))},this.getOverwrite=function(){return this.$overwrite},this.toggleOverwrite=function(){this.setOverwrite(!this.$overwrite)},this.setScrollSpeed=function(a){this.$mouseHandler.setScrollSpeed(a)},this.getScrollSpeed=function(){return this.$mouseHandler.getScrollSpeed()},this.$selectionStyle="line",this.setSelectionStyle=function(a){this.$selectionStyle!=a&&(this.$selectionStyle=a,this.onSelectionChange(),this._dispatchEvent("changeSelectionStyle",{data:a}))},this.getSelectionStyle=function(){return this.$selectionStyle},this.$highlightActiveLine=!0,this.setHighlightActiveLine=function(a){this.$highlightActiveLine!=a&&(this.$highlightActiveLine=a,this.$updateHighlightActiveLine())},this.getHighlightActiveLine=function(){return this.$highlightActiveLine},this.setShowInvisibles=function(a){this.getShowInvisibles()!=a&&this.renderer.setShowInvisibles(a)},this.getShowInvisibles=function(){return this.renderer.getShowInvisibles()},this.setShowPrintMargin=function(a){this.renderer.setShowPrintMargin(a)},this.getShowPrintMargin=function(){return this.renderer.getShowPrintMargin()},this.setPrintMarginColumn=function(a){this.renderer.setPrintMarginColumn(a)},this.getPrintMarginColumn=function(){return this.renderer.getPrintMarginColumn()},this.$readOnly=!1,this.setReadOnly=function(a){this.$readOnly=a},this.getReadOnly=function(){return this.$readOnly},this.removeRight=function(){this.$readOnly||(this.selection.isEmpty()&&this.selection.selectRight(),this.session.remove(this.getSelectionRange()),this.clearSelection())},this.removeLeft=function(){this.$readOnly||(this.selection.isEmpty()&&this.selection.selectLeft(),this.session.remove(this.getSelectionRange()),this.clearSelection())},this.removeWordRight=function(){this.$readOnly||(this.selection.isEmpty()&&this.selection.selectWordRight(),this.session.remove(this.getSelectionRange()),this.clearSelection())},this.removeWordLeft=function(){this.$readOnly||(this.selection.isEmpty()&&this.selection.selectWordLeft(),this.session.remove(this.getSelectionRange()),this.clearSelection())},this.removeToLineStart=function(){this.$readOnly||(this.selection.isEmpty()&&this.selection.selectLineStart(),this.session.remove(this.getSelectionRange()),this.clearSelection())},this.removeToLineEnd=function(){this.$readOnly||(this.selection.isEmpty()&&this.selection.selectLineEnd(),this.session.remove(this.getSelectionRange()),this.clearSelection())},this.splitLine=function(){if(!this.$readOnly){this.selection.isEmpty()||(this.session.remove(this.getSelectionRange()),this.clearSelection());var a=this.getCursorPosition();this.insert("\n"),this.moveCursorToPosition(a)}},this.transposeLetters=function(){if(!this.$readOnly){if(!this.selection.isEmpty())return;var a=this.getCursorPosition(),b=a.column;if(b==0)return;var c=this.session.getLine(a.row);if(b<c.length)var d=c.charAt(b)+c.charAt(b-1),e=new n(a.row,b-1,a.row,b+1);else var d=c.charAt(b-1)+c.charAt(b-2),e=new n(a.row,b-2,a.row,b);this.session.replace(e,d)}},this.indent=function(){if(!this.$readOnly){var a=this.session,b=this.getSelectionRange();if(b.start.row>=b.end.row&&b.start.column>=b.end.column){var d;if(this.session.getUseSoftTabs()){var e=a.getTabSize(),g=this.getCursorPosition(),h=a.documentToScreenColumn(g.row,g.column),i=e-h%e;d=f.stringRepeat(" ",i)}else d="\t";return this.onTextInput(d)}var c=this.$getSelectedRows();a.indentRows(c.first,c.last,"\t")}},this.blockOutdent=function(){if(!this.$readOnly){var a=this.session.getSelection();this.session.outdentRows(a.getRange())}},this.toggleCommentLines=function(){if(!this.$readOnly){var a=this.bgTokenizer.getState(this.getCursorPosition().row),b=this.$getSelectedRows();this.mode.toggleCommentLines(a,this.session,b.first,b.last)}},this.removeLines=function(){if(!this.$readOnly){var a=this.$getSelectedRows();this.session.remove(new n(a.first,0,a.last+1,0)),this.clearSelection()}},this.moveLinesDown=function(){this.$readOnly||this.$moveLines(function(a,b){return this.session.moveLinesDown(a,b)})},this.moveLinesUp=function(){this.$readOnly||this.$moveLines(function(a,b){return this.session.moveLinesUp(a,b)})},this.copyLinesUp=function(){this.$readOnly||this.$moveLines(function(a,b){this.session.duplicateLines(a,b);return 0})},this.copyLinesDown=function(){this.$readOnly||this.$moveLines(function(a,b){return this.session.duplicateLines(a,b)})},this.$moveLines=function(a){var b=this.$getSelectedRows(),c=a.call(this,b.first,b.last),d=this.selection;d.setSelectionAnchor(b.last+c+1,0),d.$moveSelection(function(){d.moveCursorTo(b.first+c,0)})},this.$getSelectedRows=function(){var a=this.getSelectionRange().collapseRows();return{first:a.start.row,last:a.end.row}},this.onCompositionStart=function(a){this.renderer.showComposition(this.getCursorPosition())},this.onCompositionUpdate=function(a){this.renderer.setCompositionText(a)},this.onCompositionEnd=function(){this.renderer.hideComposition()},this.getFirstVisibleRow=function(){return this.renderer.getFirstVisibleRow()},this.getLastVisibleRow=function(){return this.renderer.getLastVisibleRow()},this.isRowVisible=function(a){return a>=this.getFirstVisibleRow()&&a<=this.getLastVisibleRow()},this.getVisibleRowCount=function(){return this.getLastVisibleRow()-this.getFirstVisibleRow()+1},this.getPageDownRow=function(){return this.renderer.getLastVisibleRow()-1},this.getPageUpRow=function(){var a=this.renderer.getFirstVisibleRow(),b=this.renderer.getLastVisibleRow();return a-(b-a)+1},this.selectPageDown=function(){var a=this.getPageDownRow()+Math.floor(this.getVisibleRowCount()/2);this.scrollPageDown();var b=this.getSelection();b.$moveSelection(function(){b.moveCursorTo(a,b.getSelectionLead().column)})},this.selectPageUp=function(){var a=this.getLastVisibleRow()-this.getFirstVisibleRow(),b=this.getPageUpRow()+Math.round(a/2);this.scrollPageUp();var c=this.getSelection();c.$moveSelection(function(){c.moveCursorTo(b,c.getSelectionLead().column)})},this.gotoPageDown=function(){var a=this.getPageDownRow(),b=Math.min(this.getCursorPosition().column,this.session.getLine(a).length);this.scrollToRow(a),this.getSelection().moveCursorTo(a,b)},this.gotoPageUp=function(){var a=this.getPageUpRow(),b=Math.min(this.getCursorPosition().column,this.session.getLine(a).length);this.scrollToRow(a),this.getSelection().moveCursorTo(a,b)},this.scrollPageDown=function(){this.scrollToRow(this.getPageDownRow())},this.scrollPageUp=function(){this.renderer.scrollToRow(this.getPageUpRow())},this.scrollToRow=function(a){this.renderer.scrollToRow(a)},this.scrollToLine=function(a,b){this.renderer.scrollToLine(a,b)},this.centerSelection=function(){var a=this.getSelectionRange(),b=Math.floor(a.start.row+(a.end.row-a.start.row)/2);this.renderer.scrollToLine(b,!0)},this.getCursorPosition=function(){return this.selection.getCursor()},this.getSelectionRange=function(){return this.selection.getRange()},this.selectAll=function(){this.$blockScrolling+=1,this.selection.selectAll(),this.$blockScrolling-=1},this.clearSelection=function(){this.selection.clearSelection()},this.moveCursorTo=function(a,b){this.selection.moveCursorTo(a,b)},this.moveCursorToPosition=function(a){this.selection.moveCursorToPosition(a)},this.gotoLine=function(a,b){this.selection.clearSelection(),this.$blockScrolling+=1,this.moveCursorTo(a-1,b||0),this.$blockScrolling-=1,this.isRowVisible(this.getCursorPosition().row)||this.scrollToLine(a,!0)},this.navigateTo=function(a,b){this.clearSelection(),this.moveCursorTo(a,b)},this.navigateUp=function(a){this.selection.clearSelection(),a=a||1,this.selection.moveCursorBy(-a,0)},this.navigateDown=function(a){this.selection.clearSelection(),a=a||1,this.selection.moveCursorBy(a,0)},this.navigateLeft=function(a){if(this.selection.isEmpty()){a=a||1;while(a--)this.selection.moveCursorLeft()}else{var b=this.getSelectionRange().start;this.moveCursorToPosition(b)}this.clearSelection()},this.navigateRight=function(a){if(this.selection.isEmpty()){a=a||1;while(a--)this.selection.moveCursorRight()}else{var b=this.getSelectionRange().end;this.moveCursorToPosition(b)}this.clearSelection()},this.navigateLineStart=function(){this.selection.moveCursorLineStart(),this.clearSelection()},this.navigateLineEnd=function(){this.selection.moveCursorLineEnd(),this.clearSelection()},this.navigateFileEnd=function(){this.selection.moveCursorFileEnd(),this.clearSelection()},this.navigateFileStart=function(){this.selection.moveCursorFileStart(),this.clearSelection()},this.navigateWordRight=function(){this.selection.moveCursorWordRight(),this.clearSelection()},this.navigateWordLeft=function(){this.selection.moveCursorWordLeft(),this.clearSelection()},this.replace=function(a,b){b&&this.$search.set(b);var c=this.$search.find(this.session);this.$tryReplace(c,a),c!==null&&this.selection.setSelectionRange(c)},this.replaceAll=function(a,b){b&&this.$search.set(b);var c=this.$search.findAll(this.session);if(c.length){var d=this.getSelectionRange();this.clearSelection(),this.selection.moveCursorTo(0,0),this.$blockScrolling+=1;for(var e=c.length-1;e>=0;--e)this.$tryReplace(c[e],a);this.selection.setSelectionRange(d),this.$blockScrolling-=1}},this.$tryReplace=function(a,b){var c=this.session.getTextRange(a),b=this.$search.replace(c,b);if(b!==null){a.end=this.session.replace(a,b);return a}return null},this.getLastSearchOptions=function(){return this.$search.getOptions()},this.find=function(a,b){this.clearSelection(),b=b||{},b.needle=a,this.$search.set(b),this.$find()},this.findNext=function(a){a=a||{},typeof a.backwards=="undefined"&&(a.backwards=!1),this.$search.set(a),this.$find()},this.findPrevious=function(a){a=a||{},typeof a.backwards=="undefined"&&(a.backwards=!0),this.$search.set(a),this.$find()},this.$find=function(a){this.selection.isEmpty()||this.$search.set({needle:this.session.getTextRange(this.getSelectionRange())}),typeof a!="undefined"&&this.$search.set({backwards:a});var b=this.$search.find(this.session);b&&(this.gotoLine(b.end.row+1,b.end.column),this.selection.setSelectionRange(b))},this.undo=function(){this.session.getUndoManager().undo()},this.redo=function(){this.session.getUndoManager().redo()}}).call(p.prototype),b.Editor=p}),define("pilot/event",function(a,b,c){function g(a,b,c){var f=0;e.isOpera&&e.isMac?f=0|(b.metaKey?1:0)|(b.altKey?2:0)|(b.shiftKey?4:0)|(b.ctrlKey?8:0):f=0|(b.ctrlKey?1:0)|(b.altKey?2:0)|(b.shiftKey?4:0)|(b.metaKey?8:0);if(c in d.MODIFIER_KEYS){switch(d.MODIFIER_KEYS[c]){case"Alt":f=2;break;case"Shift":f=4;break;case"Ctrl":f=1;break;default:f=8}c=0}f&8&&(c==91||c==93)&&(c=0);if(f==0&&!(c in d.FUNCTION_KEYS))return!1;return a(b,f,c)}var d=a("pilot/keys"),e=a("pilot/useragent"),f=a("pilot/dom");b.addListener=function(a,b,c){if(a.addEventListener)return a.addEventListener(b,c,!1);if(a.attachEvent){var d=function(){c(window.event)};c._wrapper=d,a.attachEvent("on"+b,d)}},b.removeListener=function(a,b,c){if(a.removeEventListener)return a.removeEventListener(b,c,!1);a.detachEvent&&a.detachEvent("on"+b,c._wrapper||c)},b.stopEvent=function(a){b.stopPropagation(a),b.preventDefault(a);return!1},b.stopPropagation=function(a){a.stopPropagation?a.stopPropagation():a.cancelBubble=!0},b.preventDefault=function(a){a.preventDefault?a.preventDefault():a.returnValue=!1},b.getDocumentX=function(a){return a.clientX?a.clientX+f.getPageScrollLeft():a.pageX},b.getDocumentY=function(a){return a.clientY?a.clientY+f.getPageScrollTop():a.pageY},b.getButton=function(a){if(a.type=="dblclick")return 0;if(a.type=="contextmenu")return 2;return a.preventDefault?a.button:({1:0,2:2,4:1})[a.button]},document.documentElement.setCapture?b.capture=function(a,c,d){function f(e){c&&c(e),d&&d(),b.removeListener(a,"mousemove",c),b.removeListener(a,"mouseup",f),b.removeListener(a,"losecapture",f),a.releaseCapture()}function e(a){c(a);return b.stopPropagation(a)}b.addListener(a,"mousemove",c),b.addListener(a,"mouseup",f),b.addListener(a,"losecapture",f),a.setCapture()}:b.capture=function(a,b,c){function e(a){b&&b(a),c&&c(),document.removeEventListener("mousemove",d,!0),document.removeEventListener("mouseup",e,!0),a.stopPropagation()}function d(a){b(a),a.stopPropagation()}document.addEventListener("mousemove",d,!0),document.addEventListener("mouseup",e,!0)},b.addMouseWheelListener=function(a,c){var d=function(a){a.wheelDelta!==undefined?a.wheelDeltaX!==undefined?(a.wheelX=-a.wheelDeltaX/8,a.wheelY=-a.wheelDeltaY/8):(a.wheelX=0,a.wheelY=-a.wheelDelta/8):a.axis&&a.axis==a.HORIZONTAL_AXIS?(a.wheelX=(a.detail||0)*5,a.wheelY=0):(a.wheelX=0,a.wheelY=(a.detail||0)*5),c(a)};b.addListener(a,"DOMMouseScroll",d),b.addListener(a,"mousewheel",d)},b.addMultiMouseDownListener=function(a,c,d,f,g){var h=0,i,j,k=function(a){h+=1,h==1&&(i=a.clientX,j=a.clientY,setTimeout(function(){h=0},f||600));if(b.getButton(a)!=c||Math.abs(a.clientX-i)>5||Math.abs(a.clientY-j)>5)h=0;h==d&&(h=0,g(a));return b.preventDefault(a)};b.addListener(a,"mousedown",k),e.isIE&&b.addListener(a,"dblclick",k)},b.addCommandKeyListener=function(a,c){var d=b.addListener;if(e.isOldGecko){var f=null;d(a,"keydown",function(a){f=a.keyCode}),d(a,"keypress",function(a){return g(c,a,f)})}else{var h=null;d(a,"keydown",function(a){h=a.keyIdentifier||a.keyCode;return g(c,a,a.keyCode)}),e.isMac&&e.isOpera&&d(a,"keypress",function(a){var b=a.keyIdentifier||a.keyCode;if(h!==b)return g(c,a,a.keyCode);h=null})}}}),define("pilot/keys",function(a,b,c){var d=a("pilot/oop"),e=function(){var a={MODIFIER_KEYS:{16:"Shift",17:"Ctrl",18:"Alt",224:"Meta"},KEY_MODS:{ctrl:1,alt:2,option:2,shift:4,meta:8,command:8},FUNCTION_KEYS:{8:"Backspace",9:"Tab",13:"Return",19:"Pause",27:"Esc",32:"Space",33:"PageUp",34:"PageDown",35:"End",36:"Home",37:"Left",38:"Up",39:"Right",40:"Down",44:"Print",45:"Insert",46:"Delete",112:"F1",113:"F2",114:"F3",115:"F4",116:"F5",117:"F6",118:"F7",119:"F8",120:"F9",121:"F10",122:"F11",123:"F12",144:"Numlock",145:"Scrolllock"},PRINTABLE_KEYS:{32:" ",48:"0",49:"1",50:"2",51:"3",52:"4",53:"5",54:"6",55:"7",56:"8",57:"9",59:";",61:"=",65:"a",66:"b",67:"c",68:"d",69:"e",70:"f",71:"g",72:"h",73:"i",74:"j",75:"k",76:"l",77:"m",78:"n",79:"o",80:"p",81:"q",82:"r",83:"s",84:"t",85:"u",86:"v",87:"w",88:"x",89:"y",90:"z",107:"+",109:"-",110:".",188:",",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:'"'}};for(i in a.FUNCTION_KEYS){var b=a.FUNCTION_KEYS[i].toUpperCase();a[b]=parseInt(i,10)}d.mixin(a,a.MODIFIER_KEYS),d.mixin(a,a.PRINTABLE_KEYS),d.mixin(a,a.FUNCTION_KEYS);return a}();d.mixin(b,e)}),define("pilot/dom",function(a,b,c){b.setText=function(a,b){a.innerText!==undefined&&(a.innerText=b),a.textContent!==undefined&&(a.textContent=b)},b.hasCssClass=function(a,b){var c=a.className.split(/\s+/g);return c.indexOf(b)!==-1},b.addCssClass=function(a,c){b.hasCssClass(a,c)||(a.className+=" "+c)},b.setCssClass=function(a,c,d){d?b.addCssClass(a,c):b.removeCssClass(a,c)},b.removeCssClass=function(a,b){var c=a.className.split(/\s+/g);while(!0){var d=c.indexOf(b);if(d==-1)break;c.splice(d,1)}a.className=c.join(" ")},b.importCssString=function(a,b){b=b||document;if(b.createStyleSheet){var c=b.createStyleSheet();c.cssText=a}else{var d=b.createElement("style");d.appendChild(b.createTextNode(a)),b.getElementsByTagName("head")[0].appendChild(d)}},b.getInnerWidth=function(a){return parseInt(b.computedStyle(a,"paddingLeft"))+parseInt(b.computedStyle(a,"paddingRight"))+a.clientWidth},b.getInnerHeight=function(a){return parseInt(b.computedStyle(a,"paddingTop"))+parseInt(b.computedStyle(a,"paddingBottom"))+a.clientHeight},window.pageYOffset!==undefined?(b.getPageScrollTop=function(){return window.pageYOffset},b.getPageScrollLeft=function(){return window.pageXOffset}):(b.getPageScrollTop=function(){return document.body.scrollTop},b.getPageScrollLeft=function(){return document.body.scrollLeft}),b.computedStyle=function(a,b){return window.getComputedStyle?(window.getComputedStyle(a,"")||{})[b]||"":a.currentStyle[b]},b.scrollbarWidth=function(){var a=document.createElement("p");a.style.width="100%",a.style.height="200px";var b=document.createElement("div"),c=b.style;c.position="absolute",c.left="-10000px",c.overflow="hidden",c.width="200px",c.height="150px",b.appendChild(a),document.body.appendChild(b);var d=a.offsetWidth;c.overflow="scroll";var e=a.offsetWidth;d==e&&(e=b.clientWidth),document.body.removeChild(b);return d-e},b.setInnerHtml=function(a,b){var c=a.cloneNode(!1);c.innerHTML=b,a.parentNode.replaceChild(c,a);return c},b.setInnerText=function(a,b){"textContent"in document.body?a.textContent=b:a.innerText=b},b.getInnerText=function(a){return"textContent"in document.body?a.textContent:a.innerText},b.getParentWindow=function(a){return a.defaultView||a.parentWindow},b.getSelectionStart=function(a){var b;try{b=a.selectionStart||0}catch(c){b=0}return b},b.setSelectionStart=function(a,b){return a.selectionStart=b},b.getSelectionEnd=function(a){var b;try{b=a.selectionEnd||0}catch(c){b=0}return b},b.setSelectionEnd=function(a,b){return a.selectionEnd=b}}),define("ace/keyboard/textinput",function(a,b,c){var d=a("pilot/event"),e=a("pilot/useragent"),f=function(a,b){function j(a){if(!h){var d=a||c.value;d&&(d.charCodeAt(d.length-1)==f.charCodeAt(0)?(d=d.slice(0,-1),d&&b.onTextInput(d)):b.onTextInput(d))}h=!1,c.value=f,c.select()}var c=document.createElement("textarea");c.style.left="-10000px",a.appendChild(c);var f=String.fromCharCode(0);j();var g=!1,h=!1,i="",k=function(a){(!e.isIE||c.value.charCodeAt(0)<=128)&&setTimeout(function(){g||j()},0)},l=function(a){g=!0,e.isIE||(j(),c.value=""),b.onCompositionStart(),e.isGecko||setTimeout(m,0)},m=function(){g&&b.onCompositionUpdate(c.value)},n=function(){g=!1,b.onCompositionEnd(),setTimeout(function(){j()},0)},o=function(a){h=!0;var d=b.getCopyText();d?c.value=d:a.preventDefault(),c.select(),setTimeout(function(){j()},0)},p=function(a){h=!0;var d=b.getCopyText();d?(c.value=d,b.onCut()):a.preventDefault(),c.select(),setTimeout(function(){j()},0)};d.addCommandKeyListener(c,b.onCommandKey.bind(b)),d.addListener(c,"keypress",k);if(e.isIE){var q={13:1,27:1};d.addListener(c,"keyup",function(a){g&&(!c.value||q[a.keyCode])&&setTimeout(n,0);(c.value.charCodeAt(0)|0)>=129&&(g?m():l())})}d.addListener(c,"textInput",k),d.addListener(c,"paste",function(a){a.clipboardData&&a.clipboardData.getData?(j(a.clipboardData.getData("text/plain")),a.preventDefault()):k()}),e.isIE||d.addListener(c,"propertychange",k),e.isIE?(d.addListener(c,"beforecopy",function(a){var c=b.getCopyText();c?clipboardData.setData("Text",c):a.preventDefault()}),d.addListener(a,"keydown",function(a){if(a.ctrlKey&&a.keyCode==88){var c=b.getCopyText();c&&(clipboardData.setData("Text",c),b.onCut()),d.preventDefault(a)}})):(d.addListener(c,"copy",o),d.addListener(c,"cut",p)),d.addListener(c,"compositionstart",l),e.isGecko&&d.addListener(c,"text",m),e.isWebKit&&d.addListener(c,"keyup",m),d.addListener(c,"compositionend",n),d.addListener(c,"blur",function(){b.onBlur()}),d.addListener(c,"focus",function(){b.onFocus(),c.select()}),this.focus=function(){b.onFocus(),c.select(),c.focus()},this.blur=function(){c.blur()},this.getElement=function(){return c},this.onContextMenu=function(a,b){a&&(i||(i=c.style.cssText),c.style.cssText="position:fixed; z-index:1000;left:"+(a.x-2)+"px; top:"+(a.y-2)+"px;"),b&&(c.value="")},this.onContextMenuClose=function(){setTimeout(function(){i&&(c.style.cssText=i,i=""),j()},0)}};b.TextInput=f}),define("ace/mouse_handler",function(a,b,c){var d=a("pilot/event"),e=function(a){this.editor=a,d.addListener(a.container,"mousedown",function(b){a.focus();return d.preventDefault(b)}),d.addListener(a.container,"selectstart",function(a){return d.preventDefault(a)});var b=a.renderer.getMouseEventTarget();d.addListener(b,"mousedown",this.onMouseDown.bind(this)),d.addMultiMouseDownListener(b,0,2,500,this.onMouseDoubleClick.bind(this)),d.addMultiMouseDownListener(b,0,3,600,this.onMouseTripleClick.bind(this)),d.addMouseWheelListener(b,this.onMouseWheel.bind(this))};(function(){this.$scrollSpeed=1,this.setScrollSpeed=function(a){this.$scrollSpeed=a},this.getScrollSpeed=function(){return this.$scrollSpeed},this.onMouseDown=function(a){var b=d.getDocumentX(a),c=d.getDocumentY(a),e=this.editor,f=e.renderer.screenToTextCoordinates(b,c);f.row=Math.max(0,Math.min(f.row,e.session.getLength()-1));var g=d.getButton(a);{if(g==0){a.shiftKey?e.selection.selectToPosition(f):(e.moveCursorToPosition(f),e.$clickSelection||e.selection.clearSelection(f.row,f.column)),e.renderer.scrollCursorIntoView();var i=this,j,k,l=function(a){j=d.getDocumentX(a),k=d.getDocumentY(a)},m=function(){clearInterval(o),i.$clickSelection=null},n=function(){if(j!==undefined&&k!==undefined){var a=e.renderer.screenToTextCoordinates(j,k);a.row=Math.max(0,Math.min(a.row,e.session.getLength()-1));if(i.$clickSelection)if(i.$clickSelection.contains(a.row,a.column))e.selection.setSelectionRange(i.$clickSelection);else{if(i.$clickSelection.compare(a.row,a.column)==-1)var b=i.$clickSelection.end;else var b=i.$clickSelection.start;e.selection.setSelectionAnchor(b.row,b.column),e.selection.selectToPosition(a)}else e.selection.selectToPosition(a);e.renderer.scrollCursorIntoView()}};d.capture(e.container,l,m);var o=setInterval(n,20);return d.preventDefault(a)}var h=e.selection.isEmpty();h&&e.moveCursorToPosition(f),g==2&&(e.textInput.onContextMenu({x:b,y:c},h),d.capture(e.container,function(){},e.textInput.onContextMenuClose))}},this.onMouseDoubleClick=function(a){this.editor.selection.selectWord(),this.$clickSelection=this.editor.getSelectionRange()},this.onMouseTripleClick=function(a){this.editor.selection.selectLine(),this.$clickSelection=this.editor.getSelectionRange()},this.onMouseWheel=function(a){var b=this.$scrollSpeed*2;this.editor.renderer.scrollBy(a.wheelX*b,a.wheelY*b);return d.preventDefault(a)}}).call(e.prototype),b.MouseHandler=e}),define("ace/keyboard/keybinding",function(a,b,c){var d=a("pilot/useragent"),e=a("pilot/keys"),f=a("pilot/event"),g=a("pilot/settings").settings,h=a("ace/keyboard/hash_handler").HashHandler,i=a("ace/keyboard/keybinding/default_mac").bindings,j=a("ace/keyboard/keybinding/default_win").bindings,k=a("pilot/canon");a("ace/commands/default_commands");var l=function(a,b){this.$editor=a,this.$data={},this.$keyboardHandler=null,this.$defaulKeyboardHandler=new h(b||(d.isMac?i:j))};(function(){this.setKeyboardHandler=function(a){this.$keyboardHandler!=a&&(this.$data={},this.$keyboardHandler=a)},this.getKeyboardHandler=function(){return this.$keyboardHandler},this.$callKeyboardHandler=function(a,b,c,d){var e;this.$keyboardHandler&&(e=this.$keyboardHandler.handleKeyboard(this.$data,b,c,d,a));if(!e||!e.command)e=this.$defaulKeyboardHandler.handleKeyboard(this.$data,b,c,d,a);if(e){var g=k.exec(e.command,{editor:this.$editor},e.args);if(g)return f.stopEvent(a)}},this.onCommandKey=function(a,b,c){key=(e[c]||String.fromCharCode(c)).toLowerCase(),this.$callKeyboardHandler(a,b,key,c)},this.onTextInput=function(a){this.$callKeyboardHandler({},0,a,0)}}).call(l.prototype),b.KeyBinding=l}),define("ace/keyboard/hash_handler",function(a,b,c){function e(a){this.setConfig(a)}var d=a("pilot/keys");(function(){function c(a,c){var d,e,f,g,h={};for(d in a){g=a[d];if(c&&typeof g=="string"){g=g.split(c);for(e=0,f=g.length;e<f;++e)b.call(this,g[e],d,h)}else b.call(this,g,d,h)}return h}function b(b,c,e){var f,g=0,h=a(b,"\\-",null,!0),i=0,j=h.length;for(;i<j;++i)d.KEY_MODS[h[i]]?g=g|d.KEY_MODS[h[i]]:f=h[i]||"-";(e[g]||(e[g]={}))[f]=c;return e}function a(a,b,c,d){return(d&&a.toLowerCase()||a).replace(/(?:^\s+|\n|\s+$)/g,"").split(new RegExp("[\\s ]*"+b+"[\\s ]*","g"),c||999)}this.setConfig=function(a){this.$config=a,typeof this.$config.reverse=="undefined"&&(this.$config.reverse=c.call(this,this.$config,"|"))},this.handleKeyboard=function(a,b,c,d){return b!=0||d!=0?{command:(this.$config.reverse[b]||{})[c]}:{command:"inserttext",args:{text:c}}}}).call(e.prototype),b.HashHandler=e}),define("ace/keyboard/keybinding/default_mac",function(a,b,c){b.bindings={selectall:"Command-A",removeline:"Command-D",gotoline:"Command-L",togglecomment:"Command-7",findnext:"Command-K",findprevious:"Command-Shift-K",find:"Command-F",replace:"Command-R",undo:"Command-Z",redo:"Command-Shift-Z|Command-Y",overwrite:"Insert",copylinesup:"Command-Option-Up",movelinesup:"Option-Up",selecttostart:"Command-Shift-Up",gotostart:"Command-Home|Command-Up",selectup:"Shift-Up",golineup:"Up|Ctrl-P",copylinesdown:"Command-Option-Down",movelinesdown:"Option-Down",selecttoend:"Command-Shift-Down",gotoend:"Command-End|Command-Down",selectdown:"Shift-Down",golinedown:"Down|Ctrl-N",selectwordleft:"Option-Shift-Left",gotowordleft:"Option-Left",selecttolinestart:"Command-Shift-Left",gotolinestart:"Command-Left|Home|Ctrl-A",selectleft:"Shift-Left",gotoleft:"Left|Ctrl-B",selectwordright:"Option-Shift-Right",gotowordright:"Option-Right",selecttolineend:"Command-Shift-Right",gotolineend:"Command-Right|End|Ctrl-E",selectright:"Shift-Right",gotoright:"Right|Ctrl-F",selectpagedown:"Shift-PageDown",pagedown:"PageDown",gotopagedown:"Option-PageDown|Ctrl-V",selectpageup:"Shift-PageUp",pageup:"PageUp",gotopageup:"Option-PageUp",selectlinestart:"Shift-Home",selectlineend:"Shift-End",del:"Delete|Ctrl-D",backspace:"Ctrl-Backspace|Command-Backspace|Shift-Backspace|Backspace|Ctrl-H",removetolineend:"Ctrl-K",removetolinestart:"Option-Backspace",removewordleft:"Alt-Backspace|Ctrl-Alt-Backspace",removewordright:"Alt-Delete",outdent:"Shift-Tab",indent:"Tab",transposeletters:"Ctrl-T",splitline:"Ctrl-O",centerselection:"Ctrl-L"}}),define("ace/keyboard/keybinding/default_win",function(a,b,c){b.bindings={selectall:"Ctrl-A",removeline:"Ctrl-D",gotoline:"Ctrl-L",togglecomment:"Ctrl-7",findnext:"Ctrl-K",findprevious:"Ctrl-Shift-K",find:"Ctrl-F",replace:"Ctrl-R",undo:"Ctrl-Z",redo:"Ctrl-Shift-Z|Ctrl-Y",overwrite:"Insert",copylinesup:"Ctrl-Alt-Up",movelinesup:"Alt-Up",selecttostart:"Alt-Shift-Up",gotostart:"Ctrl-Home|Ctrl-Up",selectup:"Shift-Up",golineup:"Up",copylinesdown:"Ctrl-Alt-Down",movelinesdown:"Alt-Down",selecttoend:"Alt-Shift-Down",gotoend:"Ctrl-End|Ctrl-Down",selectdown:"Shift-Down",golinedown:"Down",selectwordleft:"Ctrl-Shift-Left",gotowordleft:"Ctrl-Left",selecttolinestart:"Alt-Shift-Left",gotolinestart:"Alt-Left|Home",selectleft:"Shift-Left",gotoleft:"Left",selectwordright:"Ctrl-Shift-Right",gotowordright:"Ctrl-Right",selecttolineend:"Alt-Shift-Right",gotolineend:"Alt-Right|End",selectright:"Shift-Right",gotoright:"Right",selectpagedown:"Shift-PageDown",gotopagedown:"PageDown",selectpageup:"Shift-PageUp",gotopageup:"PageUp",selectlinestart:"Shift-Home",selectlineend:"Shift-End",del:"Delete",backspace:"Ctrl-Backspace|Command-Backspace|Option-Backspace|Shift-Backspace|Backspace",outdent:"Shift-Tab",indent:"Tab"}}),define("ace/commands/default_commands",function(a,b,c){var d=a("pilot/lang"),e=a("pilot/canon");e.addCommand({name:"null",exec:function(a,b,c){}}),e.addCommand({name:"selectall",exec:function(a,b,c){a.editor.selectAll()}}),e.addCommand({name:"removeline",exec:function(a,b,c){a.editor.removeLines()}}),e.addCommand({name:"gotoline",exec:function(a,b,c){var d=parseInt(prompt("Enter line number:"));isNaN(d)||a.editor.gotoLine(d)}}),e.addCommand({name:"togglecomment",exec:function(a,b,c){a.editor.toggleCommentLines()}}),e.addCommand({name:"findnext",exec:function(a,b,c){a.editor.findNext()}}),e.addCommand({name:"findprevious",exec:function(a,b,c){a.editor.findPrevious()}}),e.addCommand({name:"find",exec:function(a,b,c){var d=prompt("Find:");a.editor.find(d)}}),e.addCommand({name:"undo",exec:function(a,b,c){a.editor.undo()}}),e.addCommand({name:"redo",exec:function(a,b,c){a.editor.redo()}}),e.addCommand({name:"redo",exec:function(a,b,c){a.editor.redo()}}),e.addCommand({name:"overwrite",exec:function(a,b,c){a.editor.toggleOverwrite()}}),e.addCommand({name:"copylinesup",exec:function(a,b,c){a.editor.copyLinesUp()}}),e.addCommand({name:"movelinesup",exec:function(a,b,c){a.editor.moveLinesUp()}}),e.addCommand({name:"selecttostart",exec:function(a,b,c){a.editor.getSelection().selectFileStart()}}),e.addCommand({name:"gotostart",exec:function(a,b,c){a.editor.navigateFileStart()}}),e.addCommand({name:"selectup",exec:function(a,b,c){a.editor.getSelection().selectUp()}}),e.addCommand({name:"golineup",exec:function(a,b,c){a.editor.navigateUp(b.times)}}),e.addCommand({name:"copylinesdown",exec:function(a,b,c){a.editor.copyLinesDown()}}),e.addCommand({name:"movelinesdown",exec:function(a,b,c){a.editor.moveLinesDown()}}),e.addCommand({name:"selecttoend",exec:function(a,b,c){a.editor.getSelection().selectFileEnd()}}),e.addCommand({name:"gotoend",exec:function(a,b,c){a.editor.navigateFileEnd()}}),e.addCommand({name:"selectdown",exec:function(a,b,c){a.editor.getSelection().selectDown()}}),e.addCommand({name:"golinedown",exec:function(a,b,c){a.editor.navigateDown(b.times)}}),e.addCommand({name:"selectwordleft",exec:function(a,b,c){a.editor.getSelection().selectWordLeft()}}),e.addCommand({name:"gotowordleft",exec:function(a,b,c){a.editor.navigateWordLeft()}}),e.addCommand({name:"selecttolinestart",exec:function(a,b,c){a.editor.getSelection().selectLineStart()}}),e.addCommand({name:"gotolinestart",exec:function(a,b,c){a.editor.navigateLineStart()}}),e.addCommand({name:"selectleft",exec:function(a,b,c){a.editor.getSelection().selectLeft()}}),e.addCommand({name:"gotoleft",exec:function(a,b,c){a.editor.navigateLeft(b.times)}}),e.addCommand({name:"selectwordright",exec:function(a,b,c){a.editor.getSelection().selectWordRight()}}),e.addCommand({name:"gotowordright",exec:function(a,b,c){a.editor.navigateWordRight()}}),e.addCommand({name:"selecttolineend",exec:function(a,b,c){a.editor.getSelection().selectLineEnd()}}),e.addCommand({name:"gotolineend",exec:function(a,b,c){a.editor.navigateLineEnd()}}),e.addCommand({name:"selectright",exec:function(a,b,c){a.editor.getSelection().selectRight()}}),e.addCommand({name:"gotoright",exec:function(a,b,c){a.editor.navigateRight(b.times)}}),e.addCommand({name:"selectpagedown",exec:function(a,b,c){a.editor.selectPageDown()}}),e.addCommand({name:"pagedown",exec:function(a,b,c){a.editor.scrollPageDown()}}),e.addCommand({name:"gotopagedown",exec:function(a,b,c){a.editor.gotoPageDown()}}),e.addCommand({name:"selectpageup",exec:function(a,b,c){a.editor.selectPageUp()}}),e.addCommand({name:"pageup",exec:function(a,b,c){a.editor.scrollPageUp()}}),e.addCommand({name:"gotopageup",exec:function(a,b,c){a.editor.gotoPageUp()}}),e.addCommand({name:"selectlinestart",exec:function(a,b,c){a.editor.getSelection().selectLineStart()}}),e.addCommand({name:"gotolinestart",exec:function(a,b,c){a.editor.navigateLineStart()}}),e.addCommand({name:"selectlineend",exec:function(a,b,c){a.editor.getSelection().selectLineEnd()}}),e.addCommand({name:"gotolineend",exec:function(a,b,c){a.editor.navigateLineEnd()}}),e.addCommand({name:"del",exec:function(a,b,c){a.editor.removeRight()}}),e.addCommand({name:"backspace",exec:function(a,b,c){a.editor.removeLeft()}}),e.addCommand({name:"removetolinestart",exec:function(a,b,c){a.editor.removeToLineStart()}}),e.addCommand({name:"removetolineend",exec:function(a,b,c){a.editor.removeToLineEnd()}}),e.addCommand({name:"removewordleft",exec:function(a,b,c){a.editor.removeWordLeft()}}),e.addCommand({name:"removewordright",exec:function(a,b,c){a.editor.removeWordRight()}}),e.addCommand({name:"outdent",exec:function(a,b,c){a.editor.blockOutdent()}}),e.addCommand({name:"indent",exec:function(a,b,c){a.editor.indent()}}),e.addCommand({name:"inserttext",exec:function(a,b,c){a.editor.insert(d.stringRepeat(b.text||"",b.times||1))}}),e.addCommand({name:"centerselection",exec:function(a,b,c){a.editor.centerSelection()}}),e.addCommand({name:"splitline",exec:function(a,b,c){a.editor.splitLine()}}),e.addCommand({name:"transposeletters",exec:function(a,b,c){a.editor.transposeLetters()}})}),define("ace/edit_session",function(a,b,c){var d=a("pilot/oop"),e=a("pilot/lang"),f=a("pilot/event_emitter").EventEmitter,g=a("ace/selection").Selection,h=a("ace/mode/text").Mode,j=a("ace/range").Range,k=a("ace/document").Document,l={},m=function(a,b){this.$modified=!0,this.$breakpoints=[],this.$frontMarkers={},this.$backMarkers={},this.$markerId=1,this.$wrapData=[],this.listeners=[],a instanceof k?this.setDocument(a):this.setDocument(new k(a)),this.selection=new g(this),b&&this.setMode(b)};(function(){d.implement(this,f),this.setDocument=function(a){if(this.doc)throw new Error("Document is already set");this.doc=a,a.on("change",this.onChange.bind(this))},this.getDocument=function(){return this.doc},this.onChange=function(a){var b=a.data;this.$modified=!0,!this.$fromUndo&&this.$undoManager&&(this.$deltas.push(b),this.$informUndoManager.schedule()),this.$updateWrapDataOnChange(a),this._dispatchEvent("change",a)},this.setValue=function(a){this.doc.setValue(a),this.$deltas=[]},this.getValue=this.toString=function(){return this.doc.getValue()},this.getSelection=function(){return this.selection},this.setUndoManager=function(a){this.$undoManager=a,this.$deltas=[],this.$informUndoManager&&this.$informUndoManager.cancel();if(a){var b=this;this.$informUndoManager=e.deferredCall(function(){b.$deltas.length>0&&a.execute({action:"aceupdate",args:[b.$deltas,b]}),b.$deltas=[]})}},this.$defaultUndoManager={undo:function(){},redo:function(){}},this.getUndoManager=function(){return this.$undoManager||this.$defaultUndoManager},this.getTabString=function(){return this.getUseSoftTabs()?e.stringRepeat(" ",this.getTabSize()):"\t"},this.$useSoftTabs=!0,this.setUseSoftTabs=function(a){this.$useSoftTabs!==a&&(this.$useSoftTabs=a)},this.getUseSoftTabs=function(){return this.$useSoftTabs},this.$tabSize=4,this.setTabSize=function(a){!isNaN(a)&&this.$tabSize!==a&&(this.$modified=!0,this.$tabSize=a,this._dispatchEvent("changeTabSize"))},this.getTabSize=function(){return this.$tabSize},this.isTabStop=function(a){return this.$useSoftTabs&&a.column%this.$tabSize==0},this.getBreakpoints=function(){return this.$breakpoints},this.setBreakpoints=function(a){this.$breakpoints=[];for(var b=0;b<a.length;b++)this.$breakpoints[a[b]]=!0;this._dispatchEvent("changeBreakpoint",{})},this.clearBreakpoints=function(){this.$breakpoints=[],this._dispatchEvent("changeBreakpoint",{})},this.setBreakpoint=function(a){this.$breakpoints[a]=!0,this._dispatchEvent("changeBreakpoint",{})},this.clearBreakpoint=function(a){delete this.$breakpoints[a],this._dispatchEvent("changeBreakpoint",{})},this.getBreakpoints=function(){return this.$breakpoints},this.addMarker=function(a,b,c,d){var e=this.$markerId++,f={range:a,type:c||"line",renderer:typeof c=="function"?c:null,clazz:b,inFront:!!d};d?(this.$frontMarkers[e]=f,this._dispatchEvent("changeFrontMarker")):(this.$backMarkers[e]=f,this._dispatchEvent("changeBackMarker"));return e},this.removeMarker=function(a){var b=this.$frontMarkers[a]||this.$backMarkers[a];if(b){var c=b.inFront?this.$frontMarkers:this.$backMarkers;b&&(delete c[a],this._dispatchEvent(b.inFront?"changeFrontMarker":"changeBackMarker"))}},this.getMarkers=function(a){return a?this.$frontMarkers:this.$backMarkers},this.setAnnotations=function(a){this.$annotations={};for(var b=0;b<a.length;b++){var c=a[b],d=c.row;this.$annotations[d]?this.$annotations[d].push(c):this.$annotations[d]=[c]}this._dispatchEvent("changeAnnotation",{})},this.getAnnotations=function(){return this.$annotations},this.clearAnnotations=function(){this.$annotations={},this._dispatchEvent("changeAnnotation",{})},this.$detectNewLine=function(a){var b=a.match(/^.*?(\r?\n)/m);b?this.$autoNewLine=b[1]:this.$autoNewLine="\n"},this.tokenRe=/^[\w\d]+/g,this.nonTokenRe=/^(?:[^\w\d|[\u3040-\u309F]|[\u30A0-\u30FF]|[\u4E00-\u9FFF\uF900-\uFAFF\u3400-\u4DBF])+/g,this.getWordRange=function(a,b){var c=this.getLine(a),d=!1;b>0&&(d=!!c.charAt(b-1).match(this.tokenRe)),d||(d=!!c.charAt(b).match(this.tokenRe));var e=d?this.tokenRe:this.nonTokenRe,f=b;if(f>0){do f--;while(f>=0&&c.charAt(f).match(e));f++}var g=b;while(g<c.length&&c.charAt(g).match(e))g++;return new j(a,f,a,g)},this.setNewLineMode=function(a){this.doc.setNewLineMode(a)},this.getNewLineMode=function(){return this.doc.getNewLineMode()},this.$mode=null,this.setMode=function(a){this.$mode!==a&&(this.$worker&&this.$worker.terminate(),window.Worker?this.$worker=a.createWorker(this):this.$worker=null,this.$mode=a,this._dispatchEvent("changeMode"))},this.getMode=function(){this.$mode||(this.$mode=new h);return this.$mode},this.$scrollTop=0,this.setScrollTopRow=function(a){this.$scrollTop!==a&&(this.$scrollTop=a,this._dispatchEvent("changeScrollTop"))},this.getScrollTopRow=function(){return this.$scrollTop},this.getWidth=function(){this.$computeWidth();return this.width},this.getScreenWidth=function(){this.$computeWidth();return this.screenWidth},this.$computeWidth=function(a){if(this.$modified||a){this.$modified=!1;var b=this.doc.getAllLines(),c=0,d=0,e=this.getTabSize();for(var f=0;f<b.length;f++){var g=b[f].length;c=Math.max(c,g),b[f].replace(/\t/g,function(a){g+=e-1;return a}),d=Math.max(d,g)}this.width=c,this.$useWrapMode?this.screenWidth=this.$wrapLimit:this.screenWidth=d}},this.getLine=function(a){return this.doc.getLine(a)},this.getDisplayLine=function(a){var b=Array(this.getTabSize()+1).join(" ");return this.doc.getLine(a).replace(/\t/g,b)},this.getLines=function(a,b){return this.doc.getLines(a,b)},this.getLength=function(){return this.doc.getLength()},this.getTextRange=function(a){return this.doc.getTextRange(a)},this.findMatchingBracket=function(a){if(a.column==0)return null;var b=this.getLine(a.row).charAt(a.column-1);if(b=="")return null;var c=b.match(/([\(\[\{])|([\)\]\}])/);if(!c)return null;return c[1]?this.$findClosingBracket(c[1],a):this.$findOpeningBracket(c[2],a)},this.$brackets={")":"(","(":")","]":"[","[":"]","{":"}","}":"{"},this.$findOpeningBracket=function(a,b){var c=this.$brackets[a],d=b.column-2,e=b.row,f=1,g=this.getLine(e);while(!0){while(d>=0){var h=g.charAt(d);if(h==c){f-=1;if(f==0)return{row:e,column:d}}else h==a&&(f+=1);d-=1}e-=1;if(e<0)break;var g=this.getLine(e),d=g.length-1}return null},this.$findClosingBracket=function(a,b){var c=this.$brackets[a],d=b.column,e=b.row,f=1,g=this.getLine(e),h=this.getLength();while(!0){while(d<g.length){var i=g.charAt(d);if(i==c){f-=1;if(f==0)return{row:e,column:d}}else i==a&&(f+=1);d+=1}e+=1;if(e>=h)break;var g=this.getLine(e),d=0}return null},this.insert=function(a,b){return this.doc.insert(a,b)},this.remove=function(a){return this.doc.remove(a)},this.undoChanges=function(a){if(a.length){this.$fromUndo=!0,this.doc.revertDeltas(a),this.$fromUndo=!1;var b=a[0],c=a[a.length-1];this.selection.clearSelection(),(b.action=="insertText"||b.action=="insertLines")&&this.selection.moveCursorToPosition(b.range.start),(b.action=="removeText"||b.action=="removeLines")&&this.selection.setSelectionRange(j.fromPoints(c.range.start,b.range.end))}},this.redoChanges=function(a){if(a.length){this.$fromUndo=!0,this.doc.applyDeltas(a),this.$fromUndo=!1;var b=a[0],c=a[a.length-1];this.selection.clearSelection(),(b.action=="insertText"||b.action=="insertLines")&&this.selection.setSelectionRange(j.fromPoints(b.range.start,c.range.end)),(b.action=="removeText"||b.action=="removeLines")&&this.selection.moveCursorToPosition(c.range.start)}},this.replace=function(a,b){return this.doc.replace(a,b)},this.indentRows=function(a,b,c){c=c.replace(/\t/g,this.getTabString());for(var d=a;d<=b;d++)this.insert({row:d,column:0},c)},this.outdentRows=function(a){var b=a.collapseRows(),c=new j(0,0,0,0),d=this.getTabSize();for(var e=b.start.row;e<=b.end.row;++e){var f=this.getLine(e);c.start.row=e,c.end.row=e;for(var g=0;g<d;++g)if(f.charAt(g)!=" ")break;g<d&&f.charAt(g)=="\t"?(c.start.column=g,c.end.column=g+1):(c.start.column=0,c.end.column=g),this.remove(c)}},this.moveLinesUp=function(a,b){if(a<=0)return 0;var c=this.doc.removeLines(a,b);this.doc.insertLines(a-1,c);return-1},this.moveLinesDown=function(a,b){if(b>=this.doc.getLength()-1)return 0;var c=this.doc.removeLines(a,b);this.doc.insertLines(a+1,c);return 1},this.duplicateLines=function(a,b){var a=this.$clipRowToDocument(a),b=this.$clipRowToDocument(b),c=this.getLines(a,b);this.doc.insertLines(a,c);var d=b-a+1;return d},this.$clipRowToDocument=function(a){return Math.max(0,Math.min(a,this.doc.getLength()-1))},this.$wrapLimit=80,this.$useWrapMode=!1,this.$wrapLimitRange={min:null,max:null},this.setUseWrapMode=function(a){if(a!=this.$useWrapMode){this.$useWrapMode=a,this.$modified=!0;if(a){var b=this.getLength();this.$wrapMode=[];for(i=0;i<b;i++)this.$wrapData.push([]);this.$updateWrapData(0,b-1)}this._dispatchEvent("changeWrapMode")}},this.getUseWrapMode=function(){return this.$useWrapMode},this.setWrapLimitRange=function(a,b){if(this.$wrapLimitRange.min!==a||this.$wrapLimitRange.max!==b)this.$wrapLimitRange.min=a,this.$wrapLimitRange.max=b,this.$modified=!0,this._dispatchEvent("changeWrapMode")},this.adjustWrapLimit=function(a){var b=this.$constrainWrapLimit(a);if(b!=this.$wrapLimit&&b>0){this.$wrapLimit=b,this.$modified=!0,this.$useWrapMode&&(this.$updateWrapData(0,this.getLength()-1),this._dispatchEvent("changeWrapLimit"));return!0}return!1},this.$constrainWrapLimit=function(a){var b=this.$wrapLimitRange.min;b&&(a=Math.max(b,a));var c=this.$wrapLimitRange.max;c&&(a=Math.min(c,a));return Math.max(1,a)},this.getWrapLimit=function(){return this.$wrapLimit},this.getWrapLimitRange=function(){return{min:this.$wrapLimitRange.min,max:this.$wrapLimitRange.max}},this.$updateWrapDataOnChange=function(a){if(this.$useWrapMode){var b,c=a.data.action,d=a.data.range.start.row,e=a.data.range.end.row;c.indexOf("Lines")!=-1?(c=="insertLines"?e=d+a.data.lines.length:e=d,b=a.data.lines.length):b=e-d;if(b!=0)if(c.indexOf("remove")!=-1)this.$wrapData.splice(d,b),e=d;else{var f=[d,0];for(var g=0;g<b;g++)f.push([]);this.$wrapData.splice.apply(this.$wrapData,f)}this.$wrapData.length!=this.doc.$lines.length&&console.error("The length of doc.$lines and $wrapData have to be the same!"),this.$updateWrapData(d,e)}},this.$updateWrapData=function(a,b){var c=this.doc.getAllLines(),d=this.getTabSize(),e=this.$wrapData,f=this.$wrapLimit;for(var g=a;g<=b;g++)e[g]=this.$computeWrapSplits(c[g],f,d)};var a=1,b=2,c=3,g=4,k=5;this.$computeWrapSplits=function(a,b,d){function j(a){var b=f.slice(h,a),c=b.length;b.join("").replace(/4/g,function(a){c-=d-1}).replace(/2/g,function(a){c-=1}),i+=c,e.push(i),h=a}a=a.trimRight();if(a.length==0)return[];var d=this.getTabSize(),e=[],f=this.$getDisplayTokens(a),g=f.length,h=0,i=0;while(g-h>b){var k=h+b;if(f[k]<c){for(k;k!=h-1;k--)if(f[k]>=c){k++;break}k>h?j(k):j(h+b)}else{while(f[k]>=c)k++;j(k)}}return e},this.$getDisplayTokens=function(d){var e=[],f=this.getTabSize();for(var h=0;h<d.length;h++){var i=d.charCodeAt(h);if(i==9){e.push(g);for(var j=1;j<f;j++)e.push(k)}else i==32?e.push(c):i>=12352&&i<=12447||i>=12448&&i<=12543||i>=19968&&i<=40959||i>=63744&&i<=64255||i>=13312&&i<=19903?e.push(a,b):e.push(a)}return e},this.$getStringScreenWidth=function(a){var b=0,c=this.getTabSize();for(var d=0;d<a.length;d++){var e=a.charCodeAt(d);e==9?b+=c:e>=12352&&e<=12447||e>=12448&&e<=12543||e>=19968&&e<=40959||e>=63744&&e<=64255||e>=13312&&e<=19903?b+=2:b+=1}return b},this.getRowHeight=function(a,b){var c;this.$useWrapMode&&this.$wrapData[b]?c=this.$wrapData[b].length+1:c=1;return c*a.lineHeight},this.getScreenLastRowColumn=function(a,b){if(!this.$useWrapMode)return this.$getStringScreenWidth(this.getLine(a));var c=this.$screenToDocumentRow(a),d=c[0],e=c[1],f,g;this.$wrapData[d][e]?(f=this.$wrapData[d][e-1]||0,g=this.$wrapData[d][e],b&&g--):(g=this.getLine(d).length,f=this.$wrapData[d][e-1]||0);return b?g:this.$getStringScreenWidth(this.getLine(d).substring(f,g))},this.getDocumentLastRowColumn=function(a,b){if(!this.$useWrapMode)return this.getLine(a).length;var c=this.documentToScreenRow(a,b);return this.getScreenLastRowColumn(c,!0)},this.getScreenFirstRowColumn=function(a){if(!this.$useWrapMode)return 0;var b=this.$screenToDocumentRow(a),c=b[0],d=b[1];return this.$wrapData[c][d-1]||0},this.getRowSplitData=function(a){return this.$useWrapMode?this.$wrapData[a]:undefined},this.$screenToDocumentRow=function(a){if(!this.$useWrapMode)return[a,0];var b=this.$wrapData,c=this.getLength(),d=0;while(d<c&&a>=b[d].length+1)a-=b[d].length+1,d++;return[d,a]},this.screenToDocumentRow=function(a){return this.$screenToDocumentRow(a)[0]},this.screenToDocumentColumn=function(a,b){return this.screenToDocumentPosition(a,b).column},this.screenToDocumentPosition=function(a,b){var c,d,e,f=b,g=this.getLength();if(this.$useWrapMode){var h=this.$wrapData,d=0;while(d<g&&a>=h[d].length+1)a-=h[d].length+1,d++;d>=g&&(d=g-1,a=h[d].length),e=h[d][a-1]||0,c=this.getLine(d).substring(e)}else d=a>=g?g-1:a<0?0:a,a=0,e=0,c=this.getLine(d);var i=this.getTabSize();for(var j=0;j<c.length;j++){var k=c.charCodeAt(j);if(f>0)e+=1,k==9?f<i?(f=0,e-=1):f-=i:k>=12352&&k<=12447||k>=12448&&k<=12543||k>=19968&&k<=40959||k>=63744&&k<=64255||k>=13312&&k<=19903?f<2?(f=0,e-=1):f-=2:f-=1;else break}this.$useWrapMode?(b=h[d][a],e>=b&&(e=b-1)):c&&(e=Math.min(e,c.length));return{row:d,column:e}},this.documentToScreenColumn=function(a,b){return this.documentToScreenPosition(a,b).column},this.$documentToScreenRow=function(a,b){if(!this.$useWrapMode)return[a,0];var c=this.$wrapData,d=0;if(a>c.length-1)return[this.getScreenLength(),c.length==0?0:c[c.length-1].length-1];for(var e=0;e<a;e++)d+=c[e].length+1;var f=0;while(b>=c[a][f])d++,f++;return[d,f]},this.documentToScreenRow=function(a,b){return this.$documentToScreenRow(a,b)[0]},this.documentToScreenPosition=function(a,b){var c,d=this.getTabSize(),e;b!=null?e=a:(e=a.row,b=a.column);if(!this.$useWrapMode){c=this.getLine(e).substring(0,b),b=this.$getStringScreenWidth(c);return{row:e,column:b}}var f=this.$documentToScreenRow(e,b),g=f[0];if(e>=this.getLength())return{row:g,column:0};var h,i=this.$wrapData[e],j,k=f[1];c=this.getLine(e).substring(i[k-1]||0,b),j=this.$getStringScreenWidth(c);return{row:g,column:j}},this.getScreenLength=function(){if(!this.$useWrapMode)return this.getLength();var a=0;for(var b=0;b<this.$wrapData.length;b++)a+=this.$wrapData[b].length+1;return a}}).call(m.prototype),b.EditSession=m}),define("ace/selection",function(a,b,c){var d=a("pilot/oop"),e=a("pilot/lang"),f=a("pilot/event_emitter").EventEmitter,g=a("ace/range").Range,h=a("ace/anchor").Anchor,i=function(a){this.session=a,this.doc=a.getDocument(),this.clearSelection(),this.selectionLead=new h(this.doc,0,0),this.selectionAnchor=new h(this.doc,0,0);var b=this;this.selectionLead.on("change",function(a){b._dispatchEvent("changeCursor"),b.$isEmpty||b._dispatchEvent("changeSelection"),a.old.row==a.value.row&&b.$updateDesiredColumn()}),this.selectionAnchor.on("change",function(){b.$isEmpty||b._dispatchEvent("changeSelection")})};(function(){d.implement(this,f),this.isEmpty=function(){return this.$isEmpty||this.selectionAnchor.row==this.selectionLead.row&&this.selectionAnchor.column==this.selectionLead.column},this.isMultiLine=function(){if(this.isEmpty())return!1;return this.getRange().isMultiLine()},this.getCursor=function(){return this.selectionLead.getPosition()},this.setSelectionAnchor=function(a,b){this.selectionAnchor.setPosition(a,b),this.$isEmpty&&(this.$isEmpty=!1,this._dispatchEvent("changeSelection"))},this.getSelectionAnchor=function(){return this.$isEmpty?this.getSelectionLead():this.selectionAnchor.getPosition()},this.getSelectionLead=function(){return this.selectionLead.getPosition()},this.shiftSelection=function(a){if(this.$isEmpty)this.moveCursorTo(this.selectionLead.row,this.selectionLead.column+a);else{var b=this.getSelectionAnchor(),c=this.getSelectionLead(),d=this.isBackwards();(!d||b.column!==0)&&this.setSelectionAnchor(b.row,b.column+a),(d||c.column!==0)&&this.$moveSelection(function(){this.moveCursorTo(c.row,c.column+a)})}},this.isBackwards=function(){var a=this.selectionAnchor,b=this.selectionLead;return a.row>b.row||a.row==b.row&&a.column>b.column},this.getRange=function(){var a=this.selectionAnchor,b=this.selectionLead;if(this.isEmpty())return g.fromPoints(b,b);return this.isBackwards()?g.fromPoints(b,a):g.fromPoints(a,b)},this.clearSelection=function(){this.$isEmpty||(this.$isEmpty=!0,this._dispatchEvent("changeSelection"))},this.selectAll=function(){var a=this.doc.getLength()-1;this.setSelectionAnchor(a,this.doc.getLine(a).length),this.moveCursorTo(0,0)},this.setSelectionRange=function(a,b){b?(this.setSelectionAnchor(a.end.row,a.end.column),this.selectTo(a.start.row,a.start.column)):(this.setSelectionAnchor(a.start.row,a.start.column),this.selectTo(a.end.row,a.end.column)),this.$updateDesiredColumn()},this.$updateDesiredColumn=function(){var a=this.getCursor();this.$desiredColumn=this.session.documentToScreenColumn(a.row,a.column)},this.$moveSelection=function(a){var b=this.selectionLead;this.$isEmpty&&this.setSelectionAnchor(b.row,b.column),a.call(this)},this.selectTo=function(a,b){this.$moveSelection(function(){this.moveCursorTo(a,b)})},this.selectToPosition=function(a){this.$moveSelection(function(){this.moveCursorToPosition(a)})},this.selectUp=function(){this.$moveSelection(this.moveCursorUp)},this.selectDown=function(){this.$moveSelection(this.moveCursorDown)},this.selectRight=function(){this.$moveSelection(this.moveCursorRight)},this.selectLeft=function(){this.$moveSelection(this.moveCursorLeft)},this.selectLineStart=function(){this.$moveSelection(this.moveCursorLineStart)},this.selectLineEnd=function(){this.$moveSelection(this.moveCursorLineEnd)},this.selectFileEnd=function(){this.$moveSelection(this.moveCursorFileEnd)},this.selectFileStart=function(){this.$moveSelection(this.moveCursorFileStart)},this.selectWordRight=function(){this.$moveSelection(this.moveCursorWordRight)},this.selectWordLeft=function(){this.$moveSelection(this.moveCursorWordLeft)},this.selectWord=function(){var a=this.getCursor(),b=this.session.getWordRange(a.row,a.column);this.setSelectionRange(b)},this.selectLine=function(){this.setSelectionAnchor(this.selectionLead.row,0),this.$moveSelection(function(){this.moveCursorTo(this.selectionLead.row+1,0)})},this.moveCursorUp=function(){this.moveCursorBy(-1,0)},this.moveCursorDown=function(){this.moveCursorBy(1,0)},this.moveCursorLeft=function(){var a=this.selectionLead.getPosition();if(a.column==0)a.row>0&&this.moveCursorTo(a.row-1,this.doc.getLine(a.row-1).length);else{var b=this.session.getTabSize();this.session.isTabStop(a)&&this.doc.getLine(a.row).slice(a.column-b,a.column).split(" ").length-1==b?this.moveCursorBy(0,-b):this.moveCursorBy(0,-1)}},this.moveCursorRight=function(){if(this.selectionLead.column==this.doc.getLine(this.selectionLead.row).length)this.selectionLead.row<this.doc.getLength()-1&&this.moveCursorTo(this.selectionLead.row+1,0);else{var a=this.session.getTabSize(),b=this.selectionLead;this.session.isTabStop(b)&&this.doc.getLine(b.row).slice(b.column,b.column+a).split(" ").length-1==a?this.moveCursorBy(0,a):this.moveCursorBy(0,1)}},this.moveCursorLineStart=function(){var a=this.selectionLead.row,b=this.selectionLead.column,c=this.session.documentToScreenRow(a,b),d=this.session.getScreenFirstRowColumn(c),e=this.doc.getLine(a).slice(d,b),f=e.match(/^\s*/);if(f[0].length==0){var g=this.session.getDocumentLastRowColumn(a,b);f=this.doc.getLine(a).substring(d,g).match(/^\s*/),this.moveCursorTo(a,d+f[0].length)}else f[0].length<b?this.moveCursorTo(a,d+f[0].length):this.moveCursorTo(a,d)},this.moveCursorLineEnd=function(){var a=this.selectionLead;this.moveCursorTo(a.row,this.session.getDocumentLastRowColumn(a.row,a.column))},this.moveCursorFileEnd=function(){var a=this.doc.getLength()-1,b=this.doc.getLine(a).length;this.moveCursorTo(a,b)},this.moveCursorFileStart=function(){this.moveCursorTo(0,0)},this.moveCursorWordRight=function(){var a=this.selectionLead.row,b=this.selectionLead.column,c=this.doc.getLine(a),d=c.substring(b),e;this.session.nonTokenRe.lastIndex=0,this.session.tokenRe.lastIndex=0;if(b==c.length)this.moveCursorRight();else{if(e=this.session.nonTokenRe.exec(d))b+=this.session.nonTokenRe.lastIndex,this.session.nonTokenRe.lastIndex=0;else if(e=this.session.tokenRe.exec(d))b+=this.session.tokenRe.lastIndex,this.session.tokenRe.lastIndex=0;this.moveCursorTo(a,b)}},this.moveCursorWordLeft=function(){var a=this.selectionLead.row,b=this.selectionLead.column,c=this.doc.getLine(a),d=e.stringReverse(c.substring(0,b)),f;this.session.nonTokenRe.lastIndex=0,this.session.tokenRe.lastIndex=0;if(b==0)this.moveCursorLeft();else{if(f=this.session.nonTokenRe.exec(d))b-=this.session.nonTokenRe.lastIndex,this.session.nonTokenRe.lastIndex=0;else if(f=this.session.tokenRe.exec(d))b-=this.session.tokenRe.lastIndex,this.session.tokenRe.lastIndex=0;this.moveCursorTo(a,b)}},this.moveCursorBy=function(a,b){if(this.session.getUseWrapMode()){var c=this.session.documentToScreenPosition(this.selectionLead.row,this.selectionLead.column),d=b==0&&this.$desiredColumn||c.column,e=this.session.screenToDocumentPosition(c.row+a,d);this.moveCursorTo(e.row,e.column+b,b==0)}else{var f=b==0&&this.$desiredColumn||this.selectionLead.column;this.moveCursorTo(this.selectionLead.row+a,f+b,b==0)}},this.moveCursorToPosition=function(a){this.moveCursorTo(a.row,a.column)},this.moveCursorTo=function(a,b,c){this.selectionLead.setPosition(a,b),c||this.$updateDesiredColumn(this.selectionLead.column)}}).call(i.prototype),b.Selection=i}),define("ace/range",function(a,b,c){var d=function(a,b,c,d){this.start={row:a,column:b},this.end={row:c,column:d}};(function(){this.toString=function(){return"Range: ["+this.start.row+"/"+this.start.column+"] -> ["+this.end.row+"/"+this.end.column+"]"},this.contains=function(a,b){return this.compare(a,b)==0},this.compare=function(a,b){if(!this.isMultiLine())if(a===this.start.row)return b<this.start.column?-1:b>this.end.column?1:0;if(a<this.start.row)return-1;if(a>this.end.row)return 1;if(this.start.row===a)return b>=this.start.column?0:-1;if(this.end.row===a)return b<=this.end.column?0:1;return 0},this.clipRows=function(a,b){if(this.end.row>b)var c={row:b+1,column:0};if(this.start.row>b)var e={row:b+1,column:0};if(this.start.row<a)var e={row:a,column:0};if(this.end.row<a)var c={row:a,column:0};return d.fromPoints(e||this.start,c||this.end)},this.extend=function(a,b){var c=this.compare(a,b);if(c==0)return this;if(c==-1)var e={row:a,column:b};else var f={row:a,column:b};return d.fromPoints(e||this.start,f||this.end)},this.isEmpty=function(){return this.start.row==this.end.row&&this.start.column==this.end.column},this.isMultiLine=function(){return this.start.row!==this.end.row},this.clone=function(){return d.fromPoints(this.start,this.end)},this.collapseRows=function(){return this.end.column==0?new d(this.start.row,0,Math.max(this.start.row,this.end.row-1),0):new d(this.start.row,0,this.end.row,0)},this.toScreenRange=function(a){var b=a.documentToScreenPosition(this.start),c=a.documentToScreenPosition(this.end);return new d(b.row,b.column,c.row,c.column)}}).call(d.prototype),d.fromPoints=function(a,b){return new d(a.row,a.column,b.row,b.column)},b.Range=d}),define("ace/anchor",function(a,b,c){var d=a("pilot/oop"),e=a("pilot/event_emitter").EventEmitter,f=b.Anchor=function(a,b,c){this.document=a,typeof c=="undefined"?this.setPosition(b.row,b.column):this.setPosition(b,c),this.$onChange=this.onChange.bind(this),a.on("change",this.$onChange)};(function(){d.implement(this,e),this.getPosition=function(){return this.$clipPositionToDocument(this.row,this.column)},this.getDocument=function(){return this.document},this.onChange=function(a){var b=a.data,c=b.range;if(c.start.row!=c.end.row||c.start.row==this.row){if(c.start.row>this.row)return;if(c.start.row==this.row&&c.start.column>this.column)return;var d=this.row,e=this.column;b.action==="insertText"?c.start.row!==d||c.start.column>e?c.start.row!==c.end.row&&c.start.row<d&&(d+=c.end.row-c.start.row):c.start.row===c.end.row?e+=c.end.column-c.start.column:(e-=c.start.column,d+=c.end.row-c.start.row):b.action==="insertLines"?c.start.row<=d&&(d+=c.end.row-c.start.row):b.action=="removeText"?c.start.row==d&&c.start.column<e?c.end.column<e?e=Math.max(0,e-(c.end.column-c.start.column)):e=c.start.column:c.start.row!==c.end.row&&c.start.row<d?(c.end.row==d&&(e=Math.max(0,e-c.end.column)+c.start.column),d-=c.end.row-c.start.row):c.end.row==d&&(d-=c.end.row-c.start.row,e=Math.max(0,e-c.end.column)+c.start.column):b.action=="removeLines"&&(c.start.row<=d&&(c.end.row>d?(d=c.start.row,e=0):d-=c.end.row-c.start.row)),this.setPosition(d,e)}},this.setPosition=function(a,b){pos=this.$clipPositionToDocument(a,b);if(this.row!=pos.row||this.column!=pos.column){var c={row:this.row,column:this.column};this.row=pos.row,this.column=pos.column,this._dispatchEvent("change",{old:c,value:pos})}},this.detach=function(){this.document.removeEventListener("change",this.$onChange)},this.$clipPositionToDocument=function(a,b){var c={};a<this.document.getLength()?a<0?(c.row=0,c.column=0):(c.row=a,c.column=Math.min(this.document.getLine(c.row).length,Math.max(0,b))):(c.row=Math.max(0,this.document.getLength()-1),c.column=this.document.getLine(c.row).length),b<0&&(c.column=0);return c}}).call(f.prototype)}),define("ace/mode/text",function(a,b,c){var d=a("ace/tokenizer").Tokenizer,e=a("ace/mode/text_highlight_rules").TextHighlightRules,f=function(){this.$tokenizer=new d((new e).getRules())};(function(){this.getTokenizer=function(){return this.$tokenizer},this.toggleCommentLines=function(a,b,c,d){},this.getNextLineIndent=function(a,b,c){return""},this.checkOutdent=function(a,b,c){return!1},this.autoOutdent=function(a,b,c){},this.$getIndent=function(a){var b=a.match(/^(\s+)/);if(b)return b[1];return""},this.createWorker=function(a){return null}}).call(f.prototype),b.Mode=f}),define("ace/tokenizer",function(a,b,c){var d=function(a){this.rules=a,this.regExps={};for(var b in this.rules){var c=this.rules[b],d=[];for(var e=0;e<c.length;e++)d.push(c[e].regex);this.regExps[b]=new RegExp("(?:("+d.join(")|(")+")|(.))","g")}};(function(){this.getLineTokens=function(a,b){var c=b,d=this.rules[c],e=this.regExps[c];e.lastIndex=0;var f,g=[],h=0,i={type:null,value:""};while(f=e.exec(a)){var j="text",k=f[0];for(var l=0;l<d.length;l++)if(f[l+1]){typeof d[l].token=="function"?j=d[l].token(f[0]):j=d[l].token;if(d[l].next&&d[l].next!==c){c=d[l].next;var d=this.rules[c],h=e.lastIndex,e=this.regExps[c];e.lastIndex=h}break}i.type!==j?(i.type&&g.push(i),i={type:j,value:k}):i.value+=k;if(h==a.length)break;h=e.lastIndex}i.type&&g.push(i);return{tokens:g,state:c}}}).call(d.prototype),b.Tokenizer=d}),define("ace/mode/text_highlight_rules",function(a,b,c){var d=function(){this.$rules={start:[{token:"empty_line",regex:"^$"},{token:"text",regex:".+"}]}};(function(){this.addRules=function(a,b){for(var c in a){var d=a[c];for(var e=0;e<d.length;e++){var f=d[e];f.next?f.next=b+f.next:f.next=b+c}this.$rules[b+c]=d}},this.getRules=function(){return this.$rules}}).call(d.prototype),b.TextHighlightRules=d}),define("ace/document",function(a,b,c){var d=a("pilot/oop"),e=a("pilot/event_emitter").EventEmitter,f=a("ace/range").Range,g=function(a){this.$lines=[],Array.isArray(a)?this.insertLines(0,a):a.length==0?this.$lines=[""]:this.insert({row:0,column:0},a)};(function(){d.implement(this,e),this.setValue=function(a){var b=this.getLength();this.remove(new f(0,0,b,this.getLine(b-1).length)),this.insert({row:0,column:0},a)},this.getValue=function(){return this.$lines.join(this.getNewLineCharacter())},"aaa".split(/a/).length==0?this.$split=function(a){return a.replace(/\r\n|\r/g,"\n").split("\n")}:this.$split=function(a){return a.split(/\r\n|\r|\n/)},this.$detectNewLine=function(a){var b=a.match(/^.*?(\r?\n)/m);b?this.$autoNewLine=b[1]:this.$autoNewLine="\n"},this.getNewLineCharacter=function(){switch(this.$newLineMode){case"windows":return"\r\n";case"unix":return"\n";case"auto":return this.$autoNewLine}},this.$autoNewLine="\n",this.$newLineMode="auto",this.setNewLineMode=function(a){this.$newLineMode!==a&&(this.$newLineMode=a)},this.getNewLineMode=function(){return this.$newLineMode},this.isNewLine=function(a){return a=="\r\n"||a=="\r"||a=="\n"},this.getLine=function(a){return this.$lines[a]||""},this.getLines=function(a,b){return this.$lines.slice(a,b+1)},this.getAllLines=function(){return this.$lines},this.getLength=function(){return this.$lines.length},this.getTextRange=function(a){if(a.start.row==a.end.row)return this.$lines[a.start.row].substring(a.start.column,a.end.column);var b=[];b.push(this.$lines[a.start.row].substring(a.start.column)),b.push.apply(b,this.getLines(a.start.row+1,a.end.row-1)),b.push(this.$lines[a.end.row].substring(0,a.end.column));return b.join(this.getNewLineCharacter())},this.$clipPosition=function(a){var b=this.getLength();a.row>=b&&(a.row=Math.max(0,b-1),a.column=this.getLine(b-1).length);return a},this.insert=function(a,b){if(b.length==0)return a;a=this.$clipPosition(a),this.getLength()<=1&&this.$detectNewLine(b);var c=this.$split(b);if(this.isNewLine(b))var d=this.insertNewLine(a);else if(c.length==1)var d=this.insertInLine(a,b);else{var d=this.insertInLine(a,c[0]);this.insertNewLine(d),c.length>2&&this.insertLines(a.row+1,c.slice(1,c.length-1));var d=this.insertInLine({row:a.row+c.length-1,column:0},c[c.length-1])}return d},this.insertLines=function(a,b){if(b.length==0)return{row:a,column:0};var c=[a,0];c.push.apply(c,b),this.$lines.splice.apply(this.$lines,c);var d=new f(a,0,a+b.length,0),e={action:"insertLines",range:d,lines:b};this._dispatchEvent("change",{data:e});return d.end},this.insertNewLine=function(a){a=this.$clipPosition(a);var b=this.$lines[a.row]||"";this.$lines[a.row]=b.substring(0,a.column),this.$lines.splice(a.row+1,0,b.substring(a.column,b.length));var c={row:a.row+1,column:0},d={action:"insertText",range:f.fromPoints(a,c),text:this.getNewLineCharacter()};this._dispatchEvent("change",{data:d});return c},this.insertInLine=function(a,b){if(b.length==0)return a;var c=this.$lines[a.row]||"";this.$lines[a.row]=c.substring(0,a.column)+b+c.substring(a.column);var d={row:a.row,column:a.column+b.length},e={action:"insertText",range:f.fromPoints(a,d),text:b};this._dispatchEvent("change",{data:e});return d},this.remove=function(a){a.start=this.$clipPosition(a.start),a.end=this.$clipPosition(a.end);if(a.isEmpty())return a.start;var b=a.start.row,c=a.end.row;if(a.isMultiLine()){var d=a.start.column==0?b:b+1,e=c-1;a.end.column>0&&this.removeInLine(c,0,a.end.column),e>=d&&this.removeLines(d,e),d!=b&&(this.removeInLine(b,a.start.column,this.$lines[b].length),this.removeNewLine(a.start.row))}else this.removeInLine(b,a.start.column,a.end.column);return a.start},this.removeInLine=function(a,b,c){if(b!=c){var d=new f(a,b,a,c),e=this.getLine(a),g=e.substring(b,c),h=e.substring(0,b)+e.substring(c,e.length);this.$lines.splice(a,1,h);var i={action:"removeText",range:d,text:g};this._dispatchEvent("change",{data:i});return d.start}},this.removeLines=function(a,b){var c=new f(a,0,b+1,0),d=this.$lines.splice(a,b-a+1),e={action:"removeLines",range:c,nl:this.getNewLineCharacter(),lines:d};this._dispatchEvent("change",{data:e});return d},this.removeNewLine=function(a){var b=this.getLine(a),c=this.getLine(a+1),d=new f(a,b.length,a+1,0),e=b+c;this.$lines.splice(a,2,e);var g={action:"removeText",range:d,text:this.getNewLineCharacter()};this._dispatchEvent("change",{data:g})},this.replace=function(a,b){if(b.length==0&&a.isEmpty())return a.start;if(b==this.getTextRange(a))return a.end;this.remove(a);if(b)var c=this.insert(a.start,b);else c=a.start;return c},this.applyDeltas=function(a){for(var b=0;b<a.length;b++){var c=a[b],d=f.fromPoints(c.range.start,c.range.end);c.action=="insertLines"?this.insertLines(d.start.row,c.lines):c.action=="insertText"?this.insert(d.start,c.text):c.action=="removeLines"?this.removeLines(d.start.row,d.end.row-1):c.action=="removeText"&&this.remove(d)}},this.revertDeltas=function(a){for(var b=a.length-1;b>=0;b--){var c=a[b],d=f.fromPoints(c.range.start,c.range.end);c.action=="insertLines"?this.removeLines(d.start.row,d.end.row-1):c.action=="insertText"?this.remove(d):c.action=="removeLines"?this.insertLines(d.start.row,c.lines):c.action=="removeText"&&this.insert(d.start,c.text)}}}).call(g.prototype),b.Document=g}),define("ace/search",function(a,b,c){var d=a("pilot/lang"),e=a("pilot/oop"),f=a("ace/range").Range,g=function(){this.$options={needle:"",backwards:!1,wrap:!1,caseSensitive:!1,wholeWord:!1,scope:g.ALL,regExp:!1}};g.ALL=1,g.SELECTION=2,function(){this.set=function(a){e.mixin(this.$options,a);return this},this.getOptions=function(){return d.copyObject(this.$options)},this.find=function(a){if(!this.$options.needle)return null;if(this.$options.backwards)var b=this.$backwardMatchIterator(a);else b=this.$forwardMatchIterator(a);var c=null;b.forEach(function(a){c=a;return!0});return c},this.findAll=function(a){if(!this.$options.needle)return[];if(this.$options.backwards)var b=this.$backwardMatchIterator(a);else b=this.$forwardMatchIterator(a);var c=[];b.forEach(function(a){c.push(a)});return c},this.replace=function(a,b){var c=this.$assembleRegExp(),d=c.exec(a);return d&&d[0].length==a.length?this.$options.regExp?a.replace(c,b):b:null},this.$forwardMatchIterator=function(a){var b=this.$assembleRegExp(),c=this;return{forEach:function(d){c.$forwardLineIterator(a).forEach(function(a,e,f){e&&(a=a.substring(e));var g=[];a.replace(b,function(a){var b=arguments[arguments.length-2];g.push({str:a,offset:e+b});return a});for(var h=0;h<g.length;h++){var i=g[h],j=c.$rangeFromMatch(f,i.offset,i.str.length);if(d(j))return!0}})}}},this.$backwardMatchIterator=function(a){var b=this.$assembleRegExp(),c=this;return{forEach:function(d){c.$backwardLineIterator(a).forEach(function(a,e,f){e&&(a=a.substring(e));var g=[];a.replace(b,function(a,b){g.push({str:a,offset:e+b});return a});for(var h=g.length-1;h>=0;h--){var i=g[h],j=c.$rangeFromMatch(f,i.offset,i.str.length);if(d(j))return!0}})}}},this.$rangeFromMatch=function(a,b,c){return new f(a,b,a,b+c)},this.$assembleRegExp=function(){if(this.$options.regExp)var a=this.$options.needle;else a=d.escapeRegExp(this.$options.needle);this.$options.wholeWord&&(a="\\b"+a+"\\b");var b="g";this.$options.caseSensitive||(b+="i");var c=new RegExp(a,b);return c},this.$forwardLineIterator=function(a){function j(d){var e=a.getLine(d);b&&d==c.end.row&&(e=e.substring(0,c.end.column));return e}var b=this.$options.scope==g.SELECTION,c=a.getSelection().getRange(),d=a.getSelection().getCursor(),e=b?c.start.row:0,f=b?c.start.column:0,h=b?c.end.row:a.getLength()-1,i=this.$options.wrap;return{forEach:function(a){var b=d.row,c=j(b),g=d.column,k=!1;while(!a(c,g,b)){if(k)return;b++,g=0;if(b>h)if(i)b=e,g=f;else return;b==d.row&&(k=!0),c=j(b)}}}},this.$backwardLineIterator=function(a){var b=this.$options.scope==g.SELECTION,c=a.getSelection().getRange(),d=b?c.end:c.start,e=b?c.start.row:0,f=b?c.start.column:0,h=b?c.end.row:a.getLength()-1,i=this.$options.wrap;return{forEach:function(g){var j=d.row,k=a.getLine(j).substring(0,d.column),l=0,m=!1;while(!g(k,l,j)){if(m)return;j--,l=0;if(j<e)if(i)j=h;else return;j==d.row&&(m=!0),k=a.getLine(j),b&&(j==e?l=f:j==h&&(k=k.substring(0,c.end.column)))}}}}}.call(g.prototype),b.Search=g}),define("ace/background_tokenizer",function(a,b,c){var d=a("pilot/oop"),e=a("pilot/event_emitter").EventEmitter,f=function(a,b){this.running=!1,this.lines=[],this.currentLine=0,this.tokenizer=a;var c=this;this.$worker=function(){if(c.running){var a=new Date,d=c.currentLine,e=c.doc,f=0,g=b.getLastVisibleRow(),h=e.getLength();while(c.currentLine<h){c.lines[c.currentLine]=c.$tokenizeRows(c.currentLine,c.currentLine)[0],c.currentLine++,f+=1;if(f%5==0&&new Date-a>20){c.fireUpdateEvent(d,c.currentLine-1);var i=c.currentLine<g?20:100;c.running=setTimeout(c.$worker,i);return}}c.running=!1,c.fireUpdateEvent(d,h-1)}}};(function(){d.implement(this,e),this.setTokenizer=function(a){this.tokenizer=a,this.lines=[],this.start(0)},this.setDocument=function(a){this.doc=a,this.lines=[],this.stop()},this.fireUpdateEvent=function(a,b){var c={first:a,last:b};this._dispatchEvent("update",{data:c})},this.start=function(a){this.currentLine=Math.min(a||0,this.currentLine,this.doc.getLength()),this.lines.splice(this.currentLine,this.lines.length),this.stop(),this.running=setTimeout(this.$worker,700)},this.stop=function(){this.running&&clearTimeout(this.running),this.running=!1},this.getTokens=function(a,b){return this.$tokenizeRows(a,b)},this.getState=function(a){return this.$tokenizeRows(a,a)[0].state},this.$tokenizeRows=function(a,b){if(!this.doc)return[];var c=[],d="start",e=!1;a>0&&this.lines[a-1]&&(d=this.lines[a-1].state,e=!0);var f=this.doc.getLines(a,b);for(var g=a;g<=b;g++)if(this.lines[g]){var h=this.lines[g];d=h.state,c.push(h)}else{var h=this.tokenizer.getLineTokens(f[g-a]||"",d),d=h.state;c.push(h),e&&(this.lines[g]=h)}return c}}).call(f.prototype),b.BackgroundTokenizer=f}),define("ace/undomanager",function(a,b,c){var d=function(){this.$undoStack=[],this.$redoStack=[]};(function(){this.execute=function(a){var b=a.args[0];this.$doc=a.args[1],this.$undoStack.push(b)},this.undo=function(){var a=this.$undoStack.pop();a&&(this.$doc.undoChanges(a),this.$redoStack.push(a))},this.redo=function(){var a=this.$redoStack.pop();a&&(this.$doc.redoChanges(a),this.$undoStack.push(a))}}).call(d.prototype),b.UndoManager=d}),define("ace/theme/textmate",function(a,b,c){var d=a("pilot/dom"),e=a("text!ace/theme/tm.css");d.importCssString(e),b.cssClass="ace-tm"}),define("ace/mode/matching_brace_outdent",function(a,b,c){var d=a("ace/range").Range,e=function(){};(function(){this.checkOutdent=function(a,b){if(!/^\s+$/.test(a))return!1;return/^\s*\}/.test(b)},this.autoOutdent=function(a,b){var c=a.getLine(b),e=c.match(/^(\s*\})/);if(!e)return 0;var f=e[1].length,g=a.findMatchingBracket({row:b,column:f});if(!g||g.row==b)return 0;var h=this.$getIndent(a.getLine(g.row));a.replace(new d(b,0,b,f-1),h)},this.$getIndent=function(a){var b=a.match(/^(\s+)/);if(b)return b[1];return""}}).call(e.prototype),b.MatchingBraceOutdent=e}),define("ace/virtual_renderer",function(a,b,c){var d=a("pilot/oop"),e=a("pilot/dom"),f=a("pilot/event"),g=a("pilot/useragent"),h=a("ace/layer/gutter").Gutter,i=a("ace/layer/marker").Marker,j=a("ace/layer/text").Text,k=a("ace/layer/cursor").Cursor,l=a("ace/scrollbar").ScrollBar,m=a("ace/renderloop").RenderLoop,n=a("pilot/event_emitter").EventEmitter,o=a("text!ace/css/editor.css");e.importCssString(o);var p=function(a,b){this.container=a,e.addCssClass(this.container,"ace_editor"),this.setTheme(b),this.$gutter=document.createElement("div"),this.$gutter.className="ace_gutter",this.container.appendChild(this.$gutter),this.scroller=document.createElement("div"),this.scroller.className="ace_scroller",this.container.appendChild(this.scroller),this.content=document.createElement("div"),this.content.className="ace_content",this.scroller.appendChild(this.content),this.$gutterLayer=new h(this.$gutter),this.$markerBack=new i(this.content);var c=this.$textLayer=new j(this.content);this.canvas=c.element,this.$markerFront=new i(this.content),this.characterWidth=c.getCharacterWidth(),this.lineHeight=c.getLineHeight(),this.$cursorLayer=new k(this.content),this.$cursorPadding=8,this.scrollBar=new l(a),this.scrollBar.addEventListener("scroll",this.onScroll.bind(this)),this.scrollTop=0,this.cursorPos={row:0,column:0};var d=this;this.$textLayer.addEventListener("changeCharaterSize",function(){d.characterWidth=c.getCharacterWidth(),d.lineHeight=c.getLineHeight(),d.$updatePrintMargin(),d.$loop.schedule(d.CHANGE_FULL)}),f.addListener(this.$gutter,"click",this.$onGutterClick.bind(this)),f.addListener(this.$gutter,"dblclick",this.$onGutterClick.bind(this)),this.$size={width:0,height:0,scrollerHeight:0,scrollerWidth:0},this.$loop=new m(this.$renderChanges.bind(this)),this.$loop.schedule(this.CHANGE_FULL),this.setPadding(4),this.$updatePrintMargin()};(function(){this.showGutter=!0,this.CHANGE_CURSOR=1,this.CHANGE_MARKER=2,this.CHANGE_GUTTER=4,this.CHANGE_SCROLL=8,this.CHANGE_LINES=16,this.CHANGE_TEXT=32,this.CHANGE_SIZE=64,this.CHANGE_MARKER_BACK=128,this.CHANGE_MARKER_FRONT=256,this.CHANGE_FULL=512,d.implement(this,n),this.setSession=function(a){this.session=a,this.$cursorLayer.setSession(a),this.$markerBack.setSession(a),this.$markerFront.setSession(a),this.$gutterLayer.setSession(a),this.$textLayer.setSession(a),this.$loop.schedule(this.CHANGE_FULL)},this.updateLines=function(a,b){b===undefined&&(b=Infinity),this.$changedLines?(this.$changedLines.firstRow>a&&(this.$changedLines.firstRow=a),this.$changedLines.lastRow<b&&(this.$changedLines.lastRow=b)):this.$changedLines={firstRow:a,lastRow:b},this.$loop.schedule(this.CHANGE_LINES)},this.updateText=function(){this.$loop.schedule(this.CHANGE_TEXT)},this.updateFull=function(){this.$loop.schedule(this.CHANGE_FULL)},this.onResize=function(a){var b=this.CHANGE_SIZE,c=e.getInnerHeight(this.container);if(a||this.$size.height!=c)this.$size.height=c,this.scroller.style.height=c+"px",this.scrollBar.setHeight(c),this.session&&(this.scrollToY(this.getScrollTop()),b=b|this.CHANGE_FULL);var d=e.getInnerWidth(this.container);if(a||this.$size.width!=d){this.$size.width=d;var f=this.showGutter?this.$gutter.offsetWidth:0;this.scroller.style.left=f+"px",this.scroller.style.width=Math.max(0,d-f-this.scrollBar.getWidth())+"px";if(this.session.getUseWrapMode()){var g=this.scroller.clientWidth-this.$padding*2,h=Math.floor(g/this.characterWidth)-1;if(this.session.adjustWrapLimit(h)||a)b=b|this.CHANGE_FULL}}this.$size.scrollerWidth=this.scroller.clientWidth,this.$size.scrollerHeight=this.scroller.clientHeight,this.$loop.schedule(b)},this.setTokenizer=function(a){this.$tokenizer=a,this.$textLayer.setTokenizer(a),this.$loop.schedule(this.CHANGE_TEXT)},this.$onGutterClick=function(a){var b=f.getDocumentX(a),c=f.getDocumentY(a);this._dispatchEvent("gutter"+a.type,{row:this.screenToTextCoordinates(b,c).row,htmlEvent:a})},this.setShowInvisibles=function(a){this.$textLayer.setShowInvisibles(a)&&this.$loop.schedule(this.CHANGE_TEXT)},this.getShowInvisibles=function(){return this.$textLayer.showInvisibles},this.$showPrintMargin=!0,this.setShowPrintMargin=function(a){this.$showPrintMargin=a,this.$updatePrintMargin()},this.getShowPrintMargin=function(){return this.$showPrintMargin},this.$printMarginColumn=80,this.setPrintMarginColumn=function(a){this.$printMarginColumn=a,this.$updatePrintMargin()},this.getPrintMarginColumn=function(){return this.$printMarginColumn},this.setShowGutter=function(a){this.showGutter!==a&&(this.$gutter.style.display=a?"block":"none",this.showGutter=a,this.onResize(!0))},this.$updatePrintMargin=function(){var a;if(this.$showPrintMargin||this.$printMarginEl){this.$printMarginEl||(a=document.createElement("div"),a.className="ace_print_margin_layer",this.$printMarginEl=document.createElement("div"),this.$printMarginEl.className="ace_print_margin",a.appendChild(this.$printMarginEl),this.content.insertBefore(a,this.$textLayer.element));var b=this.$printMarginEl.style;b.left=this.characterWidth*this.$printMarginColumn+this.$padding*2+"px",b.visibility=this.$showPrintMargin?"visible":"hidden"}},this.getContainerElement=function(){return this.container},this.getMouseEventTarget=function(){return this.content},this.getTextAreaContainer=function(){return this.container},this.moveTextAreaToCursor=function(a){if(!g.isIE){var b=this.$cursorLayer.getPixelPosition();if(!b)return;var c=this.content.getBoundingClientRect(),d=this.layerConfig&&this.layerConfig.offset||0;a.style.left=c.left+b.left+this.$padding+"px",a.style.top=c.top+b.top-this.scrollTop+d+"px"}},this.getFirstVisibleRow=function(){return(this.layerConfig||{}).firstRow||0},this.getFirstFullyVisibleRow=function(){if(!this.layerConfig)return 0;return this.layerConfig.firstRow+(this.layerConfig.offset==0?0:1)},this.getLastFullyVisibleRow=function(){if(!this.layerConfig)return 0;var a=Math.floor((this.layerConfig.height+this.layerConfig.offset)/this.layerConfig.lineHeight);return this.layerConfig.firstRow-1+a},this.getLastVisibleRow=function(){return(this.layerConfig||{}).lastRow||0},this.$padding=null,this.setPadding=function(a){this.$padding=a,this.content.style.padding="0 "+a+"px",this.$loop.schedule(this.CHANGE_FULL),this.$updatePrintMargin()},this.onScroll=function(a){this.scrollToY(a.data)},this.$updateScrollBar=function(){this.scrollBar.setInnerHeight(this.session.getScreenLength()*this.lineHeight),this.scrollBar.setScrollTop(this.scrollTop)},this.$renderChanges=function(a){if(a&&this.session&&this.$tokenizer){(!this.layerConfig||a&this.CHANGE_FULL||a&this.CHANGE_SIZE||a&this.CHANGE_TEXT||a&this.CHANGE_LINES||a&this.CHANGE_SCROLL)&&this.$computeLayerConfig();if(a&this.CHANGE_FULL){this.$textLayer.update(this.layerConfig),this.showGutter&&this.$gutterLayer.update(this.layerConfig),this.$markerBack.update(this.layerConfig),this.$markerFront.update(this.layerConfig),this.$cursorLayer.update(this.layerConfig),this.$updateScrollBar(),this.scrollCursorIntoView();return}if(a&this.CHANGE_SCROLL){a&this.CHANGE_TEXT||a&this.CHANGE_LINES?this.$textLayer.update(this.layerConfig):this.$textLayer.scrollLines(this.layerConfig),this.showGutter&&this.$gutterLayer.update(this.layerConfig),this.$markerBack.update(this.layerConfig),this.$markerFront.update(this.layerConfig),this.$cursorLayer.update(this.layerConfig),this.$updateScrollBar();return}a&this.CHANGE_TEXT?(this.$textLayer.update(this.layerConfig),this.showGutter&&this.$gutterLayer.update(this.layerConfig)):a&this.CHANGE_LINES?(this.$updateLines(),this.$updateScrollBar(),this.showGutter&&this.$gutterLayer.update(this.layerConfig)):a&this.CHANGE_GUTTER&&(this.showGutter&&this.$gutterLayer.update(this.layerConfig)),a&this.CHANGE_CURSOR&&this.$cursorLayer.update(this.layerConfig),a&(this.CHANGE_MARKER|this.CHANGE_MARKER_FRONT)&&this.$markerFront.update(this.layerConfig),a&(this.CHANGE_MARKER|this.CHANGE_MARKER_BACK)&&this.$markerBack.update(this.layerConfig),a&this.CHANGE_SIZE&&this.$updateScrollBar()}},this.$computeLayerConfig=function(){var a=this.session,b=this.scrollTop%this.lineHeight,c=this.$size.scrollerHeight+this.lineHeight,d=this.$getLongestLine(),e=this.layerConfig?this.layerConfig.width!=d:!0,f=Math.ceil(c/this.lineHeight)-1,g=Math.max(0,Math.round((this.scrollTop-b)/this.lineHeight)),h=g+f,i,j,k={lineHeight:this.lineHeight};g=a.screenToDocumentRow(g),i=a.documentToScreenRow(g),j=a.getRowHeight(k,g),h=Math.min(a.screenToDocumentRow(h),a.getLength()-1),c=this.$size.scrollerHeight+a.getRowHeight(k,h)+j,b=this.scrollTop-i*this.lineHeight;var l=this.layerConfig={width:d,padding:this.$padding,firstRow:g,firstRowScreen:i,lastRow:h,lineHeight:this.lineHeight,characterWidth:this.characterWidth,minHeight:c,offset:b,height:this.$size.scrollerHeight};this.$gutterLayer.element.style.marginTop=-b+"px",this.content.style.marginTop=-b+"px",this.content.style.width=d+"px",this.content.style.height=c+"px"},this.$updateLines=function(){var a=this.$changedLines.firstRow,b=this.$changedLines.lastRow;this.$changedLines=null;var c=this.layerConfig;if(c.width!=this.$getLongestLine())return this.$textLayer.update(c);if(a<=c.lastRow+1){if(b<c.firstRow)return;if(b===Infinity){this.showGutter&&this.$gutterLayer.update(c),this.$textLayer.update(c);return}this.$textLayer.updateLines(c,a,b)}},this.$getLongestLine=function(){var a=this.session.getScreenWidth()+1;this.$textLayer.showInvisibles&&(a+=1);return Math.max(this.$size.scrollerWidth-this.$padding*2,Math.round(a*this.characterWidth))},this.updateFrontMarkers=function(){this.$markerFront.setMarkers(this.session.getMarkers(!0)),this.$loop.schedule(this.CHANGE_MARKER_FRONT)},this.updateBackMarkers=function(){this.$markerBack.setMarkers(this.session.getMarkers()),this.$loop.schedule(this.CHANGE_MARKER_BACK)},this.addGutterDecoration=function(a,b){this.$gutterLayer.addGutterDecoration(a,b),this.$loop.schedule(this.CHANGE_GUTTER)},this.removeGutterDecoration=function(a,b){this.$gutterLayer.removeGutterDecoration(a,b),this.$loop.schedule(this.CHANGE_GUTTER)},this.setBreakpoints=function(a){this.$gutterLayer.setBreakpoints(a),this.$loop.schedule(this.CHANGE_GUTTER)},this.setAnnotations=function(a){this.$gutterLayer.setAnnotations(a),this.$loop.schedule(this.CHANGE_GUTTER)},this.updateCursor=function(a,b){this.$cursorLayer.setCursor(a,b),this.$loop.schedule(this.CHANGE_CURSOR)},this.hideCursor=function(){this.$cursorLayer.hideCursor()},this.showCursor=function(){this.$cursorLayer.showCursor()},this.scrollCursorIntoView=function(){var a=this.$cursorLayer.getPixelPosition(),b=a.left+this.$padding,c=a.top;this.getScrollTop()>c&&this.scrollToY(c),this.getScrollTop()+this.$size.scrollerHeight<c+this.lineHeight&&this.scrollToY(c+this.lineHeight-this.$size.scrollerHeight),this.scroller.scrollLeft>b&&this.scrollToX(b),this.scroller.scrollLeft+this.$size.scrollerWidth<b+this.characterWidth&&(b+this.characterWidth>this.scroller.scrollWidth&&this.$renderChanges(this.CHANGE_SIZE),this.scrollToX(Math.round(b+this.characterWidth-this.$size.scrollerWidth)))},this.getScrollTop=function(){return this.scrollTop},this.getScrollLeft=function(){return this.scroller.scrollLeft},this.getScrollTopRow=function(){return this.scrollTop/this.lineHeight},this.scrollToRow=function(a){this.scrollToY(a*this.lineHeight)},this.scrollToLine=function(a,b){var c={lineHeight:this.lineHeight},d=0;for(var e=1;e<a;e++)d+=this.session.getRowHeight(c,e-1);b&&(d-=this.$size.scrollerHeight/2),this.scrollToY(d)},this.scrollToY=function(a){var b=this.session.getScreenLength()*this.lineHeight-this.$size.scrollerHeight,a=Math.max(0,Math.min(b,a));this.scrollTop!==a&&(this.scrollTop=a,this.$loop.schedule(this.CHANGE_SCROLL))},this.scrollToX=function(a){a<=this.$padding&&(a=0),this.scroller.scrollLeft=a},this.scrollBy=function(a,b){b&&this.scrollToY(this.scrollTop+b),a&&this.scrollToX(this.scroller.scrollLeft+a)},this.screenToTextCoordinates=function(a,b){var c=this.scroller.getBoundingClientRect(),d=Math.round((a+this.scroller.scrollLeft-c.left-this.$padding-e.getPageScrollLeft())/this.characterWidth),f=Math.floor((b+this.scrollTop-c.top-e.getPageScrollTop())/this.lineHeight);return this.session.screenToDocumentPosition(f,Math.max(d,0))},this.textToScreenCoordinates=function(a,b){var c=this.scroller.getBoundingClientRect(),d=this.session.documentToScreenPosition(a,b),e=this.$padding+Math.round(d.column*this.characterWidth),f=d.row*this.lineHeight;return{pageX:c.left+e-this.getScrollLeft(),pageY:c.top+f-this.getScrollTop()}},this.visualizeFocus=function(){e.addCssClass(this.container,"ace_focus")},this.visualizeBlur=function(){e.removeCssClass(this.container,"ace_focus")},this.showComposition=function(a){this.$composition||(this.$composition=document.createElement("div"),this.$composition.className="ace_composition",this.content.appendChild(this.$composition)),this.$composition.innerHTML="&nbsp;";var b=this.$cursorLayer.getPixelPosition(),c=this.$composition.style;c.top=b.top+"px",c.left=b.left+this.$padding+"px",c.height=this.lineHeight+"px",this.hideCursor()},this.setCompositionText=function(a){e.setInnerText(this.$composition,a)},this.hideComposition=function(){this.showCursor();if(this.$composition){var a=this.$composition.style;a.top="-10000px",a.left="-10000px"}},this.setTheme=function(b){function d(a){c.$theme&&e.removeCssClass(c.container,c.$theme),c.$theme=a?a.cssClass:null,c.$theme&&e.addCssClass(c.container,c.$theme),c.$size&&(c.$size.width=0,c.onResize())}var c=this;b&&typeof b!="string"?d(b):(b=b||"ace/theme/textmate",a([b],function(a){d(a)}));var c=this},this.setStyle=function b(a){e.addCssClass(this.container,a)},this.unsetStyle=function c(a){e.removeCssClass(this.container,a)}}).call(p.prototype),b.VirtualRenderer=p}),define("ace/layer/gutter",function(a,b,c){var d=a("pilot/dom"),e=function(a){this.element=document.createElement("div"),this.element.className="ace_layer ace_gutter-layer",a.appendChild(this.element),this.$breakpoints=[],this.$annotations=[],this.$decorations=[]};(function(){this.setSession=function(a){this.session=a},this.addGutterDecoration=function(a,b){this.$decorations[a]||(this.$decorations[a]=""),this.$decorations[a]+=" ace_"+b},this.removeGutterDecoration=function(a,b){this.$decorations[a]=this.$decorations[a].replace(" ace_"+b,"")},this.setBreakpoints=function(a){this.$breakpoints=a.concat()},this.setAnnotations=function(a){this.$annotations=[];for(var b in a)if(a.hasOwnProperty(b)){var c=a[b];if(!c)continue;var d=this.$annotations[b]={text:[]};for(var e=0;e<c.length;e++){var f=c[e];d.text.push(f.text.replace(/"/g,"&quot;").replace(/'/g,"&rsquo;").replace(/</,"&lt;"));var g=f.type;g=="error"?d.className="ace_error":g=="warning"&&d.className!="ace_error"?d.className="ace_warning":g=="info"&&!d.className&&(d.className="ace_info")}}},this.update=function(a){this.$config=a;var b=[];for(var c=a.firstRow;c<=a.lastRow;c++){var e=this.$annotations[c]||{className:"",text:[]};b.push("<div class='ace_gutter-cell",this.$decorations[c]||"",this.$breakpoints[c]?" ace_breakpoint ":" ",e.className,"' title='",e.text.join("\n"),"' style='height:",this.session.getRowHeight(a,c),"px;'>",c+1,"</div>"),b.push("</div>")}this.element=d.setInnerHtml(this.element,b.join("")),this.element.style.height=a.minHeight+"px"}}).call(e.prototype),b.Gutter=e}),define("ace/layer/marker",function(a,b,c){var d=a("ace/range").Range,e=a("pilot/dom"),f=function(a){this.element=document.createElement("div"),this.element.className="ace_layer ace_marker-layer",a.appendChild(this.element)};(function(){this.setSession=function(a){this.session=a},this.setMarkers=function(a){this.markers=a},this.update=function(a){var a=a||this.config;if(a){this.config=a;var b=[];for(var c in this.markers){var d=this.markers[c],f=d.range.clipRows(a.firstRow,a.lastRow);if(f.isEmpty())continue;f=f.toScreenRange(this.session);if(d.renderer){var g=this.$getTop(f.start.row,a),h=Math.round(f.start.column*a.characterWidth);d.renderer(b,f,h,g,a)}else f.isMultiLine()?d.type=="text"?this.drawTextMarker(b,f,d.clazz,a):this.drawMultiLineMarker(b,f,d.clazz,a):this.drawSingleLineMarker(b,f,d.clazz,a)}this.element=e.setInnerHtml(this.element,b.join(""))}},this.$getTop=function(a,b){return(a-b.firstRowScreen)*b.lineHeight},this.drawTextMarker=function(a,b,c,e){var f=b.start.row,g=new d(f,b.start.column,f,this.session.getScreenLastRowColumn(f));this.drawSingleLineMarker(a,g,c,e,1);var f=b.end.row,g=new d(f,0,f,b.end.column);this.drawSingleLineMarker(a,g,c,e);for(var f=b.start.row+1;f<b.end.row;f++)g.start.row=f,g.end.row=f,g.end.column=this.session.getScreenLastRowColumn(f),this.drawSingleLineMarker(a,g,c,e,1)},this.drawMultiLineMarker=function(a,b,c,d){var e=d.lineHeight,f=Math.round(d.width-b.start.column*d.characterWidth),g=this.$getTop(b.start.row,d),h=Math.round(b.start.column*d.characterWidth);a.push("<div class='",c,"' style='","height:",e,"px;","width:",f,"px;","top:",g,"px;","left:",h,"px;'></div>");var g=this.$getTop(b.end.row,d),f=Math.round(b.end.column*d.characterWidth);a.push("<div class='",c,"' style='","height:",e,"px;","top:",g,"px;","width:",f,"px;'></div>");var e=(b.end.row-b.start.row-1)*d.lineHeight;if(e>=0){var g=this.$getTop(b.start.row+1,d);a.push("<div class='",c,"' style='","height:",e,"px;","width:",d.width,"px;","top:",g,"px;'></div>")}},this.drawSingleLineMarker=function(a,b,c,d,e){var f=d.lineHeight,g=Math.round((b.end.column+(e||0)-b.start.column)*d.characterWidth),h=this.$getTop(b.start.row,d),i=Math.round(b.start.column*d.characterWidth);a.push("<div class='",c,"' style='","height:",f,"px;","width:",g,"px;","top:",h,"px;","left:",i,"px;'></div>")}}).call(f.prototype),b.Marker=f}),define("ace/layer/text",function(a,b,c){var d=a("pilot/oop"),e=a("pilot/dom"),f=a("pilot/lang"),g=a("pilot/event_emitter").EventEmitter,h=function(a){this.element=document.createElement("div"),this.element.className="ace_layer ace_text-layer",a.appendChild(this.element),this.$characterSize=this.$measureSizes(),this.$pollSizeChanges()};(function(){d.implement(this,g),this.EOF_CHAR="&para;",this.EOL_CHAR="&not;",this.TAB_CHAR="&rarr;",this.SPACE_CHAR="&middot;",this.setTokenizer=function(a){this.tokenizer=a},this.getLineHeight=function(){return this.$characterSize.height||1},this.getCharacterWidth=function(){return this.$characterSize.width||1},this.$pollSizeChanges=function(){var a=this;setInterval(function(){var b=a.$measureSizes();if(a.$characterSize.width!==b.width||a.$characterSize.height!==b.height)a.$characterSize=b,a._dispatchEvent("changeCharaterSize",{data:b})},500)},this.$fontStyles={fontFamily:1,fontSize:1,fontWeight:1,fontStyle:1,lineHeight:1},this.$measureSizes=function(){var a=1e3;if(!this.$measureNode){var b=this.$measureNode=document.createElement("div"),c=b.style;c.width=c.height="auto",c.left=c.top=-a*40+"px",c.visibility="hidden",c.position="absolute",c.overflow="visible",c.whiteSpace="nowrap",b.innerHTML=f.stringRepeat("Xy",a),document.body.insertBefore(b,document.body.firstChild)}var c=this.$measureNode.style;for(var d in this.$fontStyles){var g=e.computedStyle(this.element,d);c[d]=g}var h={height:this.$measureNode.offsetHeight,width:this.$measureNode.offsetWidth/(a*2)};return h},this.setSession=function(a){this.session=a},this.showInvisibles=!1,this.setShowInvisibles=function(a){if(this.showInvisibles==a)return!1;this.showInvisibles=a;return!0},this.$computeTabString=function(){var a=this.session.getTabSize();if(this.showInvisibles){var b=a/2;this.$tabString="<span class='ace_invisible'>"+Array(Math.floor(b)).join("&nbsp;")+this.TAB_CHAR+Array(Math.ceil(b)+1).join("&nbsp;")+"</span>"}else this.$tabString=Array(a+1).join("&nbsp;")},this.updateLines=function(a,b,c){this.$computeTabString(),(this.config.lastRow!=a.lastRow||this.config.firstRow!=a.firstRow)&&this.scrollLines(a),this.config=a;var d=Math.max(b,a.firstRow),f=Math.min(c,a.lastRow),g=this.element.childNodes,h=this.tokenizer.getTokens(d,f);for(var i=d;i<=f;i++){var j=g[i-a.firstRow];if(!j)continue;var k=[];this.$renderLine(k,i,h[i-d].tokens),j=e.setInnerHtml(j,k.join("")),j.style.height=this.session.getRowHeight(a,i)+"px"}},this.scrollLines=function(a){this.$computeTabString();var b=this.config;this.config=a;if(!b||b.lastRow<a.firstRow)return this.update(a);if(a.lastRow<b.firstRow)return this.update(a);var c=this.element;if(b.firstRow<a.firstRow)for(var d=b.firstRow;d<a.firstRow;d++)c.removeChild(c.firstChild);if(b.lastRow>a.lastRow)for(var d=a.lastRow+1;d<=b.lastRow;d++)c.removeChild(c.lastChild);if(a.firstRow<b.firstRow){var e=this.$renderLinesFragment(a,a.firstRow,b.firstRow-1);c.firstChild?c.insertBefore(e,c.firstChild):c.appendChild(e)}if(a.lastRow>b.lastRow){var e=this.$renderLinesFragment(a,b.lastRow+1,a.lastRow);c.appendChild(e)}},this.$renderLinesFragment=function(a,b,c){var d=document.createDocumentFragment(),e=this.tokenizer.getTokens(b,c);for(var f=b;f<=c;f++){var g=document.createElement("div");g.className="ace_line";var h=g.style;h.height=this.session.getRowHeight(a,f)+"px",h.width=a.width+"px";var i=[];e.length>f-b&&this.$renderLine(i,f,e[f-b].tokens),g.innerHTML=i.join(""),d.appendChild(g)}return d},this.update=function(a){this.$computeTabString(),this.config=a;var b=[],c=this.tokenizer.getTokens(a.firstRow,a.lastRow),d=this.$renderLinesFragment(a,a.firstRow,a.lastRow);this.element.innerHTML="",this.element.appendChild(d)},this.$textToken={text:!0,rparen:!0,lparen:!0},this.$renderLine=function(a,b,c){function i(b,c){var d=c.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(e,f).replace(/\t/g,g.$tabString).replace(/[\u3040-\u309F]|[\u30A0-\u30FF]|[\u4E00-\u9FFF\uF900-\uFAFF\u3400-\u4DBF]/g,function(a){return"<span class='ace_cjk' style='width:"+h*2+"px'>"+a+"</span>"});if(g.$textToken[b.type])a.push(d);else{var i="ace_"+b.type.replace(/\./g," ace_");a.push("<span class='",i,"'>",d,"</span>")}}if(this.showInvisibles)var d=this,e=/( +)|([\v\f \u00a0\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u200b\u2028\u2029\u3000])/g,f=function(a){if(a.charCodeAt(0)==32)return Array(a.length+1).join("&nbsp;");var a=Array(a.length+1).join(d.SPACE_CHAR);return"<span class='ace_invisible'>"+a+"</span>"};else var e=/[\v\f \u00a0\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u200b\u2028\u2029\u3000]/g,f="&nbsp;";var g=this,h=this.config.characterWidth,j=this.session.getRowSplitData(b),k=0,l=0,m;j&&j.length!=0?m=j[0]:m=Number.MAX_VALUE,a.push("<div style='height:",this.config.lineHeight,"px","'>");for(var n=0;n<c.length;n++){var o=c[n],p=o.value;if(k+p.length<m)i(o,p),k+=p.length;else{while(k+p.length>=m)i(o,p.substring(0,m-k)),p=p.substring(m-k),k=m,a.push("</div>","<div style='height:",this.config.lineHeight,"px","'>"),l++,m=j[l]||Number.MAX_VALUE;p.length!=0&&(k+=p.length,i(o,p))}}this.showInvisibles&&(b!==this.session.getLength()-1?a.push("<span class='ace_invisible'>"+this.EOL_CHAR+"</span>"):a.push("<span class='ace_invisible'>"+this.EOF_CHAR+"</span>")),a.push("</div>")}}).call(h.prototype),b.Text=h}),define("ace/layer/cursor",function(a,b,c){var d=a("pilot/dom"),e=function(a){this.element=document.createElement("div"),this.element.className="ace_layer ace_cursor-layer",a.appendChild(this.element),this.cursor=document.createElement("div"),this.cursor.className="ace_cursor",this.isVisible=!1};(function(){this.setSession=function(a){this.session=a},this.setCursor=function(a,b){this.position=this.session.documentToScreenPosition(a),b?d.addCssClass(this.cursor,"ace_overwrite"):d.removeCssClass(this.cursor,"ace_overwrite")},this.hideCursor=function(){this.isVisible=!1,this.cursor.parentNode&&this.cursor.parentNode.removeChild(this.cursor),clearInterval(this.blinkId)},this.showCursor=function(){this.isVisible=!0,this.element.appendChild(this.cursor);var a=this.cursor;a.style.visibility="visible",this.restartTimer()},this.restartTimer=function(){clearInterval(this.blinkId);if(this.isVisible){var a=this.cursor;this.blinkId=setInterval(function(){a.style.visibility="hidden",setTimeout(function(){a.style.visibility="visible"},400)},1e3)}},this.getPixelPosition=function(a){if(!this.config||!this.position)return{left:0,top:0};var b=this.position,c=Math.round(b.column*this.config.characterWidth),d=(b.row-(a?this.config.firstRowScreen:0))*this.config.lineHeight;return{left:c,top:d}},this.update=function(a){this.position&&(this.config=a,this.pixelPos=this.getPixelPosition(!0),this.cursor.style.left=this.pixelPos.left+"px",this.cursor.style.top=this.pixelPos.top+"px",this.cursor.style.width=a.characterWidth+"px",this.cursor.style.height=a.lineHeight+"px",this.isVisible&&this.element.appendChild(this.cursor),this.restartTimer())}}).call(e.prototype),b.Cursor=e}),define("ace/scrollbar",function(a,b,c){var d=a("pilot/oop"),e=a("pilot/dom"),f=a("pilot/event"),g=a("pilot/event_emitter").EventEmitter,h=function(a){this.element=document.createElement("div"),this.element.className="ace_sb",this.inner=document.createElement("div"),this.element.appendChild(this.inner),a.appendChild(this.element),this.width=e.scrollbarWidth(),this.element.style.width=this.width,f.addListener(this.element,"scroll",this.onScroll.bind(this))};(function(){d.implement(this,g),this.onScroll=function(){this._dispatchEvent("scroll",{data:this.element.scrollTop})},this.getWidth=function(){return this.width},this.setHeight=function(a){this.element.style.height=Math.max(0,a-this.width)+"px"},this.setInnerHeight=function(a){this.inner.style.height=a+"px"},this.setScrollTop=function(a){this.element.scrollTop=a}}).call(h.prototype),b.ScrollBar=h}),define("ace/renderloop",function(a,b,c){var d=a("pilot/event"),e=function(a){this.onRender=a,this.pending=!1,this.changes=0};(function(){this.schedule=function(a){this.changes=this.changes|a;if(!this.pending){this.pending=!0;var b=this;this.setTimeoutZero(function(){b.pending=!1;var a=b.changes;b.changes=0,b.onRender(a)})}},window.postMessage?(this.messageName="zero-timeout-message",this.setTimeoutZero=function(a){if(!this.attached){var b=this;d.addListener(window,"message",function(a){b.callback&&a.data==b.messageName&&(d.stopPropagation(a),b.callback())}),this.attached=!0}this.callback=a,window.postMessage(this.messageName,"*")}):this.setTimeoutZero=function(a){setTimeout(a,0)}}).call(e.prototype),b.RenderLoop=e}),define("text!ace/css/editor.css",'.ace_editor {    position: absolute;    overflow: hidden;    font-family: "Menlo", "Monaco", "Courier New", monospace;    font-size: 12px;  }.ace_scroller {    position: absolute;    overflow-x: scroll;    overflow-y: hidden;     }.ace_content {    position: absolute;    box-sizing: border-box;    -moz-box-sizing: border-box;    -webkit-box-sizing: border-box;}.ace_composition {    position: absolute;    background: #555;    color: #DDD;    z-index: 4;}.ace_gutter {    position: absolute;    overflow-x: hidden;    overflow-y: hidden;    height: 100%;}.ace_gutter-cell.ace_error {    background-image: url("data:image/gif,GIF89a%10%00%10%00%D5%00%00%F5or%F5%87%88%F5nr%F4ns%EBmq%F5z%7F%DDJT%DEKS%DFOW%F1Yc%F2ah%CE(7%CE)8%D18E%DD%40M%F2KZ%EBU%60%F4%60m%DCir%C8%16(%C8%19*%CE%255%F1%3FR%F1%3FS%E6%AB%B5%CA%5DI%CEn%5E%F7%A2%9A%C9G%3E%E0a%5B%F7%89%85%F5yy%F6%82%80%ED%82%80%FF%BF%BF%E3%C4%C4%FF%FF%FF%FF%FF%FF%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00!%F9%04%01%00%00%25%00%2C%00%00%00%00%10%00%10%00%00%06p%C0%92pH%2C%1A%8F%C8%D2H%93%E1d4%23%E4%88%D3%09mB%1DN%B48%F5%90%40%60%92G%5B%94%20%3E%22%D2%87%24%FA%20%24%C5%06A%00%20%B1%07%02B%A38%89X.v%17%82%11%13q%10%0Fi%24%0F%8B%10%7BD%12%0Ei%09%92%09%0EpD%18%15%24%0A%9Ci%05%0C%18F%18%0B%07%04%01%04%06%A0H%18%12%0D%14%0D%12%A1I%B3%B4%B5IA%00%3B");    background-repeat: no-repeat;    background-position: 4px center;}.ace_gutter-cell.ace_warning {    background-image: url("data:image/gif,GIF89a%10%00%10%00%D5%00%00%FF%DBr%FF%DE%81%FF%E2%8D%FF%E2%8F%FF%E4%96%FF%E3%97%FF%E5%9D%FF%E6%9E%FF%EE%C1%FF%C8Z%FF%CDk%FF%D0s%FF%D4%81%FF%D5%82%FF%D5%83%FF%DC%97%FF%DE%9D%FF%E7%B8%FF%CCl%7BQ%13%80U%15%82W%16%81U%16%89%5B%18%87%5B%18%8C%5E%1A%94d%1D%C5%83-%C9%87%2F%C6%84.%C6%85.%CD%8B2%C9%871%CB%8A3%CD%8B5%DC%98%3F%DF%9BB%E0%9CC%E1%A5U%CB%871%CF%8B5%D1%8D6%DB%97%40%DF%9AB%DD%99B%E3%B0p%E7%CC%AE%FF%FF%FF%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00!%F9%04%01%00%00%2F%00%2C%00%00%00%00%10%00%10%00%00%06a%C0%97pH%2C%1A%8FH%A1%ABTr%25%87%2B%04%82%F4%7C%B9X%91%08%CB%99%1C!%26%13%84*iJ9(%15G%CA%84%14%01%1A%97%0C%03%80%3A%9A%3E%81%84%3E%11%08%B1%8B%20%02%12%0F%18%1A%0F%0A%03\'F%1C%04%0B%10%16%18%10%0B%05%1CF%1D-%06%07%9A%9A-%1EG%1B%A0%A1%A0U%A4%A5%A6BA%00%3B");    background-repeat: no-repeat;    background-position: 4px center;}.ace_editor .ace_sb {    position: absolute;    overflow-x: hidden;    overflow-y: scroll;    right: 0;}.ace_editor .ace_sb div {    position: absolute;    width: 1px;    left: 0;}.ace_editor .ace_print_margin_layer {    z-index: 0;    position: absolute;    overflow: hidden;    margin: 0;    left: 0;    height: 100%;    width: 100%;}.ace_editor .ace_print_margin {    position: absolute;    height: 100%;}.ace_editor textarea {    position: fixed;    z-index: -1;    width: 10px;    height: 30px;    opacity: 0;    background: transparent;    appearance: none;    border: none;    resize: none;    outline: none;    overflow: hidden;}.ace_layer {    z-index: 1;    position: absolute;    overflow: hidden;      white-space: nowrap;    height: 100%;    width: 100%;}.ace_text-layer {    font-family: Monaco, "Courier New", monospace;    color: black;}.ace_cjk {    display: inline-block;    text-align: center;}.ace_cursor-layer {    z-index: 4;    cursor: text;    pointer-events: none;}.ace_cursor {    z-index: 4;    position: absolute;}.ace_line {    white-space: nowrap;}.ace_marker-layer {}.ace_marker-layer .ace_step {    position: absolute;    z-index: 3;}.ace_marker-layer .ace_selection {    position: absolute;    z-index: 4;}.ace_marker-layer .ace_bracket {    position: absolute;    z-index: 5;}.ace_marker-layer .ace_active_line {    position: absolute;    z-index: 2;}'),define("text!ace/theme/eclipse.css",".ace-eclipse .ace_editor {  border: 2px solid rgb(159, 159, 159);}.ace-eclipse .ace_editor.ace_focus {  border: 2px solid #327fbd;}.ace-eclipse .ace_gutter {  width: 40px;  background: rgb(227, 227, 227);  border-right: 1px solid rgb(159, 159, 159);\t   color: rgb(136, 136, 136);}.ace-eclipse .ace_gutter-layer {  right: 10px;  text-align: right;}.ace-eclipse .ace_text-layer {  cursor: text;}.ace-eclipse .ace_cursor {  border-left: 1px solid black;}.ace-eclipse .ace_line .ace_keyword, .ace-eclipse .ace_line .ace_variable {  color: rgb(127, 0, 85);}.ace-eclipse .ace_line .ace_constant.ace_buildin {  color: rgb(88, 72, 246);}.ace-eclipse .ace_line .ace_constant.ace_library {  color: rgb(6, 150, 14);}.ace-eclipse .ace_line .ace_function {  color: rgb(60, 76, 114);}.ace-eclipse .ace_line .ace_string {  color: rgb(42, 0, 255);}.ace-eclipse .ace_line .ace_comment {  color: rgb(63, 127, 95);}.ace-eclipse .ace_line .ace_comment.ace_doc {  color: rgb(63, 95, 191);}.ace-eclipse .ace_line .ace_comment.ace_doc.ace_tag {  color: rgb(127, 159, 191);}.ace-eclipse .ace_line .ace_constant.ace_numeric {}.ace-eclipse .ace_line .ace_tag {\tcolor: rgb(63, 127, 127);}.ace-eclipse .ace_line .ace_xml_pe {  color: rgb(104, 104, 91);}.ace-eclipse .ace_marker-layer .ace_selection {  background: rgb(181, 213, 255);}.ace-eclipse .ace_marker-layer .ace_bracket {  margin: -1px 0 0 -1px;  border: 1px solid rgb(192, 192, 192);}.ace-eclipse .ace_marker-layer .ace_active_line {  background: rgb(232, 242, 254);}"),define("text!ace/theme/tm.css",".ace-tm .ace_editor {  border: 2px solid rgb(159, 159, 159);}.ace-tm .ace_editor.ace_focus {  border: 2px solid #327fbd;}.ace-tm .ace_gutter {  width: 50px;  background: #e8e8e8;  color: #333;  overflow : hidden;}.ace-tm .ace_gutter-layer {  width: 100%;  text-align: right;}.ace-tm .ace_gutter-layer .ace_gutter-cell {  padding-right: 6px;}.ace-tm .ace_print_margin {  width: 1px;  background: #e8e8e8;}.ace-tm .ace_text-layer {  cursor: text;}.ace-tm .ace_cursor {  border-left: 2px solid black;}.ace-tm .ace_cursor.ace_overwrite {  border-left: 0px;  border-bottom: 1px solid black;}        .ace-tm .ace_line .ace_invisible {  color: rgb(191, 191, 191);}.ace-tm .ace_line .ace_keyword {  color: blue;}.ace-tm .ace_line .ace_constant.ace_buildin {  color: rgb(88, 72, 246);}.ace-tm .ace_line .ace_constant.ace_language {  color: rgb(88, 92, 246);}.ace-tm .ace_line .ace_constant.ace_library {  color: rgb(6, 150, 14);}.ace-tm .ace_line .ace_invalid {  background-color: rgb(153, 0, 0);  color: white;}.ace-tm .ace_line .ace_support.ace_function {  color: rgb(60, 76, 114);}.ace-tm .ace_line .ace_support.ace_constant {  color: rgb(6, 150, 14);}.ace-tm .ace_line .ace_support.ace_type,.ace-tm .ace_line .ace_support.ace_class {  color: rgb(109, 121, 222);}.ace-tm .ace_line .ace_keyword.ace_operator {  color: rgb(104, 118, 135);}.ace-tm .ace_line .ace_string {  color: rgb(3, 106, 7);}.ace-tm .ace_line .ace_comment {  color: rgb(76, 136, 107);}.ace-tm .ace_line .ace_comment.ace_doc {  color: rgb(0, 102, 255);}.ace-tm .ace_line .ace_comment.ace_doc.ace_tag {  color: rgb(128, 159, 191);}.ace-tm .ace_line .ace_constant.ace_numeric {  color: rgb(0, 0, 205);}.ace-tm .ace_line .ace_variable {  color: rgb(49, 132, 149);}.ace-tm .ace_line .ace_xml_pe {  color: rgb(104, 104, 91);}.ace-tm .ace_marker-layer .ace_selection {  background: rgb(181, 213, 255);}.ace-tm .ace_marker-layer .ace_step {  background: rgb(252, 255, 0);}.ace-tm .ace_marker-layer .ace_stack {  background: rgb(164, 229, 101);}.ace-tm .ace_marker-layer .ace_bracket {  margin: -1px 0 0 -1px;  border: 1px solid rgb(192, 192, 192);}.ace-tm .ace_marker-layer .ace_active_line {  background: rgb(232, 242, 254);}.ace-tm .ace_string.ace_regex {  color: rgb(255, 0, 0)   }"),define("text!icons/epl.html",'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><!-- saved from url=(0049)http://www.eclipse.org/org/documents/epl-v10.html --><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Eclipse Public License - Version 1.0</title><style type="text/css">  body {    size: 8.5in 11.0in;    margin: 0.25in 0.5in 0.25in 0.5in;    tab-interval: 0.5in;    }  p {  \t    margin-left: auto;    margin-top:  0.5em;    margin-bottom: 0.5em;    }  p.list {  \tmargin-left: 0.5in;    margin-top:  0.05em;    margin-bottom: 0.05em;    }  </style><script src="chrome-extension://jgghnecdoiloelcogfmgjgcacadpaejf/inject.js"></script></head><body lang="EN-US"><h2>Eclipse Public License - v 1.0</h2><p>THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSEPUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION ORDISTRIBUTION OF THE PROGRAM CONSTITUTES RECIPIENT\'S ACCEPTANCE OF THISAGREEMENT.</p><p><b>1. DEFINITIONS</b></p><p>"Contribution" means:</p><p class="list">a) in the case of the initial Contributor, the initialcode and documentation distributed under this Agreement, and</p><p class="list">b) in the case of each subsequent Contributor:</p><p class="list">i) changes to the Program, and</p><p class="list">ii) additions to the Program;</p><p class="list">where such changes and/or additions to the Programoriginate from and are distributed by that particular Contributor. AContribution \'originates\' from a Contributor if it was added to theProgram by such Contributor itself or anyone acting on suchContributor\'s behalf. Contributions do not include additions to theProgram which: (i) are separate modules of software distributed inconjunction with the Program under their own license agreement, and (ii)are not derivative works of the Program.</p><p>"Contributor" means any person or entity that distributesthe Program.</p><p>"Licensed Patents" mean patent claims licensable by aContributor which are necessarily infringed by the use or sale of itsContribution alone or when combined with the Program.</p><p>"Program" means the Contributions distributed in accordancewith this Agreement.</p><p>"Recipient" means anyone who receives the Program underthis Agreement, including all Contributors.</p><p><b>2. GRANT OF RIGHTS</b></p><p class="list">a) Subject to the terms of this Agreement, eachContributor hereby grants Recipient a non-exclusive, worldwide,royalty-free copyright license to reproduce, prepare derivative worksof, publicly display, publicly perform, distribute and sublicense theContribution of such Contributor, if any, and such derivative works, insource code and object code form.</p><p class="list">b) Subject to the terms of this Agreement, eachContributor hereby grants Recipient a non-exclusive, worldwide,royalty-free patent license under Licensed Patents to make, use, sell,offer to sell, import and otherwise transfer the Contribution of suchContributor, if any, in source code and object code form. This patentlicense shall apply to the combination of the Contribution and theProgram if, at the time the Contribution is added by the Contributor,such addition of the Contribution causes such combination to be coveredby the Licensed Patents. The patent license shall not apply to any othercombinations which include the Contribution. No hardware per se islicensed hereunder.</p><p class="list">c) Recipient understands that although each Contributorgrants the licenses to its Contributions set forth herein, no assurancesare provided by any Contributor that the Program does not infringe thepatent or other intellectual property rights of any other entity. EachContributor disclaims any liability to Recipient for claims brought byany other entity based on infringement of intellectual property rightsor otherwise. As a condition to exercising the rights and licensesgranted hereunder, each Recipient hereby assumes sole responsibility tosecure any other intellectual property rights needed, if any. Forexample, if a third party patent license is required to allow Recipientto distribute the Program, it is Recipient\'s responsibility to acquirethat license before distributing the Program.</p><p class="list">d) Each Contributor represents that to its knowledge ithas sufficient copyright rights in its Contribution, if any, to grantthe copyright license set forth in this Agreement.</p><p><b>3. REQUIREMENTS</b></p><p>A Contributor may choose to distribute the Program in object codeform under its own license agreement, provided that:</p><p class="list">a) it complies with the terms and conditions of thisAgreement; and</p><p class="list">b) its license agreement:</p><p class="list">i) effectively disclaims on behalf of all Contributorsall warranties and conditions, express and implied, including warrantiesor conditions of title and non-infringement, and implied warranties orconditions of merchantability and fitness for a particular purpose;</p><p class="list">ii) effectively excludes on behalf of all Contributorsall liability for damages, including direct, indirect, special,incidental and consequential damages, such as lost profits;</p><p class="list">iii) states that any provisions which differ from thisAgreement are offered by that Contributor alone and not by any otherparty; and</p><p class="list">iv) states that source code for the Program is availablefrom such Contributor, and informs licensees how to obtain it in areasonable manner on or through a medium customarily used for softwareexchange.</p><p>When the Program is made available in source code form:</p><p class="list">a) it must be made available under this Agreement; and</p><p class="list">b) a copy of this Agreement must be included with eachcopy of the Program.</p><p>Contributors may not remove or alter any copyright notices containedwithin the Program.</p><p>Each Contributor must identify itself as the originator of itsContribution, if any, in a manner that reasonably allows subsequentRecipients to identify the originator of the Contribution.</p><p><b>4. COMMERCIAL DISTRIBUTION</b></p><p>Commercial distributors of software may accept certainresponsibilities with respect to end users, business partners and thelike. While this license is intended to facilitate the commercial use ofthe Program, the Contributor who includes the Program in a commercialproduct offering should do so in a manner which does not createpotential liability for other Contributors. Therefore, if a Contributorincludes the Program in a commercial product offering, such Contributor("Commercial Contributor") hereby agrees to defend andindemnify every other Contributor ("Indemnified Contributor")against any losses, damages and costs (collectively "Losses")arising from claims, lawsuits and other legal actions brought by a thirdparty against the Indemnified Contributor to the extent caused by theacts or omissions of such Commercial Contributor in connection with itsdistribution of the Program in a commercial product offering. Theobligations in this section do not apply to any claims or Lossesrelating to any actual or alleged intellectual property infringement. Inorder to qualify, an Indemnified Contributor must: a) promptly notifythe Commercial Contributor in writing of such claim, and b) allow theCommercial Contributor to control, and cooperate with the CommercialContributor in, the defense and any related settlement negotiations. TheIndemnified Contributor may participate in any such claim at its ownexpense.</p><p>For example, a Contributor might include the Program in a commercialproduct offering, Product X. That Contributor is then a CommercialContributor. If that Commercial Contributor then makes performanceclaims, or offers warranties related to Product X, those performanceclaims and warranties are such Commercial Contributor\'s responsibilityalone. Under this section, the Commercial Contributor would have todefend claims against the other Contributors related to thoseperformance claims and warranties, and if a court requires any otherContributor to pay any damages as a result, the Commercial Contributormust pay those damages.</p><p><b>5. NO WARRANTY</b></p><p>EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM ISPROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONSOF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION,ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITYOR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is solelyresponsible for determining the appropriateness of using anddistributing the Program and assumes all risks associated with itsexercise of rights under this Agreement , including but not limited tothe risks and costs of program errors, compliance with applicable laws,damage to or loss of data, programs or equipment, and unavailability orinterruption of operations.</p><p><b>6. DISCLAIMER OF LIABILITY</b></p><p>EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENTNOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT,INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDINGWITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OFLIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDINGNEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ORDISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTEDHEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.</p><p><b>7. GENERAL</b></p><p>If any provision of this Agreement is invalid or unenforceable underapplicable law, it shall not affect the validity or enforceability ofthe remainder of the terms of this Agreement, and without further actionby the parties hereto, such provision shall be reformed to the minimumextent necessary to make such provision valid and enforceable.</p><p>If Recipient institutes patent litigation against any entity(including a cross-claim or counterclaim in a lawsuit) alleging that theProgram itself (excluding combinations of the Program with othersoftware or hardware) infringes such Recipient\'s patent(s), then suchRecipient\'s rights granted under Section 2(b) shall terminate as of thedate such litigation is filed.</p><p>All Recipient\'s rights under this Agreement shall terminate if itfails to comply with any of the material terms or conditions of thisAgreement and does not cure such failure in a reasonable period of timeafter becoming aware of such noncompliance. If all Recipient\'s rightsunder this Agreement terminate, Recipient agrees to cease use anddistribution of the Program as soon as reasonably practicable. However,Recipient\'s obligations under this Agreement and any licenses granted byRecipient relating to the Program shall continue and survive.</p><p>Everyone is permitted to copy and distribute copies of thisAgreement, but in order to avoid inconsistency the Agreement iscopyrighted and may only be modified in the following manner. TheAgreement Steward reserves the right to publish new versions (includingrevisions) of this Agreement from time to time. No one other than theAgreement Steward has the right to modify this Agreement. The EclipseFoundation is the initial Agreement Steward. The Eclipse Foundation mayassign the responsibility to serve as the Agreement Steward to asuitable separate entity. Each new version of the Agreement will begiven a distinguishing version number. The Program (includingContributions) may always be distributed subject to the version of theAgreement under which it was received. In addition, after a new versionof the Agreement is published, Contributor may elect to distribute theProgram (including its Contributions) under the new version. Except asexpressly stated in Sections 2(a) and 2(b) above, Recipient receives norights or licenses to the intellectual property of any Contributor underthis Agreement, whether expressly, by implication, estoppel orotherwise. All rights in the Program not expressly granted under thisAgreement are reserved.</p><p>This Agreement is governed by the laws of the State of New York andthe intellectual property laws of the United States of America. No partyto this Agreement will bring a legal action under this Agreement morethan one year after the cause of action arose. Each party waives itsrights to a jury trial in any resulting litigation.</p></body></html>'),define("text!styles.css","html {    height: 100%;    overflow: hidden;}body {    overflow: hidden;    margin: 0;    padding: 0;    height: 100%;    width: 100%;    font-family: Arial, Helvetica, sans-serif, Tahoma, Verdana, sans-serif;    font-size: 12px;    background: rgb(14, 98, 165);    color: white;}#editor {    position: absolute;    top: 60px;    left: 0px;    background: white;}.cool {    position: absolute;    background: orange;    opacity: 0.8;}.cool_header {    position: absolute;    background: orange;    color: black;    font-size: 8px;    padding: 1px;    margin-top: -8px;    opacity: 0.8;}#controls {    width: 100%;}#cockpitInput {    position: absolute;    width: 100%;    bottom: 0;    border: none; outline: none;    font-family: consolas, courier, monospace;    font-size: 120%;}#cockpitOutput {    padding: 10px;    margin: 0 15px;    border: 1px solid #AAA;    -moz-border-radius-topleft: 10px;    -moz-border-radius-topright: 10px;    border-top-left-radius: 4px; border-top-right-radius: 4px;    background: #DDD; color: #000;}"),define("text!icons/error_obj.gif","data:image/gif;base64,R0lGODlhEAAQANUAAPVvcvWHiPVucvRuc+ttcfV6f91KVN5LU99PV/FZY/JhaM4oN84pONE4Rd1ATfJLWutVYPRgbdxpcsgWKMgZKs4lNfE/UvE/U+artcpdSc5uXveimslHPuBhW/eJhfV5efaCgO2CgP+/v+PExP///////wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAACUALAAAAAAQABAAAAZwwJJwSCwaj8jSSJPhZDQj5IjTCW1CHU60OPWQQGCSR1uUID4i0ock+iAkxQZBACCxBwJCoziJWC52F4IRE3EQD2kkD4sQe0QSDmkJkgkOcEQYFSQKnGkFDBhGGAsHBAEEBqBIGBINFA0SoUmztLVJQQA7"),define("text!icons/warning_obj.gif","data:image/gif;base64,R0lGODlhEAAQANUAAP/bcv/egf/ijf/ij//klv/jl//lnf/mnv/uwf/IWv/Na//Qc//Ugf/Vgv/Vg//cl//enf/nuP/MbHtRE4BVFYJXFoFVFolbGIdbGIxeGpRkHcWDLcmHL8aELsaFLs2LMsmHMcuKM82LNdyYP9+bQuCcQ+GlVcuHMc+LNdGNNtuXQN+aQt2ZQuOwcOfMrv///wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAAC8ALAAAAAAQABAAAAZhwJdwSCwaj0ihq1RyJYcrBIL0fLlYkQjLmRwhJhOEKmlKOSgVR8qEFAEalwwDgDqaPoGEPhEIsYsgAhIPGBoPCgMnRhwECxAWGBALBRxGHS0GB5qaLR5HG6ChoFWkpaZCQQA7"),define("text!logo.png","data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAIkAAAAyCAYAAABoKfh/AAAACXBIWXMAAAsTAAALEwEAmpwYAAAKT2lDQ1BQaG90b3Nob3AgSUNDIHByb2ZpbGUAAHjanVNnVFPpFj333vRCS4iAlEtvUhUIIFJCi4AUkSYqIQkQSoghodkVUcERRUUEG8igiAOOjoCMFVEsDIoK2AfkIaKOg6OIisr74Xuja9a89+bN/rXXPues852zzwfACAyWSDNRNYAMqUIeEeCDx8TG4eQuQIEKJHAAEAizZCFz/SMBAPh+PDwrIsAHvgABeNMLCADATZvAMByH/w/qQplcAYCEAcB0kThLCIAUAEB6jkKmAEBGAYCdmCZTAKAEAGDLY2LjAFAtAGAnf+bTAICd+Jl7AQBblCEVAaCRACATZYhEAGg7AKzPVopFAFgwABRmS8Q5ANgtADBJV2ZIALC3AMDOEAuyAAgMADBRiIUpAAR7AGDIIyN4AISZABRG8lc88SuuEOcqAAB4mbI8uSQ5RYFbCC1xB1dXLh4ozkkXKxQ2YQJhmkAuwnmZGTKBNA/g88wAAKCRFRHgg/P9eM4Ors7ONo62Dl8t6r8G/yJiYuP+5c+rcEAAAOF0ftH+LC+zGoA7BoBt/qIl7gRoXgugdfeLZrIPQLUAoOnaV/Nw+H48PEWhkLnZ2eXk5NhKxEJbYcpXff5nwl/AV/1s+X48/Pf14L7iJIEyXYFHBPjgwsz0TKUcz5IJhGLc5o9H/LcL//wd0yLESWK5WCoU41EScY5EmozzMqUiiUKSKcUl0v9k4t8s+wM+3zUAsGo+AXuRLahdYwP2SycQWHTA4vcAAPK7b8HUKAgDgGiD4c93/+8//UegJQCAZkmScQAAXkQkLlTKsz/HCAAARKCBKrBBG/TBGCzABhzBBdzBC/xgNoRCJMTCQhBCCmSAHHJgKayCQiiGzbAdKmAv1EAdNMBRaIaTcA4uwlW4Dj1wD/phCJ7BKLyBCQRByAgTYSHaiAFiilgjjggXmYX4IcFIBBKLJCDJiBRRIkuRNUgxUopUIFVIHfI9cgI5h1xGupE7yAAygvyGvEcxlIGyUT3UDLVDuag3GoRGogvQZHQxmo8WoJvQcrQaPYw2oefQq2gP2o8+Q8cwwOgYBzPEbDAuxsNCsTgsCZNjy7EirAyrxhqwVqwDu4n1Y8+xdwQSgUXACTYEd0IgYR5BSFhMWE7YSKggHCQ0EdoJNwkDhFHCJyKTqEu0JroR+cQYYjIxh1hILCPWEo8TLxB7iEPENyQSiUMyJ7mQAkmxpFTSEtJG0m5SI+ksqZs0SBojk8naZGuyBzmULCAryIXkneTD5DPkG+Qh8lsKnWJAcaT4U+IoUspqShnlEOU05QZlmDJBVaOaUt2ooVQRNY9aQq2htlKvUYeoEzR1mjnNgxZJS6WtopXTGmgXaPdpr+h0uhHdlR5Ol9BX0svpR+iX6AP0dwwNhhWDx4hnKBmbGAcYZxl3GK+YTKYZ04sZx1QwNzHrmOeZD5lvVVgqtip8FZHKCpVKlSaVGyovVKmqpqreqgtV81XLVI+pXlN9rkZVM1PjqQnUlqtVqp1Q61MbU2epO6iHqmeob1Q/pH5Z/YkGWcNMw09DpFGgsV/jvMYgC2MZs3gsIWsNq4Z1gTXEJrHN2Xx2KruY/R27iz2qqaE5QzNKM1ezUvOUZj8H45hx+Jx0TgnnKKeX836K3hTvKeIpG6Y0TLkxZVxrqpaXllirSKtRq0frvTau7aedpr1Fu1n7gQ5Bx0onXCdHZ4/OBZ3nU9lT3acKpxZNPTr1ri6qa6UbobtEd79up+6Ynr5egJ5Mb6feeb3n+hx9L/1U/W36p/VHDFgGswwkBtsMzhg8xTVxbzwdL8fb8VFDXcNAQ6VhlWGX4YSRudE8o9VGjUYPjGnGXOMk423GbcajJgYmISZLTepN7ppSTbmmKaY7TDtMx83MzaLN1pk1mz0x1zLnm+eb15vft2BaeFostqi2uGVJsuRaplnutrxuhVo5WaVYVVpds0atna0l1rutu6cRp7lOk06rntZnw7Dxtsm2qbcZsOXYBtuutm22fWFnYhdnt8Wuw+6TvZN9un2N/T0HDYfZDqsdWh1+c7RyFDpWOt6azpzuP33F9JbpL2dYzxDP2DPjthPLKcRpnVOb00dnF2e5c4PziIuJS4LLLpc+Lpsbxt3IveRKdPVxXeF60vWdm7Obwu2o26/uNu5p7ofcn8w0nymeWTNz0MPIQ+BR5dE/C5+VMGvfrH5PQ0+BZ7XnIy9jL5FXrdewt6V3qvdh7xc+9j5yn+M+4zw33jLeWV/MN8C3yLfLT8Nvnl+F30N/I/9k/3r/0QCngCUBZwOJgUGBWwL7+Hp8Ib+OPzrbZfay2e1BjKC5QRVBj4KtguXBrSFoyOyQrSH355jOkc5pDoVQfujW0Adh5mGLw34MJ4WHhVeGP45wiFga0TGXNXfR3ENz30T6RJZE3ptnMU85ry1KNSo+qi5qPNo3ujS6P8YuZlnM1VidWElsSxw5LiquNm5svt/87fOH4p3iC+N7F5gvyF1weaHOwvSFpxapLhIsOpZATIhOOJTwQRAqqBaMJfITdyWOCnnCHcJnIi/RNtGI2ENcKh5O8kgqTXqS7JG8NXkkxTOlLOW5hCepkLxMDUzdmzqeFpp2IG0yPTq9MYOSkZBxQqohTZO2Z+pn5mZ2y6xlhbL+xW6Lty8elQfJa7OQrAVZLQq2QqboVFoo1yoHsmdlV2a/zYnKOZarnivN7cyzytuQN5zvn//tEsIS4ZK2pYZLVy0dWOa9rGo5sjxxedsK4xUFK4ZWBqw8uIq2Km3VT6vtV5eufr0mek1rgV7ByoLBtQFr6wtVCuWFfevc1+1dT1gvWd+1YfqGnRs+FYmKrhTbF5cVf9go3HjlG4dvyr+Z3JS0qavEuWTPZtJm6ebeLZ5bDpaql+aXDm4N2dq0Dd9WtO319kXbL5fNKNu7g7ZDuaO/PLi8ZafJzs07P1SkVPRU+lQ27tLdtWHX+G7R7ht7vPY07NXbW7z3/T7JvttVAVVN1WbVZftJ+7P3P66Jqun4lvttXa1ObXHtxwPSA/0HIw6217nU1R3SPVRSj9Yr60cOxx++/p3vdy0NNg1VjZzG4iNwRHnk6fcJ3/ceDTradox7rOEH0x92HWcdL2pCmvKaRptTmvtbYlu6T8w+0dbq3nr8R9sfD5w0PFl5SvNUyWna6YLTk2fyz4ydlZ19fi753GDborZ752PO32oPb++6EHTh0kX/i+c7vDvOXPK4dPKy2+UTV7hXmq86X23qdOo8/pPTT8e7nLuarrlca7nuer21e2b36RueN87d9L158Rb/1tWeOT3dvfN6b/fF9/XfFt1+cif9zsu72Xcn7q28T7xf9EDtQdlD3YfVP1v+3Njv3H9qwHeg89HcR/cGhYPP/pH1jw9DBY+Zj8uGDYbrnjg+OTniP3L96fynQ89kzyaeF/6i/suuFxYvfvjV69fO0ZjRoZfyl5O/bXyl/erA6xmv28bCxh6+yXgzMV70VvvtwXfcdx3vo98PT+R8IH8o/2j5sfVT0Kf7kxmTk/8EA5jz/GMzLdsAAAAgY0hSTQAAeiUAAICDAAD5/wAAgOkAAHUwAADqYAAAOpgAABdvkl/FRgAANBxJREFUeNrsfXd0XcW97jczu519qrrVZcuyXHHBDRsXMM2AjSkmEMAQqoEQyg1JIAkBQgiBJHAvKZQklEAwgdCLTTWmGeNecLdlWVavp+42M++PfSRLxgbue/e9++5azFp7aemcXWbPfPOr328OkVLCXPQ4jtgkQAj+040QwHE8uEnHGFyRc9bJY8vnTRxaUFuaa+ZpClOlBCGA5FKKnrSd2tUUb1xf17Hh/c2Nb7S2Jd9mQVVqCgP5Tz6c+F0e0DwuwIX/qZASkYCGyvwghDh4JqUErXELXSkHjJJDhwCOyzGkIARDUyCl7HtHTwD72pOQ8gid6dfsjANBCAyVIagpcDyOtO0hGtSRcTm4yxEJabBdgbTjQUq/v7qm+IMFIKSp0FTq38/jiCcdCCGgKRSuKxA0NXhSQkoJISVcVwBSglICBsCTEtGgjkTGgaEweELCdjkkgJywAV2lAAjiaQfJJy8BACj4v9SEBFxXVP/b2eP//tNzJhyTE9K/7pJhAGbXtyWvv/el9e/8cdkX1whGd7L/HYR+2/5LG/0mEoFRApldUd/0yKSdnCtOGP7Sby855pickH74lXao0JJARUEIf7ji2BNuPWvcUtvmFd9O0X9/U77JxIUDKnrSLsQ3mWkAXEjEQtplP14wdnTvPQgBPI/jxY+2Y93eNvDsvSiA6SNKcPoxw9D/3F8sPHrIa2v23bWlMb5IU9k3exsJREwVCcvFN+zqt+2/AiQCEgGVgQUJWuMZUErxdQrA8TgmVuXPqy6KHrQTpMQ1f3oHjy7dugWa+glALAASUpr41/oT/rg4WXXNvAmQ0geKpjKcOr58/sa6DSVQWePXqzeJsKEiGtDQk3HxrZL6fwiS3tWdY2qwXI6E5X69McllpDRmDumbKQJs3deBJz+q+0zLi52kUBLvf3radmsefX/Hp1fMHZunKqxPCgwriUZByCgCNH4dQAyFoTCs9xmo37b/hzZJr3VPAAyKGAgb6gCv4AhXhIM6C/YCDADq25OwBf6lEMT7xEX2YJTutD1sVxXaZwcBQK5v7BZ+le3DpYSmMJTEAlAZ/VbN/HdJkl6ggPhAAYCE5YIeWaIwknUAJSQICDx/8jp77Zr+1yqUoCPldC/+wztgREJI/7Pd7RlomhInXyVBVIaSqA8Q8S1C/ntB0mdU4iBQkrb3Fbrf/0YICcqILx2khMsFCABKAIX5BqnCCOIO/8nD7+1eBcczoLIieHwfMfU209De6S8e+sMgL6Qjx9RAiA+Yb73l/0Z18yWJAqAgrIOSLweuDhcvOdLnXEg/YCQAgGwCyB0Ljx9R+O4vz5hZXJJTL7n8k+vxjMsFeg8h/CARFxIhXfX78K0A+f8LJAPQ8g0m5+tUgJASXEpYScs8Y3LVK49dM/PS40eXVL9884l/K44aNzpJC47Hs4eAlwVJ77Xf4uP/Z5D0YuRrQCCPGKQ7qBuclG3Onzp4yT9unDPP0FVkXI5JQwvxyq1zf1+cH7oBttdPgX3b/keBBN9MmBz+wVmQ2CnbnD+lask/bpgzz8jmMwAg43JMrC7Ay7eecn9xfrAPKN+2/2Eg6U2mSSm/eSJOAoxSEEJgp+zA/ClVz/QCxMoCpLdlXI5J1YV4+Sen3F+cF7pefguU/5mSpLe5jgfBxdd6GL25IMt2Q/N8gMw3dAUSfryjv2QyVAbLE5g0tBAv3XLyAyUFoR/wQ4D0P7VJmc1OOx4ytoeM48FxeV+G+auuE9kMrxzwuQR3/ayyy8VhJX7f8xwPruPBO+S8/vf+T7nAEkDSciH7GYwEvmfChe8TSynhpB3kxAKIhAykkvZXqhnb5ZhQlfvnf9180hkKo5AADrT2IJ6yUVtZAI8LMEKw6osGjK8tgeUJTB5aiGdunPPvp9z1Rosr8SyBRCLjwvEIpCRZAEo4rt/Pr8sep2wPrsf7LB1KCVJfIam4yD6Py35UAQmFZdP48pujw7JcqJTklOSHxuaEA8NiISMn43Crsztd355Ib0zZ1m4hJCj98hqmFFGF0RIA0uViP4CUcDwIQx00ckjBjLLCSGVdS8+Ofa3xV+HnZSFcDgB6SWF4fEl+eExO2MjpSTnJjp701j1NPZ9LjyeJykApChVG8wDCCcE+APbXgkQCkEKOunT2sF8PLgznuNx3VikhxPWE+9vXNv6tuSfztEL90JntcmI5ngZPZo5gZboAEDW1wLb6jqK/vbkBV50+Hh3daZzzy5dw3YKJGD24EB4HNIXi/pfXYlDOdjyweA4ytos/v7oWnpDFTKXQGD3uurmjfpwT1IJcSAEAjBLak3JSv3ll470Zj7/XCxSCg1Fc4gfqFl5z0ohrAprKeDZ8rDLKVu1q3fu393bcbAbU5v6d9rhANKDOu/G0Md8Pm5rJhT8OhqawldtbOp5YsfNaVWENX6eahctBVFYxd2r19fOPqV5Ynhcq11UFMhsncIVEe4+V+GhLw/LnP9rxQGdn6j1oB5ObjuXlz5s5/J0Ljh8xzPMEHnp93cqX3t166qjaQVdef/bEn1QPihQXhE08/+E23Llk1URG6RqRcciomsIrLjph9DWjqvLHGgrrQ7TtCmze17H9r0s33LNzb9ua6y485vWpI0oKuCvEHU9//AqA8/tAcqQ1Z9keJg/Ju/eeCyaferjvW3vSR9/9wrr3mKE1wXJzLj519DMjynKKfvDHD+7yuPiyOMm4uWdMH/rw3PHlx1758Ie/X/yXjyJJ253y9sYGfL6re3coZFT3Pz0QDmX+/cUNbdGgUbGruRtLPt33mBkxH0pnHHX+1MF/uPXMcSMP168NdR1VSz7eM9Y0VVsCoIyifx65O2GNam3rmX3P92YMuO7yOcOn721O5Lz/RdN8M6CK3oXiZtwRv7xg0lPXnTom0v/8RMrCn15dCwA/IwQNRzLoCQDL8VCQGzz7ZxdOe3BMRW5xR3cSqUQaNqN9UUpPCDAhw2dMqpg3c1TJab//15rfrd3edAt0hVNCICFLqBRjmefCcz2oRE6rrS56/neLjz8tk0xjz/52uPlheJ4HSBnilhM996TRf7/ilNHzUokMOju6oasKVEZBiT8u46uitb/53vTH7nx6ZQPhssxOZWBqDJDi6AHq5kiiUrp83OVzhp8EAGmXDwCTrjBcPHtY9I/LvjgvnvEeXXzm+JcfvPzYGYwSdKfsp7bta2P9b5vMuJgzsfLOv10zKxwyVJiacufVf/n4th8+taaO6spKhM1uSDw2UDUhgVDwzDtf3nwDoaTFjAZ/IqXkjJD5V544YmSvcTsAWCrDVScOr31+5d7ThMQL9DArQDPU3/3mpY3HlecHZ147bwIyWWZWQGX405XHnjb9Zy//oMfmDxgqRTrlqGdMqXr02rmjI7YnwKWEQgkEFzjnntexrr7nJjMU2HToIPZ/rONy5AaNC+67ctYTQcrZll0NyA0b2LG/E6t3NqM7YcM0VIwdXICxQwtR15iArqn0loXjbr7rnyK6ob7zKlNXAELSibSdau6MB7sSaTBI/XunjDkt3tUNx/VAuIfueArxlAXYXvDsE0cvufzEEads39UAVWXQGMUnW/djZ1MPhJAYUhjBpBEliIUNXHx8TVnC5tjd0IrCWBCW4yUG2iSHGUjHExhcHF181tQhisclCACFUTDq2xSOxzGsJIZ5Eyq+8/T722NnTqqYwSiB5QncevYE44v6DthZI9PlvvE556iysKmrAIDTJ5SX3JMbuDZuuRM0lSGTcS47DE51CNFgho1Fffrc8TBtWOG1s0aVwPZ8w0tVGAh8ioLtCRw7ohjTawuvWbG99YWArhxO9Ce0sHnhzU9+9tHw8ryKOeMqkXE5LJdjeGkM91045a7L/vTBB5ZQ1pXnB3/+4GXTpwMEQvq2ksYobvzLcry1qeVxMxq8/6sMEj+HKcdev2D8w5qXYbubu1CUE8JT72zBsg2NWwRVnieM7pNCFLy9qemMqdV50y47eRS6ehKwLQuLT6q98tYla1elbO+vAPFcjwvbsdHa0YORZVHkByRS6TRe+ng3Vu1s9dKu6LEl3TF8WPHlF8wYesrGrXUwdAXxhIM/v7EJe9oyb4GxFQDh4E1TX/587/zr5h1FCmMmEskUeiyOmKlCCOkO8G4I+fLBHa/0opnV5+aGdHApoDKK1q4kNu5uhsZon46/6qQRk5jKIuf/dmnTO2v3wlAouJQYXZXfl6PhUqKyKIKcsAFKgI54Gqfe/iLW13e+ph/UubSfBOmV2RKQatYE8G0kV0y8Yk7tHJVRABIao6hr7MTuAx3Qsp8pjOLyOcNnS49PFRiYNe5bHZTst5m26NIH37XrmrsRUBko8QF96ZzhwfOOrX6QJzLnPHDJtJ+U54fgcg5KCHSF4tE31+OBN7euNCLmtYcC5JAENyzHI8eMKP316JJQcO+BdhTEAnhzzT68uaH5KT0Ummaaxu0BXX3MDOj3mpHQrJV7u+9+dsVO5EVMdMYzCGvA3LGltzsuj4DClj55Fa7HoVIBBQIPvbEZL69pfKTDUyZbTBtpCXLDd46tmdvd1QkhOBihePC1Tek9Pd55ZiR4shnQf2UGtHvMSHBBUwbzH3xtc9xyPDDIPrUiAT5wYg7Jv3tcIiesL/recbU5WYMQCiV4ZeVu3PGPT7P/+1nXacMH0ZmjS4Z2ZnD+wvuWdb+7di80RiGEBKMEjFIolEJmPY7OeBpn/epVrNjZea9pGrf1n7lebLBDrPpejojjCgwtjSw+a8oQJgEo1Jdsj7y5EX96bUNfvySABZMHs9qy2NWOe2SXOaArH9R3uzcsuv8tpC0HPvHa/+7XF0ye/utLpz131tTBau+76ArFx5v348bHVzapQfNCCqS/QWBx4injK05OJNKIBANIWxJvbGhcpwcDVxDI+ICrpPQCQeOny7e3v9nUmUFBNIh42sX02qKykKHMh5ApQojQVRUBXUNhLITVO9vw2Z7uh8yweZXCyDrORevgwvB5R5XHjHjSQXFeFMs3N6G+2/lp0FCfHQBqKRHQlNca495tK7e3oSQ/ClPXoClK1sTvB5JDV5pjucEFEysvqyqMQEp/MiCBF1bVuUs3tyYb2uJglICAgBKCq+YMPw0K7YxDPeOc+5Yl3ltX5wOEUDBCwIg/eV2JDM66+zWs2NF5rxk2f3wkMd3rlch+IXwCgNtuxaIZNeeETS0blCPI2C5eXNtgvby+IZO2XJ/pLoFQQMUls2rOFI5XRXo9nC+pAgkzZDz04fb2P9/06HKQLEClBKoKI/jJ2RP6nq9QiobWOBb9+7tuhigXq4zsPqIbkz24lCiIBuYNL4lSx5Mozo1iY30Xkrb4PSOwjnS5B/Kb1bs7RFFuFIQqKM0NoiIvdDo8oVJKYQYMxEJBxIJBfLqzrYtq6l1ZsQvP48aYyvy5QZUhYOhQFQ2r9nTsVnX1kSNpRaLQp3e0JFtj4RAioSBMXRswVvSQ94KQEprKFlx14ogBnsamujZ8srPtDcsWtz//8a4BD5k3qZKMKo/9hBCyIi7Vc86+d2ni3XV7+8oACAE642mc+atX8MGOjvvMyJEBcqRmc4G8mHHJxbOHRft//t7G/djdmvxrXVv64bfX7xtwzUWzhoULc8xLXS6/Mm4RiJg3PvzuzuUPvrKmb3BkdtX0cm4tx8Ol//EW9nTaPzJ09e3DJSoFH3i4roeS3ODkqKlDUVSYAR3bm+LdhNF3v+pdGaOrdrUm9mqaBkPXEdB1lOcFR4OLGCOEG5qOcNAEB0Fz3FqjUHqgTxJLVA4dFBssCUU4GETc8tAat95nlKa/BOSDi7DLE+RAwDBgGgY0TR/wPT1Uj1q2R48bOeiaiTVFSLkCyay4/seHO5C2+DPU0B575pNdibTDkeYSCZcjoKu4ZPawBdx2qwOG8lZcqgvPuXdZ4p21e0EJ0N6Txtl3v4oPtnfeZ4bNHx0JIBK+Ikx6vI8N1xvo8iwvfPaUwZdWFISRzPZLAPj78u1SEvYYKHvs7x/sEFxKJD2BhCtQmhfCOVOqLnEtNyaPYJtkx8zWwsGLbnp85falq/dAEr8PCY8j5Qm4QuLGR9/H25taHjJDxgOH6z8lBIwNPACixky9vMsWaM0ItGcEOpL2PkZJ21eGwSnJdKedna0ZgQ4baLcEAoaaB8g8V0J02AIdjkSXzeFy2UgGTDjKdEPVm5Iuul2gOWHD4XIL/ZpIuCSQXY5EmyXQZYsBr0izJ/QdRMoZFx0//JhuT6A146LL4djXncbzK/fWQ1VepZR0rtnT+fL7XzQgJSQ6Mh4OpF2cPnWIWZwXvNx2OAydLYtDXXj+/W8nnluxFYvuX4rlOzrvMyNHBgghgCOBLlegPe2hhwOcHFzVAYOdff6s2soWi6M94yLuSWzc34llGxs/IwpdQxW28Z1NjZ+sr+9EwhPoyLhosTjOm1VbHjSUc6SUOJLaAQDu8YZwOPg6DehoyXjoyB7tGRfdrkAsFuZQ1EelEIelUR7hnQxPiuDmlm6sOdCJrW09cLhIEkK9rwu8cUm6dnUmseZABza1dMHyOAOlatLx5KaWbqw90Im6rhQA4vY3mimh4c6Mg7WNnVh7oBON8QwoIT3ya3IzLpfY2taDtQc6sL09PoArTHu9CUoA1+U4qirvmpljSkh3MgPuudAY8M6aOuxuSnzCKMmVUlYKLj969oMdgODwPBfpjI3CnADOmjp4kWd5uRQEjJBl7d3eaef+5u0P31x14GemGfiRoVA4nA+oqBswUVLC9Vx4nguPe1nKJBG242H2qJLFo6pykUhn4HkuVAa8+MlOdCecFQyooJAVPQlnxUsf7YRKAddzkUhnMKIyB8cfVbrYsj3lq0LuVMgT/nDVzCsm1BQhmbb8PmSPeNrCDxdOZBfNrvlDJm5FyCEqOku6g2V7sGyvDzaEEG7ZLleEDYWnQYUNQ1M0IQT5KpAJCQR0JajCBfPS0KWDjOVwgLgEkjBuQeEZMOEeojYACem6tgVd2oCbQkCRYIyGvip7n6V8SOpaoDwDekgcVOl/BXe92gtm1swLGiqcpAUKAtvxMKa6CMt+tWABo/S03vsplCBluaDwQ/IZ28P5M2tKnnh/x1mW4y05a3LV/cNLY0WuRIpATlIIefWv729/pDslXwUloJCghIAf0lsK0ndkW5pIeeyi42qnSKDv84zl4qSJQzDjqMrvU0KuztoFLKBSpDIOWDZxIYTEouNqj359Tf0cCSwjh5kQO2XX3HnhlCdOnVwV7ohnQIkfe9FVBWnLgZASqYyLuy8+5pjdLfGHP9necn7Q1L4kFGW2vDKoG8g4HJSQTHfCatcoHaJrGiglKM41SzfVd0UBdMNPe8C2XGiG4hvNADjnSnFeaAhjFKqiwNBUdMStTlB0ERCqKgyqqoAxehgSF5o74xlZWRIh3SkbkaCOmKmNbE856EufpB0QAii6CkhACEFNQ9UpY2CUQWVsAPgUABAAXE+gND90+RlTBgdSlgtK/JgD5xKDck2UF4QMKWH0IlYICdvjWZfRD7CNrMjDiUeVXvTi8h1dZ02tuvzsY6qRcP34ghASz32yK3RAyFcVBkQNFSqjiNseuJ/RJJrqUwj8IxsncQUdX1N47awxpUjbveUcEpwLVBSEoTBi9k4WIb5UcFy/XwQEadvDsaNKMLE6/9rVdR3LDE3p5zYBVsqOXjSn9pnvzzuqpDtpgRJA11QcaInjheVbcNN3pyNpufCEgKmrePia2eeddufr2+o703eYAeUwy1ICErAdD5RR2dKT2WY5fHIkZCDtCgyvyC15b2Pj0QR4FwBc14PkAp7DQXU/SCUlRo0dOmhY2vEQChrgHGjsSH0BxrooAVMUBaqigLIvF60pjO7Z09jdPGNseTFjCqiqYFRl3py31+03iK5YLCv2hPCNa6ZQSCFLaysLKm0uQBkDY+zL3g0lALfd/IVTh1xUnBfyxW+WqJwbCSAaNGDqGoKGf5i6hlBAR37EhKGpfvqfEAgpcfGc4VNBcXZHwpIJlyOestGdsuF6HGFDDUICQU2BoTAwQhDVFTguh6kpJVWFUXAuwajfsbTjJeGJCRfNGna6aah9xeuaoiA/aiJi6l/qVzigIz9qQlOVLFCAgK7gotnDThYOP0r2A0g66ZAZI4sfue9704/O2H5BF2MUpqrgrn98inueWdP9yofbkR8OgBICy/FQVhDCo9fOuj2o0vMPTclLT4AxWl5aEDktFNDG246HhOW9uX1fB4rzosi4EmVFUYyuyP1BOuNCiKyBmM2kux5HJpHBiIr8G2oq87V42kVpfhR7DnShK+0sIwQOIZQoigJFVcEY+5KuUhTWtasp/lEiZSM/FkR3xsWxY8tq8qPGNXbaznJ//BXFhUAmnsGQkpzvj6stCXcmLVBFheLHSQZKEi4kwkHt/O/OqimyXA+MUt+j8Dh+9uh76Mk4oIeax9LPal51xtGorSyA5XjIOBzHjizRRlYXnrdxTxsuOXFU9joCVWVYfMro0esefP+URNpZKjyB3tgezzijrz5r/AVDS2NIZFwwRsG5wN6mnpaCkug586cMDqVtv18KY+iKp/Dzv74H7zA7HkgJKJC46dxjkJ8TgutxpCwXp08erP3+lY1X1ndmvq+rFJbtoaowdMfD184+lykUti1AKEV+2MAfX/gcr6xuWKIW5v761r+vfO/omqK8suIcZGwP8YyD6aNKcf+l0x6+8qEVO6mhrmaEwOMChbnmuT++eMYfSnLDBYlkxv3Ti6sfWL+n7Y4VGxvqp44pr4iGAuiyPJw9e/j81s41NzW2J38PSgAhISAgLBeFBZHLLzl9wqKuRBrhoIGQyvDO2n1tiqq84HrCAAEYU6Aoh1c3lAAZTzz6/pq6hefPHYdtjV2AynDl6eN/9eTSTcmGjsTjsBwHAoCmmLVV+d+/auHUGxzXgScpVJX44DvUJrEznn7GtKorR1bmoTvtgBKCiKnhjU934o+vbVkBXX8d5Eu0Ag8pa5hhGpc9+P0TYGcTgIam4OpTRpG7l3yG2y+YCl1T4bocacvDWdOHBioLwy+v2dO+QQIZAFAICQwvi42YOrw4lPb1OExDRV1jJ9bvbs+5fsH4M4vzguhM2KCEIGqq+PuyXXhs6faXEDQ+AaB+iY6QykytKS8464ZzJqEzISAkUJRj4rzp1ef9+l/rfuVAaQowev5frzvu52UFYcTTDhghCJka1mw7gDufW1OvhQI3qYw0tabEDTc+vPzvL/ziTKgKA+cC3WkbF80ZHt5+oHvJ715cPzMQMhpd2y1eMPeoPxXlmHmrdx5ARUFYXTir9uat9Z0vHei2fv7aim1PfOfU8djVEgdUhuvPP+Z3b322d8yGHU1PJDJ2fSiglYwdVnzB6bNGLnZcG64QGFocwz+Xrkd9Z+bXZkDvdF1RSrLZW0oZSNYkOLQZuvr2R1ubXxpRuX/BuNGV2NXcg2hIN266YNrDuxq6r2lo6V5PCSFDKvImjq0pGik8Fxu2NMIMBCAJQJXD2CSaSk+98uTRoykl0FUFIIBOCZas2MkRNG8yDW3N4TrjBnTyxrqGY3/WkayNxfxV6wiJ78wahnueX41fPP4hHrzuRKQVhoztIuV4mFBTpE0dWTypvy53ufTtDQCGoSKoUtz77CromlJ92Ykj4UlA1xRfurkcz32yu4fmhBcbKms5LMVBU/Of+2T38VfPGx8LZCsOXQEsmjMi75F3ti7sTjjL/3jd7EdmjyxGh82hawoUhcJO2/jBQ8tFUiqLTUqapATMoP7U8q1tx/3u2ZWX3n7xsei2/bhR2pW466Kp1fXtySef+2TPXMJITTSg5rX3ZJB2BTpTDnICKjSFnEiYdse7mw6cHgooC0+bPRptKRu2x7Hg+OGXzJtZe4nliXTAUE1dpejsSUJhBIPzQ3j5nQ14e33DcwEz8B+9Y0UJgaExGLqCIxXSEwCKpl37+LLNwy6RcuTEsYPRnrSRsCwMrYiOHTOsYKymMKgUUMHx0fo9eH/tPpx3xmT0pDJ9tdsDQDK+KvcHVbkBNDR1+zkWSrCpNY73v2herevquiNFAlRKZGO3teS5D7b94pwZNXBcX0ebGsPC6UPxwHOrG5Npu+RHCydhaGUhVEYgsoZy/2SNphAYigYhgabWbtz8zKdY8sHuFfNn1tSEFFnc1NSV1bcUn29vwvr67qW6obccGvEk2RC6rrL2jQ09r73+6Y4Lp40shZvNFpsqw5TqgtsipnbLnFGDQruauvu4HColuPvZVVhfH/+tGTHf7HNdpIQeCtx03+ubjzlqSP6IicOK4XFfVeoqw0/PPGrOhrqOX+040P3XtV/slxNHFBFJYiiKBLDi891I2W6boWvQA8b3XvxsH/a3xheeMWsECgti8CQHo0A4QExID8IFcgMqDjR24KkV27CxIf5UwDSuIpA8O1hEoYRV5IUQ0hgI55BHII4xShq5qp/26Jubn9q4u2X6cROHoKggAoUC0nFgWRzN3Sl8tG4flq2t3za0sjAa1NXiRNqClBK2e9APJlJK5H3v8dcM6c7urfElALEESaahXMUoeelr2HjlTLhvhJkc3M8mJELRDsQ9LMikrAsjqlw8uTo/Z9zgfJQXRRHWVTB6sMbY5RIt8TQ27mrFB9ta7OaE97gRMm8PKfJZlbtHy360yRQnHQ5VFlJCVg3gFGgKhJBwPJ5NL2CiJtzng0zmy35xBJdpKY0SXbqO0v++QkJ0uHhH0/TvAvJLeRVPyMkKd56OqaRY9HN5NVVBhqhvpRxxruc6z5wwpuSco2uLsbepC69+VrfHJmwaI6SlN3CSsZxrDPAbh5fFqmsr8lCQE4SqMFi2i+aOJLbta8fO5sQmzpTfGbr2RH8/mwsZKQip66vyAoOlEHAEwbbm5C89idvIkdmFum27VzDhXVwY0UflhPQAIQQ9acdt7cnstQR9hlD24MRhRa9dcOq4qc2dceQHNNz3zKf/an500Tl9IDEvetzwhCzv9fMJIZRREmeUNPUFm7JuqcwScHtLIrLvEHKFKIGEzBq4lBB0MELaCSFwuahwLGc2hJgAISoBGe3LQPserQuQJijKBs3Q3lIY3QQ/Ix4RUg7qn+ujhHRQgo6DkUnf5Z0zsRod8QzW72iEoSm9MYNcIWX+Ide3Syk1CUQwwBmGxyjZSw6WPfcF/HqNdiERFVIWHWoIMIJGQkhKAhHLcm4k3JsmCN1uBPQHKCF7DjNxMcfxTuCedyyFrCFAQABxCfKFoqorVJWtINkMc2/uqJdH67h8BOdiAggIISSta8rbBEh8iXYqJUzVL1Hx6RKEcSGGcS5KfLIebWOM7qAE6VTaipw1c+TO6RMqCruTGTDPw73PfPb71FOX/dtB+iKBZah0Z0BXoSjM9wgyTt9D86Im0paDjOUiZOrgXKAnnkbJoBiklOjoTifDAW2HwiiS2UBNH/q5gKkp9bGQ8WQybT/pSw9y+M3NINEfeQQyzgiJ9w5Q//uqjMEMaOhMpCGye4IRAgjOwQX1PTSCTkpIZ98te6vY/Rs1H67QjEsJSig8IVBaEIHHBVq7UsjGoXoUSnoGXnNQbRIgHjC0OwDdD/L0k1SyX3SXUdKta8rz0NTnj1TJ5BOhCRRG/YkWEmFTQ044sLUrkdn6dXVQfX+F8EecSE6BrYrKtkL6QTzBOTwJaAqbM662pLAnmUHE1LBjZwfSNl87IE7iOB40TcHEkWU46ZgajK8tQWlBFLbjG2nja0ugqwyOx2HoKgKGCsmFH5XUVNi2g8qSHEyoLYHtetkaX9/vt2wHg/LDmDyyDLbDUV4YhaZQCC7ABYeUAkIICPnlpJKmKFCYT0fo3Zai1/4ImfqAnQl664qRDQx6nhhgyKmKz2s5EomeEQJDU1FVnAtNYXBcjpxIAKUFEeRFAogEDagK6xf+zvJsFJ8O0ftszkX2nSRUhYFm3ePeSoO8qNmvRknC49xf55AQQoBz4e/YFNRRFAth5JAi3/B2OUxDw5TR5X0gkv2ivIfjs1CKAOfCcBwPCiWw0g6stI1M2oFtObAzDtxEJjJ/xojbYlEDadtFWGNYs70pyRj7aABIPI9DSGiUkhpdU8dqqjK0N1ZxsCMH9XC/eo2olDIKIWEo9MyQqd4khVA9zkGQnVguoDJ6UthUb+FC6MGAVghAtS0Xg0tyETF1FOWGkBcxEcjaFZbtwVAVDK8qRHlRDgpyghg1tAiu66+oLCUwK10IIKQSDqjXGxo7FyK7raMQ/nsJCV1lGF5ViLKiKAqzsZPeHRKElLAyLkrywigtiKKsKNbn/Qkhs5OtIC9sYlhFAWzbg+N4COkqKgflYmhpPopyQ7AsBx4XGFqej2gwgMpBORhbU4KQocF2PHDu32t0dRHyYyZsx4OqUIyoKvTtMo+jtDCCyuIcCClQVhSDoavQVeaDwHcoJkWC2s+lRJ7LBQblR2CoCqyEBdfxBoDGttzwCZOGvPvzS2evHlNddJOuKiPBhSksF9J2ITgPF+YGT1x01uSlx0+pHtfQ1oXSvDD21rdhU13nq5rG9g3M3XgCZXnBnx87uvjGuv3twRFlYVQXRz5oaO66whVy56GrLj9moq25OzBjTOkHEpB1u1smx4LqjRX5wRnS5c9IKZtyckIwDR07Ey0I6nRxRUHwTF2le+dPr37opQ/cP2/oSt4yKD8MK+MgFNTh2Byex+GkOHrpijQb1CPEF7tC+qjmQkJRWIQQGAqlrYSLaFm++YDrOmvhyX8ePaYM+xo70NKZBFMYiKGAUV8i6aqSXe29EkhAcgFKfWnAD1fYlC1YYtRPL3CHQ49RKIz6FAFC/HOERGFOCGnLRW40AE1hh1UHhBBwz48JDcqPYPu+dji2i2g4gIDGUNfUmb2fL5GkxwGPw1DJd6oHhf9NCLHCUJQPIqaOdDLjF2Z5Aop6UFvrGjt++piKYwblBnDV2RN/15Ny7u7syTQk0k4rABkLB0qKC8JVUgocaO1ESW4YImPhyaWbEmDKneRwCT5TV4b0JDLBh15cc4ui0JwfXjD9R8dNrHrgjU93nda/0osLiYqiHOxr6rbfX717KwEENEUIKW0uZAYAkdwXjzRI1KrKAk9ImRZSekLK+D/eXLelLe7sUwM6pPAzp6YpiSREtR3eZwjZjgdCiAYQz3a54NlMoJQSmkK12ePK3mvvSbdv209P2W873OMiZTs8UVSSi9xoUN+5r7XPhbNdDkKISiklactxeierF4wQAo7LETH0gMdlxs0SuIWUcD0B1xNQg0rA8URGcgEQX6UJCSgKC1guz/SKJtfjsB3Pd7sNYtguH+Apid6itl4pZnt9gHVcnt2tyX+uqioBLmSm93wp4Tkuh64xq7wgR3FdIRxXCMBn70NKEOqnR4K6egJxbdi2goxtg1HoxflmdSkLVZOsWsxYGaiMoDIvhF17mvHkW5uttoy4TFeVbYet4JNSeo4nEIyE/ig9kUw7fHEmY+erjI0dXpHz4OZdTb+RXLxuqPSsYWWxG977nF89rKqslVJo+w/s4H1mpZRcCtDxtcU/nTKq5HupjGPHU3bAcbkNSdJTx1UnPlq/r6OnscsszTefM7VBLbUVeUfnRs3wO5/v/cuKtXV3A1KZNq7y9qmjShb1pKxEfUtiMyWggvNLhCCpaaNL/zahtujoVMZ1K4oiqx95ueNml4uu8qJIzdDy3JWVg2LFnuc89c6nO3/OPSEnjS/90cTaoqsoocqWuo7H9h7ovJNRn+gruUBOTmjsyVOrfxkNKtMIVeoSqfRvN2w5sCQ3rN9bmBOsHlmVi+qS2Ky0Kzbtb+76cXtT16rigvCCOZMqbmNEljd2Rt94tj1+I3e8nsKY8VQsNMiuKIrUlBWGKzUmn3nz0523+hpF5JblB19IpjJL99e33xMJ6qcdXVv4wzVb919rc/nF4EGRRxzXYxT0tqmjSu6JGuwUpqn1ze09t+3d2/Y6JAQIwfETqu4eNTi/hqlK50vLt/+mqz3xDGEUnseh6b7UTDv83Z89+v53jx5akDtqSBGK8sNgAR1g1I9VcQ4rZWFnUxc+39qIzfu71xBV+6GuqctxpDJPjwsxKC+MRaeM+VdpYbS0qaUz/O7qul/FwmZJSa45gxH5JqR8XVPIuOK8wAwhxMjSPHMuYzQEIa72Y2QS4CI9bmzlDSdMrLzzkX+tXN+TctoumTfhRC7RIaWsqC2Lnrx+m7JVeuK94lxzbmVhkDzxypoPy4qi4fPmjv/Vhl3Nq4aV50+ePbbkp39+/rNPHI9bi8+afG5rj5WQnhcyQmZq3daG1nHV+byxLZ5a/vneBiGkRUB4eWGo7LGXVx+IhQ3r0gWTb928u2VNbsQsmDSs8J4nXl3zNCVEv/zMSbftauhs3rav/c+EAAqjpVecOeH1+obWomde3bGkdkjh7AtPHvtMQ3NPO6Q4ava4ipMff/nz5mUrNn+84LiR8xedetQ/nnx1/c2nHjPkny+9v+XThub4kotOG/v9E6cMwRtvb74qFtLmDC2JFTz8r89WmwG166pzpv5wx/6O3XsOdD0kATseTw0fX1M47LNVe343vCL3quFlkdkVRZFzvkhYDx41JP+KF5ZvfW3+zGF/ScQTM59/Y+dDwwbnn3L+iaOevffJj2tczq3i/DBWb6mf+tCST5ZOHFN2/IWnjHr67tbufT0p5xNBCTzuq0VKyUsZoax974vWs9/f3HiSqbKRIV3J0zWqSwlpu9xOWF5TxpXrqKq+qAUCLxMgc1jW3cEIHZWpjIUVK7cNfeODjYWxsEGmHlVZ43hcZtWNmxV5Tu//HheWx0Wmn77lICRvyojixZ9t2d+8syk5qzXhnfThhv3LKSWmX6khIKR0skxF79PNBz5r7HJnrtvTeXk8aaEoxzxn0ohBV36wft+O+jZrVnOXM2fV1qYvCJHcdwA4etLeT9OOSCRsvqE16S2AlFtUheas3ta0tb41M3ljXfd3WzuTGJQXnDe2puAyTyBz8qyxXxw3bdR2VVVQUxb7LmwX0hMoHxQ7Jy+slb62su7fklS/6LNtrWc2t8XlmJrCK7iQ1s797XzVjrZTO1x2xosf7b47FlSrp40re1JVmDJu1OANC+YevYeqWlttee4CEFJGCcms3t60b19LeurWhsS5jW1xlBaETpBcgDKa2ri79fmCmFlsxMzjqgZFj/5g9R6MGlIwMy8veLqUEk2dqV2jBuefEjDNrecumFpXWVG0tSBqBPNyzBMJiN3RncL76xuu6ZbK2e+sbfheOm2ToaU535W261MO+hXUM0rqA4Z2vxEMzuWKPqbTo2MbU3Jyc1pO7vbYUVIzxgVC5nd0TVlCsrm0wzWlH6uJpS0PWxoSJ2NPVxtV1LdPmFR95+bdzbfA54NwCAmPC/criHcCjMZ0jRWnLL4GIHG4Hlwh9kNi2mGMOCokmiEFFKZ2ZCkKhZpC8tOOeA9CeKAEAugESDmIn7sBFwGaZdBnXR0FAJUg7RACRGVdfphe5gd0JS+ZytBd2xt/yDSm7K9vbNrXlq7TggYcy4ahkiqPSzieWJ2liW21PJHUFFJqcZKybJ4BF7uYIpBx+SrOJcKGGnIcl+/dvf+7TFM0AqQ7EvY2aAqXUjJJSCsI4RAinTUn9F43+0Bb8jXLdq89enjxHYQg/O66/SsWzhk1edKwQYP2NfcccFyxV1cYmls6hiaS1l1MZXzJ/pbGeNqOR0ytzPU4uMAXhAh4Qq53uIRCSRGk73pLCXgegdp/hwafHhBXCIl/ibz5DQjpykDqGxAJG15+NJipqSz0OrtTipV2BAFQXZZflbZBasrzhxu62rcnSa/PTwjxCWdc9uxp6GicMLx05GebG0tyo8H2cTUlIwghnsxGL0k/8nB2X3yfJM4IpETH9rr2xmljyo+ua4qXg1Bv1JDCwamM7fa9k7+bATE01YhFTcSTFicEhPpp0ewiIgBIT31jd2LU0EFdq/d2H69paqOhKWYqY3dQRqDoGpo6UrsURjFuWPEJO+o7PwnlBKcPLo6FX/9w+9by4py8ipJYoKIsfzgo+by6JDrH4xxrtzW211YVxPZ22JcnrNS7kZARsGw3CS4opVTp1w+ajVTL3jG2bL5yd0NX09ypQ6YuX1O3rrkt+WPLdj+ePrZs1PPvbX06Y7kfdyUy4FR9c01dy7WGpkDXFMWyvFYp5eSivBCGluVOyNjiczPAjs8JG9jX3L2d6TooI32T+V+5TVhfmadte/qg3CAuOW3sS2FTy0+nMiXPvPPFX7gk/3z/8923nTGj9gdTRpee0NXZM7KtIwHGqOF6XlBKGgQBuMdNx/VC0FjH8nX7/1BdHP2PH3xn8ufxtJ1MxpPD4inhUkp023bBpdQBAsf1GOcy0Duxtu1BYTT57ud77y7JDz52yaljtrZ0Jjw7Y0W5IE2QEpRRSE1JbNzRVL9wzugp0XDgvcdeXf8jx/FUj/NgNp5LHdeDwqi3Yt2+B6tLon+5ZdG0ZSmbbxUer3j8jQ03d8UzrxkBHUmbP/fPtzZef8bsEXe0jCg5IS+sTXzvs53JusaePw4pz7tNco+dOaP6Ld0wdkQMOvkfyzau2FrfdefqLfWvXrdw4lPdKfdjQ1OKXlz+xXNdzV33uK4X9jye6KXGOa4HzkWgd2UwlXVvq2//ZOa48rO37ut4F5Su3NXQuX1ISWzE7sbut6nC1jz/7pa3L5p71HkTR5QOAZDZ29hpLFm6eTZjVN3f2IHZY0sfCoWCl+aE1MlvfLStrbXbflw3tN6dJr7RNmX/qc2KpJQILHocKsF5OSa7WNdYNG257W099htQ1L8pCnNc25ldEtNv1VQW3N+eWhoy1GFpD3cZCs4DYKRd3GIw/EChGJ10cZ2Q0qacX19ZFDzPcnh3S7f1aSiglqRd+R9BFT+zPDzjCrwZ0vCoy7HK5vLPFCgKauTfbQ/POly+6DruqTFTWdAdz7QuPHnsJYwS+vTSTTW6oaWYwuB53oySqP4Lyihr7LavCKrkOi5xwPJwLyGIhVT8weF4y+J4UrjuJeX55sUBTcnvSli7uiz+C4BuJNk6VNv2hsQM+tOSPHNSR9za2Rx3fisk+fSUSVXvVA6KHLtk2cY3ygpDgxs70p8lHHmnpiqNtuXMLopqN+aE9epk2m3uSHkPepK8HFTxgJBotzzcJSHDIY38weX4xBZ42C9nk4CUs4IquTrhyttByDYF8gJdwakpF9dTStsdl8cCTNxSlh86QQgp2+LWh2mX3KwpOJVKMZ8L2VVREDqhM2HtbU24d+u6uvqwRcj/hy2V/SkTIqVE8OIn/OovV0BC9DHT+oePXdcPnauK/3svjNEBQS+ZDcVT2otnAsdxQRmFojAILvoYZ70qp3/isDcGI4REfjRw4txpw07bdaBrRX40MG5iTf7PH3lp7VONXdZFSrbeF8S/v8+H8SO1IKQvGce58O+djRtwT/h9UBgY7bexH+ndb1bAdTiYyvzKQMvFacdUf1hbkTvp9//4rIiqrEdTlYMMvew2oY7rEYUpUlV8Bl52q5SDHOHed+x3neyXm+lj+fXlnw7uf+u6HkAIVEXpJyX8zZC564+nopDD/yDRfyFIlAFEFUZ8PvphHqowAil9rnrvy/XPnfiZSvKlfElviWbvDw31/8GhQ398iGWzaGnLGbS/ofnqyrzw9Rnbwp+fX/VmU9z5iaYOJB4r/eh79HD3OuTdJKHZyTp8cZWq+N9LCaiqgm11bQ1NbT0lqqYQxggOZXAySqApVPZ/9qG7ZLPDVEX1jkd/CgM7xI7wGfv+DxTRfglOkk0XUoX+p38w6n+3/a8BAGOtxmE+9d9lAAAAAElFTkSuQmCC");var deps=["pilot/fixoldbrowsers","pilot/index","pilot/plugin_manager","pilot/environment","ace/editor","ace/edit_session","ace/virtual_renderer","ace/undomanager","ace/theme/textmate"];require(deps,function(){var a=require("pilot/plugin_manager").catalog;a.registerPlugins(["pilot/index"]);var b=require("pilot/dom"),c=require("pilot/event"),d=require("ace/editor").Editor,e=require("ace/edit_session").EditSession,f=require("ace/undomanager").UndoManager,g=require("ace/virtual_renderer").VirtualRenderer;window.ace={edit:function(h){typeof h=="string"&&(h=document.getElementById(h));var i=new e(b.getInnerText(h));i.setUndoManager(new f),h.innerHTML="";var j=new d(new g(h,"ace/theme/textmate"));j.setSession(i);var k=require("pilot/environment").create();a.startupPlugins({env:k}).then(function(){k.document=i,k.editor=k,j.resize(),c.addListener(window,"resize",function(){j.resize()}),h.env=k});return j}}})

define("ace/theme/twilight",function(a,b,c){var d=a("pilot/dom"),e=".ace-twilight .ace_editor {\n  border: 2px solid rgb(159, 159, 159);\n}\n\n.ace-twilight .ace_editor.ace_focus {\n  border: 2px solid #327fbd;\n}\n\n.ace-twilight .ace_gutter {\n  width: 50px;\n  background: #e8e8e8;\n  color: #333;\n  overflow : hidden;\n}\n\n.ace-twilight .ace_gutter-layer {\n  width: 100%;\n  text-align: right;\n}\n\n.ace-twilight .ace_gutter-layer .ace_gutter-cell {\n  padding-right: 6px;\n}\n\n.ace-twilight .ace_print_margin {\n  border-left: 1px solid #3C3C3C;\n  width: 100%;\n  background: #242424;\n}\n\n.ace-twilight .ace_scroller {\n  background-color: #141414;\n}\n\n.ace-twilight .ace_text-layer {\n  cursor: text;\n  color: #F8F8F8;\n}\n\n.ace-twilight .ace_cursor {\n  border-left: 2px solid #A7A7A7;\n}\n\n.ace-twilight .ace_cursor.ace_overwrite {\n  border-left: 0px;\n  border-bottom: 1px solid #A7A7A7;\n}\n.ace-twilight.normal-mode .ace_cursor.ace_overwrite {\n  border: 1px solid #FFE300;\n  background: #766B13;\n}\n.ace-twilight.normal-mode .ace_cursor-layer {\n  z-index: 0;\n}\n \n.ace-twilight .ace_marker-layer .ace_selection {\n  background: rgba(221, 240, 255, 0.20);\n}\n\n.ace-twilight .ace_marker-layer .ace_step {\n  background: rgb(198, 219, 174);\n}\n\n.ace-twilight .ace_marker-layer .ace_bracket {\n  margin: -1px 0 0 -1px;\n  border: 1px solid rgba(255, 255, 255, 0.25);\n}\n\n.ace-twilight .ace_marker-layer .ace_active_line {\n  background: rgba(255, 255, 255, 0.031);\n}\n\n       \n.ace-twilight .ace_invisible {\n  color: rgba(255, 255, 255, 0.25);\n}\n\n.ace-twilight .ace_keyword {\n  color:#CDA869;\n}\n\n.ace-twilight .ace_keyword.ace_operator {\n  \n}\n\n.ace-twilight .ace_constant {\n  color:#CF6A4C;\n}\n\n.ace-twilight .ace_constant.ace_language {\n  \n}\n\n.ace-twilight .ace_constant.ace_library {\n  \n}\n\n.ace-twilight .ace_constant.ace_numeric {\n  \n}\n\n.ace-twilight .ace_invalid {\n  \n}\n\n.ace-twilight .ace_invalid.ace_illegal {\n  color:#F8F8F8;\nbackground-color:rgba(86, 45, 86, 0.75);\n}\n\n.ace-twilight .ace_invalid.ace_deprecated {\n  text-decoration:underline;\nfont-style:italic;\ncolor:#D2A8A1;\n}\n\n.ace-twilight .ace_support {\n  color:#9B859D;\n}\n\n.ace-twilight .ace_support.ace_function {\n  color:#DAD085;\n}\n\n.ace-twilight .ace_function.ace_buildin {\n  \n}\n\n.ace-twilight .ace_string {\n  color:#8F9D6A;\n}\n\n.ace-twilight .ace_string.ace_regexp {\n  color:#E9C062;\n}\n\n.ace-twilight .ace_comment {\n  font-style:italic;\ncolor:#5F5A60;\n}\n\n.ace-twilight .ace_comment.ace_doc {\n  \n}\n\n.ace-twilight .ace_comment.ace_doc.ace_tag {\n  \n}\n\n.ace-twilight .ace_variable {\n  color:#7587A6;\n}\n\n.ace-twilight .ace_variable.ace_language {\n  \n}\n\n.ace-twilight .ace_xml_pe {\n  color:#494949;\n}";d.importCssString(e),b.cssClass="ace-twilight"})

define("ace/mode/html",function(a,b,c){var d=a("pilot/oop"),e=a("ace/mode/text").Mode,f=a("ace/mode/javascript").Mode,g=a("ace/mode/css").Mode,h=a("ace/tokenizer").Tokenizer,i=a("ace/mode/html_highlight_rules").HtmlHighlightRules,j=function(){this.$tokenizer=new h((new i).getRules()),this.$js=new f,this.$css=new g};d.inherits(j,e),function(){this.toggleCommentLines=function(a,b,c,d){this.$delegate("toggleCommentLines",arguments,function(){return 0})},this.getNextLineIndent=function(a,b,c){var d=this;return this.$delegate("getNextLineIndent",arguments,function(){return d.$getIndent(b)})},this.checkOutdent=function(a,b,c){return this.$delegate("checkOutdent",arguments,function(){return!1})},this.autoOutdent=function(a,b,c){this.$delegate("autoOutdent",arguments)},this.$delegate=function(a,b,c){var d=b[0],e=d.split("js-");if(!e[0]&&e[1]){b[0]=e[1];return this.$js[a].apply(this.$js,b)}var e=d.split("css-");if(!e[0]&&e[1]){b[0]=e[1];return this.$css[a].apply(this.$css,b)}return c?c():undefined}}.call(j.prototype),b.Mode=j}),define("ace/mode/javascript",function(a,b,c){var d=a("pilot/oop"),e=a("ace/mode/text").Mode,f=a("ace/tokenizer").Tokenizer,g=a("ace/mode/javascript_highlight_rules").JavaScriptHighlightRules,h=a("ace/mode/matching_brace_outdent").MatchingBraceOutdent,i=a("ace/range").Range,j=a("ace/worker/worker_client").WorkerClient,k=function(){this.$tokenizer=new f((new g).getRules()),this.$outdent=new h};d.inherits(k,e),function(){this.toggleCommentLines=function(a,b,c,d){var e=!0,f=[],g=/^(\s*)\/\//;for(var h=c;h<=d;h++)if(!g.test(b.getLine(h))){e=!1;break}if(e){var j=new i(0,0,0,0);for(var h=c;h<=d;h++){var k=b.getLine(h),l=k.match(g);j.start.row=h,j.end.row=h,j.end.column=l[0].length,b.replace(j,l[1])}}else b.indentRows(c,d,"//")},this.getNextLineIndent=function(a,b,c){var d=this.$getIndent(b),e=this.$tokenizer.getLineTokens(b,a),f=e.tokens,g=e.state;if(f.length&&f[f.length-1].type=="comment")return d;if(a=="start"){var h=b.match(/^.*[\{\(\[]\s*$/);h&&(d+=c)}else if(a=="doc-start"){if(g=="start")return"";var h=b.match(/^\s*(\/?)\*/);h&&(h[1]&&(d+=" "),d+="* ")}return d},this.checkOutdent=function(a,b,c){return this.$outdent.checkOutdent(b,c)},this.autoOutdent=function(a,b,c){this.$outdent.autoOutdent(b,c)},this.createWorker=function(a){var b=a.getDocument(),c=new j(["ace","pilot"],"worker-javascript.js","ace/mode/javascript_worker","JavaScriptWorker");c.call("setValue",[b.getValue()]),b.on("change",function(a){a.range={start:a.data.range.start,end:a.data.range.end},c.emit("change",a)}),c.on("jslint",function(b){var c=[];for(var d=0;d<b.data.length;d++){var e=b.data[d];e&&c.push({row:e.line-1,column:e.character-1,text:e.reason,type:"warning",lint:e})}a.setAnnotations(c)}),c.on("narcissus",function(b){a.setAnnotations([b.data])}),c.on("terminate",function(){a.clearAnnotations()});return c}}.call(k.prototype),b.Mode=k}),define("ace/mode/javascript_highlight_rules",function(a,b,c){var d=a("pilot/oop"),e=a("pilot/lang"),f=a("ace/mode/doc_comment_highlight_rules").DocCommentHighlightRules,g=a("ace/mode/text_highlight_rules").TextHighlightRules;JavaScriptHighlightRules=function(){var a=new f,b=e.arrayToMap("break|case|catch|continue|default|delete|do|else|finally|for|function|if|in|instanceof|new|return|switch|throw|try|typeof|var|while|with".split("|")),c=e.arrayToMap("null|Infinity|NaN|undefined".split("|")),d=e.arrayToMap("class|enum|extends|super|const|export|import|implements|let|private|public|yield|interface|package|protected|static".split("|"));this.$rules={start:[{token:"comment",regex:"\\/\\/.*$"},a.getStartRule("doc-start"),{token:"comment",regex:"\\/\\*",next:"comment"},{token:"string.regexp",regex:"[/](?:(?:\\[(?:\\\\]|[^\\]])+\\])|(?:\\\\/|[^\\]/]))*[/]\\w*\\s*(?=[).,;]|$)"},{token:"string",regex:'["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]'},{token:"string",regex:'["].*\\\\$',next:"qqstring"},{token:"string",regex:"['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']"},{token:"string",regex:"['].*\\\\$",next:"qstring"},{token:"constant.numeric",regex:"0[xX][0-9a-fA-F]+\\b"},{token:"constant.numeric",regex:"[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b"},{token:"constant.language.boolean",regex:"(?:true|false)\\b"},{token:function(a){return a=="this"?"variable.language":b.hasOwnProperty(a)?"keyword":c.hasOwnProperty(a)?"constant.language":d.hasOwnProperty(a)?"invalid.illegal":a=="debugger"?"invalid.deprecated":"identifier"},regex:"[a-zA-Z_$][a-zA-Z0-9_$]*\\b"},{token:"keyword.operator",regex:"!|\\$|%|&|\\*|\\-\\-|\\-|\\+\\+|\\+|~|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\\|\\||\\?\\:|\\*=|%=|\\+=|\\-=|&=|\\^=|\\b(?:in|instanceof|new|delete|typeof|void)"},{token:"lparen",regex:"[[({]"},{token:"rparen",regex:"[\\])}]"},{token:"text",regex:"\\s+"}],comment:[{token:"comment",regex:".*?\\*\\/",next:"start"},{token:"comment",regex:".+"}],qqstring:[{token:"string",regex:'(?:(?:\\\\.)|(?:[^"\\\\]))*?"',next:"start"},{token:"string",regex:".+"}],qstring:[{token:"string",regex:"(?:(?:\\\\.)|(?:[^'\\\\]))*?'",next:"start"},{token:"string",regex:".+"}]},this.addRules(a.getRules(),"doc-"),this.$rules["doc-start"][0].next="start"},d.inherits(JavaScriptHighlightRules,g),b.JavaScriptHighlightRules=JavaScriptHighlightRules}),define("ace/mode/doc_comment_highlight_rules",function(a,b,c){var d=a("pilot/oop"),e=a("ace/mode/text_highlight_rules").TextHighlightRules,f=function(){this.$rules={start:[{token:"comment.doc",regex:"\\*\\/",next:"start"},{token:"comment.doc.tag",regex:"@[\\w\\d_]+"},{token:"comment.doc",regex:"s+"},{token:"comment.doc",regex:"TODO"},{token:"comment.doc",regex:"[^@\\*]+"},{token:"comment.doc",regex:"."}]}};d.inherits(f,e),function(){this.getStartRule=function(a){return{token:"comment.doc",regex:"\\/\\*(?=\\*)",next:a}}}.call(f.prototype),b.DocCommentHighlightRules=f}),define("ace/worker/worker_client",function(a,b,c){var d=a("pilot/oop"),e=a("pilot/event_emitter").EventEmitter,f=function(b,c,d,e){this.callbacks=[];if(a.packaged)var f=this.$guessBasePath(),g=this.$worker=new Worker(f+c);else{var h=a.nameToUrl("ace/worker/worker",null,"_"),g=this.$worker=new Worker(h),i={};for(var j=0;j<b.length;j++){var k=b[j];i[k]=a.nameToUrl(k,null,"_").replace(/.js$/,"")}}this.$worker.postMessage({init:!0,tlns:i,module:d,classname:e}),this.callbackId=1,this.callbacks={};var l=this;this.$worker.onerror=function(a){console.log(a);throw a},this.$worker.onmessage=function(a){var b=a.data;switch(b.type){case"log":window.console&&console.log&&console.log(b.data);break;case"event":l._dispatchEvent(b.name,{data:b.data});break;case"call":var c=l.callbacks[b.id];c&&(c(b.data),delete l.callbacks[b.id])}}};(function(){d.implement(this,e),this.$guessBasePath=function(){var a=document.getElementsByTagName("script");for(var b=0;b<a.length;b++){var c=a[b].src.match(/^(.*\/)ace\.js$/);if(c)return c[1]}return""},this.terminate=function(){this._dispatchEvent("terminate",{}),this.$worker.terminate()},this.send=function(a,b){this.$worker.postMessage({command:a,args:b})},this.call=function(a,b,c){if(c){var d=this.callbackId++;this.callbacks[d]=c,b.push(d)}this.send(a,b)},this.emit=function(a,b){this.$worker.postMessage({event:a,data:b})}}).call(f.prototype),b.WorkerClient=f}),define("ace/mode/css",function(a,b,c){var d=a("pilot/oop"),e=a("ace/mode/text").Mode,f=a("ace/tokenizer").Tokenizer,g=a("ace/mode/css_highlight_rules").CssHighlightRules,h=a("ace/mode/matching_brace_outdent").MatchingBraceOutdent,i=function(){this.$tokenizer=new f((new g).getRules()),this.$outdent=new h};d.inherits(i,e),function(){this.getNextLineIndent=function(a,b,c){var d=this.$getIndent(b),e=this.$tokenizer.getLineTokens(b,a).tokens;if(e.length&&e[e.length-1].type=="comment")return d;var f=b.match(/^.*\{\s*$/);f&&(d+=c);return d},this.checkOutdent=function(a,b,c){return this.$outdent.checkOutdent(b,c)},this.autoOutdent=function(a,b,c){this.$outdent.autoOutdent(b,c)}}.call(i.prototype),b.Mode=i}),define("ace/mode/css_highlight_rules",function(a,b,c){var d=a("pilot/oop"),e=a("pilot/lang"),f=a("ace/mode/text_highlight_rules").TextHighlightRules,g=function(){function g(a){var b=[],c=a.split("");for(var d=0;d<c.length;d++)b.push("[",c[d].toLowerCase(),c[d].toUpperCase(),"]");return b.join("")}var a=e.arrayToMap("-moz-box-sizing|-webkit-box-sizing|azimuth|background-attachment|background-color|background-image|background-position|background-repeat|background|border-bottom-color|border-bottom-style|border-bottom-width|border-bottom|border-collapse|border-color|border-left-color|border-left-style|border-left-width|border-left|border-right-color|border-right-style|border-right-width|border-right|border-spacing|border-style|border-top-color|border-top-style|border-top-width|border-top|border-width|border|bottom|box-sizing|caption-side|clear|clip|color|content|counter-increment|counter-reset|cue-after|cue-before|cue|cursor|direction|display|elevation|empty-cells|float|font-family|font-size-adjust|font-size|font-stretch|font-style|font-variant|font-weight|font|height|left|letter-spacing|line-height|list-style-image|list-style-position|list-style-type|list-style|margin-bottom|margin-left|margin-right|margin-top|marker-offset|margin|marks|max-height|max-width|min-height|min-width|-moz-border-radius|opacity|orphans|outline-color|outline-style|outline-width|outline|overflow|overflow-x|overflow-y|padding-bottom|padding-left|padding-right|padding-top|padding|page-break-after|page-break-before|page-break-inside|page|pause-after|pause-before|pause|pitch-range|pitch|play-during|position|quotes|richness|right|size|speak-header|speak-numeral|speak-punctuation|speech-rate|speak|stress|table-layout|text-align|text-decoration|text-indent|text-shadow|text-transform|top|unicode-bidi|vertical-align|visibility|voice-family|volume|white-space|widows|width|word-spacing|z-index".split("|")),b=e.arrayToMap("rgb|rgba|url|attr|counter|counters".split("|")),c=e.arrayToMap("absolute|all-scroll|always|armenian|auto|baseline|below|bidi-override|block|bold|bolder|border-box|both|bottom|break-all|break-word|capitalize|center|char|circle|cjk-ideographic|col-resize|collapse|content-box|crosshair|dashed|decimal-leading-zero|decimal|default|disabled|disc|distribute-all-lines|distribute-letter|distribute-space|distribute|dotted|double|e-resize|ellipsis|fixed|georgian|groove|hand|hebrew|help|hidden|hiragana-iroha|hiragana|horizontal|ideograph-alpha|ideograph-numeric|ideograph-parenthesis|ideograph-space|inactive|inherit|inline-block|inline|inset|inside|inter-ideograph|inter-word|italic|justify|katakana-iroha|katakana|keep-all|left|lighter|line-edge|line-through|line|list-item|loose|lower-alpha|lower-greek|lower-latin|lower-roman|lowercase|lr-tb|ltr|medium|middle|move|n-resize|ne-resize|newspaper|no-drop|no-repeat|nw-resize|none|normal|not-allowed|nowrap|oblique|outset|outside|overline|pointer|progress|relative|repeat-x|repeat-y|repeat|right|ridge|row-resize|rtl|s-resize|scroll|se-resize|separate|small-caps|solid|square|static|strict|super|sw-resize|table-footer-group|table-header-group|tb-rl|text-bottom|text-top|text|thick|thin|top|transparent|underline|upper-alpha|upper-latin|upper-roman|uppercase|vertical-ideographic|vertical-text|visible|w-resize|wait|whitespace|zero".split("|")),d=e.arrayToMap("aqua|black|blue|fuchsia|gray|green|lime|maroon|navy|olive|orange|purple|red|silver|teal|white|yellow".split("|")),f="\\-?(?:(?:[0-9]+)|(?:[0-9]*\\.[0-9]+))";this.$rules={start:[{token:"comment",regex:"\\/\\*",next:"comment"},{token:"string",regex:'["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]'},{token:"string",regex:"['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']"},{token:"constant.numeric",regex:f+g("em")},{token:"constant.numeric",regex:f+g("ex")},{token:"constant.numeric",regex:f+g("px")},{token:"constant.numeric",regex:f+g("cm")},{token:"constant.numeric",regex:f+g("mm")},{token:"constant.numeric",regex:f+g("in")},{token:"constant.numeric",regex:f+g("pt")},{token:"constant.numeric",regex:f+g("pc")},{token:"constant.numeric",regex:f+g("deg")},{token:"constant.numeric",regex:f+g("rad")},{token:"constant.numeric",regex:f+g("grad")},{token:"constant.numeric",regex:f+g("ms")},{token:"constant.numeric",regex:f+g("s")},{token:"constant.numeric",regex:f+g("hz")},{token:"constant.numeric",regex:f+g("khz")},{token:"constant.numeric",regex:f+"%"},{token:"constant.numeric",regex:f},{token:"constant.numeric",regex:"#[a-fA-F0-9]{6}"},{token:"constant.numeric",regex:"#[a-fA-F0-9]{3}"},{token:"lparen",regex:"{"},{token:"rparen",regex:"}"},{token:function(e){return a.hasOwnProperty(e.toLowerCase())?"support.type":b.hasOwnProperty(e.toLowerCase())?"support.function":c.hasOwnProperty(e.toLowerCase())?"support.constant":d.hasOwnProperty(e.toLowerCase())?"support.constant.color":"text"},regex:"\\-?[a-zA-Z_][a-zA-Z0-9_\\-]*"}],comment:[{token:"comment",regex:".*?\\*\\/",next:"start"},{token:"comment",regex:".+"}]}};d.inherits(g,f),b.CssHighlightRules=g}),define("ace/mode/html_highlight_rules",function(a,b,c){var d=a("pilot/oop"),e=a("ace/mode/css_highlight_rules").CssHighlightRules,f=a("ace/mode/javascript_highlight_rules").JavaScriptHighlightRules,g=a("ace/mode/text_highlight_rules").TextHighlightRules,h=function(){this.$rules={start:[{token:"text",regex:"<\\!\\[CDATA\\[",next:"cdata"},{token:"xml_pe",regex:"<\\?.*?\\?>"},{token:"comment",regex:"<\\!--",next:"comment"},{token:"text",regex:"<(?=s*script)",next:"script"},{token:"text",regex:"<(?=s*style)",next:"css"},{token:"text",regex:"<\\/?",next:"tag"},{token:"text",regex:"\\s+"},{token:"text",regex:"[^<]+"}],script:[{token:"text",regex:">",next:"js-start"},{token:"keyword",regex:"[-_a-zA-Z0-9:]+"},{token:"text",regex:"\\s+"},{token:"string",regex:'".*?"'},{token:"string",regex:"'.*?'"}],css:[{token:"text",regex:">",next:"css-start"},{token:"keyword",regex:"[-_a-zA-Z0-9:]+"},{token:"text",regex:"\\s+"},{token:"string",regex:'".*?"'},{token:"string",regex:"'.*?'"}],tag:[{token:"text",regex:">",next:"start"},{token:"keyword",regex:"[-_a-zA-Z0-9:]+"},{token:"text",regex:"\\s+"},{token:"string",regex:'".*?"'},{token:"string",regex:"'.*?'"}],cdata:[{token:"text",regex:"\\]\\]>",next:"start"},{token:"text",regex:"\\s+"},{token:"text",regex:".+"}],comment:[{token:"comment",regex:".*?-->",next:"start"},{token:"comment",regex:".+"}]};var a=(new f).getRules();this.addRules(a,"js-"),this.$rules["js-start"].unshift({token:"comment",regex:"\\/\\/.*(?=<\\/script>)",next:"tag"},{token:"text",regex:"<\\/(?=script)",next:"tag"});var b=(new e).getRules();this.addRules(b,"css-"),this.$rules["css-start"].unshift({token:"text",regex:"<\\/(?=style)",next:"tag"})};d.inherits(h,g),b.HtmlHighlightRules=h})
