var $=(function(){var original$=window.$,monthNames=['January','Fabruary','March','April','May','June','July','August','September','October','November','December'];var addCls,hasCls,removeCls,loadDataset,addListener,removeListener;if(document.body.classList){addCls=function(cls){this.classList.add(cls);};hasCls=function(cls){return this.classList.contains(cls);};removeCls=function(cls){this.classList.remove(cls);};}else{addCls=function(cls){var list=this.className.split(' ');this.className=$.include(list,cls).join(' ');};hasCls=function(cls){return $.contains(this.className.split(' '),cls);};removeCls=function(cls){var list=this.className.split(' ');this.className=$.remove(list,cls).join(' ');};}if(document.body.dataset){loadDataset=function(element,output){$.eachKey(element.dataset,function(e,i){output[i]=e;});}}else{loadDataset=function(element,output){$.each(element.attributes,function(e){if(e.name.match(/^data-/)){output[e.name.substr(5)]=e.value;}});}}function event(e){e=e||window.event;var delta=e.wheelDelta||-e.detail||e.delta;delta=delta?(delta>0?1:-1):0;return{x:e.pageX,y:e.pageY,event:e,button:e.button,ctrl:e.ctrlKey,alt:e.altKey,shift:e.shiftKey,meta:e.metaKey,key:e.keyCode||e.charCode,target:$(e.target||e.srcElement),relatedTarget:$(e.relatedTarget||e.toElement),delta:delta?(delta>0?1:-1):0,cancel:function(){e.returnValue=false;e.cancelBubble=true;if(e.stopPropagation){e.stopPropagation();e.preventDefault();}}};}function extract(e){if(!$.isDef(e)||$.isBool(e)||$.isNum(e))e+='';if(e.div)return extract(e.div);if(e.element)return extract(e.element);if($.isElem(e))return e;if($.isStr(e))return document.createTextNode(e);return extract($(e));}function filter(nodeList,selector){var result=nodeList;if(selector){selector=selector.split('.');var tagName=selector[0].toUpperCase(),className=selector[1];result=$.filter(nodeList,function(e){return e.tagName&&e.tagName==tagName&&((!className)||(className==e.className));});}return $.map(result,function(e){return $(e);});}function pushParam(value,key){if($.isDef(value)){if($.isJson(value)){$.eachKey(value,function(e,i){pushParam.call(this,e,key+'['+i+']');},this);}else if($.isArray(value)){$.each(value,function(e,i){pushParam.call(this,e,key+'['+i+']');},this);}else{this[key]=value||'';}}}if(window.attachEvent){addListener=function(element,name,callback){element.attachEvent('on'+name,callback);};removeListener=function(element,name,callback){element.detachEvent('on'+name,callback);};}else{addListener=function(element,name,callback){element.addEventListener(name,callback,false);};removeListener=function(element,name,callback){element.removeEventListener(name,callback,false);};}var $=function(a,properties){if(this instanceof $){var that=this,element=that.element=a;that.element.foobarInstance=that;$.extend(that,{add:function(){$.each($.flatten(arguments),function(e){element.appendChild(extract(e));});return that;},addCls:function(){$.each($.flatten(arguments),addCls,element);return that;},clr:function(){return that.width(that.width()).val(null);},cls:function(a){if(arguments.length){element.className=a;return that;}return element.className;},contains:function(element){element=extract(element);if(element){while(element){if(element==that.element)return true;element=element.parentNode;}}return false;},context:function(name){return element.getContext(name);},css:function(a){if($.isStr(a)){return element.style[a];}$.css(element,a);return that;},enabled:function(a){if(arguments.length){element.disabled=!a;return that;}return!element.disabled;},first:function(selector){return that.tags(selector)[0];},focus:function(){try{element.focus();var focusables=$.filter(that.tagsAll(),function(e){return e.element.offsetParent&&$.contains(['INPUT','SELECT','TEXTAREA'],e.element.tagName);});if(focusables[0]){focusables[0].element.focus();}}catch(e){}return that;},has:function(selector){return that.tags(selector).length>0;},hasCls:function(cls){return hasCls.call(element,cls);},height:function(a){if(arguments.length){element.height=a;return that;}return element.height||element.offsetHeight;},html:function(a){if(arguments.length){element.innerHTML=a;return that;}return element.innerHTML;},insert:function(element,before){if(that.has()){that.element.insertBefore(extract(element),extract(before||that.first()));}else{that.add(element);}return that;},last:function(selector){return $.reverse(that.tags(selector))[0];},name:function(a){if(arguments.length){element.name=a;return that;}return element.name;},next:function(selector){var tags1=that.parent().tags(),tags2=that.parent().tags(selector);for(var i=$.find(tags1,that)+1;i<tags1.length;i++){if($.contains(tags2,tags1[i])){return tags1[i];}}return null;},parent:function(){if(element.parentNode&&$.isDef(element.parentNode.innerHTML)){return $(element.parentNode);}},prev:function(selector){var tags1=that.parent().tags(),tags2=that.parent().tags(selector);for(var i=$.find(tags1,that)-1;i>=0;i--){if($.contains(tags2,tags1[i])){return tags1[i];}}return null;},readonly:function(a){if(arguments.length){element.readOnly=a;return that;}return element.readOnly;},remove:function(){try{$.each($.flatten(arguments),function(e){element.removeChild(extract(e));});}catch(e){}return that;},removeCls:function(){$.each($.flatten(arguments),removeCls,element);return that;},replace:function(){$.each(that.tags(),function(e){that.remove(e);});return that.add.apply(that,arguments);},scrollHeight:function(){return element.scrollHeight;},scrollLeft:function(a){if(arguments.length){element.scrollLeft=a;return that;}return element.scrollLeft||0;},scrollTop:function(a){if(arguments.length){element.scrollTop=a;return that;}return element.scrollTop||0;},scrollWidth:function(){return element.scrollWidth;},selectionStart:function(a){if(arguments.length){element.selectionStart=a;return that;}return element.selectionStart;},selectionEnd:function(a){if(arguments.length){element.selectionEnd=a;return that;}return element.selectionEnd;},src:function(a){if(arguments.length){element.src=element.href=a;return that;}if(element.toDataURL){return element.toDataURL();}return element.href||element.src;},tags:function(selector){return filter(element.childNodes,selector);},tagsAll:function(selector){return filter(element.getElementsByTagName('*'),selector);},val:function(a){var field=element.type=='checkbox'?'checked':'value';if(arguments.length){element[field]=a;return that;}return element[field];},width:function(a){if(arguments.length){element.width=a;return that;}return element.width||element.offsetWidth;},x:function(){var x;if(document.getBoxObjectFor){x=document.getBoxObjectFor(element).x;}else{x=element.getBoundingClientRect().left;}return x+$.document.html.scrollLeft()+$.document.body.scrollLeft();},y:function(){var y;if(document.getBoxObjectFor){y=document.getBoxObjectFor(element).y;}else{y=element.getBoundingClientRect().top;}return y+$.document.html.scrollTop()+$.document.body.scrollTop();}});$.eventify(that);that.on({addListener:function(eventName,callback){if(!callback.listener){callback.listener=function(e){callback.call(that,event(e));};}addListener(element,eventName,callback.listener);if(eventName=='mousewheel'){that.on('DOMMouseScroll',callback);}that.dataset={};loadDataset(element,that.dataset);},removeListener:function(eventName,callback){removeListener(element,eventName,callback.listener);if(eventName=='mousewheel'){that.un('DOMMouseScroll',callback);}}});}else{if(arguments.length==0){return $('');}if(arguments.length==1&&$.isJson(a)){properties=a;a='';}if($.isDef(a)){var that;if($.isObj(a)){var element=extract(a);if($.isStr(element.nodeValue))return element;if(element.foobarInstance)that=element.foobarInstance;else that=new $(element);}else if($.isStr(a)){if(/^#/.test(a)){return $(document.getElementById(a.substring(1)),properties);}var parts=a.split('.',2),element=document.createElement(parts[0]||'div');if(parts[1])element.className=parts[1];that=new $(element);}$.eachKey(properties,function(e,i){if(i=='add')that.add(e);else if(i=='cls')that.cls(e);else if(i=='css')that.css(e);else if(i=='html')that.html(e);else if(i=='on')that.on(e);else that.element[i]=e;});return that;}}};$.extend=function(subject){if($.isDef(subject)){for(var i=1;i<arguments.length;i++){if($.isDef(arguments[i])){for(var j in arguments[i]){subject[j]=arguments[i][j];}}}}return subject;};$.isDef=function(subject){return subject!==null&&subject!==undefined;};$.extend($,{DATE_DEFAULT:'y-m-d h:i:s.u',DATE_SQL_DATETIME:'y-m-d h:i:s',DATE_SQL_DATE:'y-m-d',keyboard:{ALT:18,BACKSPACE:8,CAPSLOCK:20,CTRL:17,DELETE:46,DOWN:40,END:35,ENTER:13,ESC:27,HOME:36,INSERT:45,LEFT:37,MINUS:109,PAGEDOWN:34,PAGEUP:33,PLUS:107,RIGHT:39,SHIFT:16,SPACE:32,TAB:9,UP:38},location:{hash:{},search:{}},addMonth:function(date,n){return new Date(date.getFullYear(),date.getMonth()+n,date.getDate(),date.getHours(),date.getMinutes(),date.getSeconds(),date.getMilliseconds());},addYear:function(date,n){return new Date(date.getFullYear()+n,date.getMonth(),date.getDate(),date.getHours(),date.getMinutes(),date.getSeconds(),date.getMilliseconds());},buildQuery:function(params,doNotEncode){var result={},resultString='';$.eachKey(params,pushParam,result);$.sortKey(result);if(doNotEncode)return result;$.eachKey(result,function(e,i){if(!$.isFunc(e)){if(resultString)resultString+='&';resultString+=$.urlencode(i)+'='+$.urlencode(e);}});return resultString;},combine:function(){arguments=$.flatten(arguments);arguments.unshift({});return $.extend.apply($,arguments);},contains:function(subject,element){return $.find(subject,element)!=-1;},css:function(element,styles){var style=element.style;$.eachKey(styles,function(value,i){try{if(i=='boxSizing'){style.MozBoxSizing=value;}else if(i=='cssFloat'){style.styleFloat=value;}else if(i=='display'){if(value=='box')style[i]='-moz-box';}else if(i=='opacity'){style.msFilter='progid:DXImageTransform.Microsoft.Alpha(Opacity='+(value*100)+')';style.filter='alpha(opacity='+(value*100)+')';}else if(i=='transition'){style.MozTransition=style.webkitTransition=style.oTransition=value;}else{if($.isNum(value))value=value+'px';}style[i]=value;}catch(e){}});},debounce:function(callback,milliseconds){var timeout;return function(){clearTimeout(timeout);timeout=setTimeout(callback,milliseconds);};},defer:function(callback){setTimeout(callback,0);},each:function(subject,callback,scope){if(subject){for(var i=0;i<subject.length;i++){callback.call(scope,subject[i],i,subject);}}return subject;},eachKey:function(subject,callback,scope){if(subject){for(var i in subject){callback.call(scope,subject[i],i,subject);}}return subject;},edit:function(subject,callback,scope){return $.each(subject,function(e,i){subject[i]=callback.call(scope,e,i,subject);});},eventify:function(subject){var listeners={};$.extend(subject,{on:function(a,b){if(arguments.length==0){return listeners;}if($.isStr(a)){if($.isFunc(b)){if(!listeners[a])listeners[a]=[];listeners[a].push(b);subject.on('addListener',a,b);}else{var eventArgs=$.map(arguments);eventArgs.shift();if(listeners[a]){for(var i=0;i<listeners[a].length;i++){if(listeners[a][i].apply(subject,eventArgs)===false){return false;}}}return true;}}else if($.isJson(a)){$.eachKey(a,function(e,i){subject.on(i,e);});}return subject;},un:function(eventName,callback){$.remove(listeners[eventName],callback);subject.on('removeListener',eventName,callback);return subject;}});return subject;},filter:function(subject,callback,scope){callback=callback||function(e){return!!e;};var result=[];$.each(subject,function(e,i){if(callback.call(scope,e,i,subject)){result.push(e);}});return result;},find:function(subject,element){for(var i=0;i<subject.length;i++){if(subject[i]===element)return i;}return-1;},flatten:function(){var result=[];$.each(arguments,function(e){if(e&&!$.isStr(e)&&!$.isElem(e)&&$.isInt(e.length)){e=$.map(e);result.push.apply(result,$.flatten.apply($,e));}else{result.push(e);}});return result;},formatDate:function(date,format){format=format||$.DATE_DEFAULT;var values={y:date.getFullYear(),Y:date.getFullYear()%100,m:$.lpad(date.getMonth()+1,2),M:date.getMonth()+1,d:$.lpad(date.getDate(),2),D:date.getDate(),a:date.getHours()<12?'am':'pm',A:date.getHours()<12?'AM':'PM',h:$.lpad(date.getHours(),2),H:date.getHours(),g:$.lpad(date.getHours()%12,2),G:date.getHours()%12,i:$.lpad(date.getMinutes(),2),s:$.lpad(date.getSeconds(),2),u:$.lpad(date.getMilliseconds(),3)};return format.replace(/[yYmMdDaAhHgGisu]/g,function(c){return values[c];});},own:function(subject,property){if(Object.prototype.hasOwnProperty.call(subject,property)){return subject[property];}},pushHash:function(name,value){$.location.hash[name]=value;var query=$.buildQuery($.location.hash,true),params=[];$.eachKey(query,function(e,i){params.push(i+'='+e);});location='#'+params.join('&');},hex:function(subject,length){var result='';for(var i=0;i<length;i++){result=(subject&15).toString(16)+result;subject>>>=4;}return result;},include:function(list,element){if(!$.contains(list,element)){list.push(element);}return list;},isArray:function(subject){return subject&&subject.constructor==Array;},isBool:function(subject){return typeof subject=='boolean';},isElem:function(subject){return subject&&subject.childNodes;},isFunc:function(subject){return typeof subject=='function';},isJson:function(subject){return subject&&subject.constructor==Object;},isInt:function(subject){return isFinite(subject)&&Math.floor(subject)==subject;},isNatural:function(subject){return $.isInt(subject)&&subject>0;},isNum:function(subject){return typeof subject=='number';},isObj:function(subject){return typeof subject=='object';},isStr:function(subject){return typeof subject=='string';},last:function(subject){if(subject)return subject[subject.length-1];},load:function(e){function load(item,resource){$.remove(items,item);if(e.progress)e.progress(resource);if(!items.length&&e.load)e.load();}var items=[];$.each(e.images,function(e){var image=new Image();items.push(image);image.onload=function(){image.onload=null;load(image);};image.src=e;});$.each(e.scripts,function(e){var script=$.Script(e).on('load',function(){load(script);});items.push(script);});},lpad:function(subject,length,ch){subject+='';ch=ch||'0';while(subject.length<length)subject=ch+subject;return subject;},ltrim:function(subject){return subject.replace(/^\s+/,'');},map:function(subject,callback){callback=callback||function(e){return e;};var result=new Array(subject.length);$.each(subject,function(e,i){result[i]=callback.call(subject,e,i);});return result;},max:function(){return Math.max.apply(Math,$.flatten(arguments));},median:function(){var array=$.flatten(arguments).sort();if(array.length%2==0){return(array[array.length/2]+array[array.length/2-1])/2;}else{return array[Math.floor(array.length/2)];}},min:function(){return Math.min.apply(Math,$.flatten(arguments));},mod:function(a,b){return(a<0?b+a%b:a)%b;},monthLength:function(a,b){if(arguments.length==2)a=new Date(a,b,0);return new Date(a.getFullYear(),a.getMonth()+1,0).getDate();},monthName:function(date){return monthNames[date.getMonth()];},noConflict:function(){window.$=original$;},parseDate:function(input,format,def){function read(n){var s=input.substr(0,n);input=input.substr(n);if(s.match(/^\d+$/))return+s;return null;}format=format||$.DATE_DEFAULT;var j,c,y=0,m=1,d=1,h=0,i=0,s=0,u=0;for(j=0;j<format.length;j++){c=format[j];if(c=='y')y=read(4);else if(c=='m')m=read(2)-1;else if(c=='d')d=read(2);else if(c=='h')h=read(2);else if(c=='i')i=read(2);else if(c=='s')s=read(2);else if(c=='u')u=read(3);else if(c==input[0])input=input.substr(1);else break;}return new Date(y,m,d,h,i,s,u);},parseQuery:function(input,plain){input=input.replace(/^[#?]/,'');var params={};$.each(input.split('&'),function(e){e=e.split('=');if(plain)params[e[0]]=e[1];else params[$.urldecode(e[0])]=$.urldecode(e[1]);});return params;},pluck:function(subject,field){var fields=field.split(/\./g);$.each(fields,function(field){subject=$.map(subject,function(e){if($.isDef(e))return e[field];});});return subject;},random:function(a,b){var random=Math.random();if(arguments.length==0)return random;if($.isInt(a)){if($.isInt(b)){return Math.floor(a+random*(b-a));}return Math.floor(random*a);}if($.isArray(a)){if($.isNatural(b)){return $.shuffle(a).splice(0,b);}return a[Math.floor(random*a.length)];}},range:function(min,max){var result=[];for(var i=min;i<=max;i++){result.push(i);}return result;},remove:function(list,element){if(list){for(var i=0;i<list.length;i++){if(list[i]===element){list.splice(i,1);break;}}}return list;},reverse:function(subject){if($.isStr(subject)){return subject.split('').reverse().join('');}else if($.isArray(subject)){return subject.reverse();}},rpad:function(subject,length,ch){subject+='';ch=ch||'0';while(subject.length<length)subject+=ch;return subject;},rtrim:function(subject){return subject.replace(/\s+$/,'');},shortcut:function(shortcut,callback){var keys=shortcut.split('-'),alt=$.contains(keys,'ALT'),ctrl=$.contains(keys,'CTRL'),meta=$.contains(keys,'META'),shift=$.contains(keys,'SHIFT');$.remove(keys,'ALT');$.remove(keys,'CTRL');$.remove(keys,'META');$.remove(keys,'SHIFT');var key=keys[0];if($.isStr(key)){if(key.length==1){key=key.toUpperCase().charCodeAt(0);}else{key=$.keyboard[key];}}$.on('keydown',function(e){if(e.alt==alt&&e.ctrl==ctrl&&e.meta==meta&&e.shift==shift&&e.key==key){return callback(e);}});return $;},shuffle:function(subject){return $.map(subject).sort(function(){return Math.random()<0.5?1:0;});},sort:function(subject,callback){callback=callback||function(a,b){return a>b?1:-1;};Array.prototype.sort.call(subject,callback);return subject;},sortKey:function(subject,callback){callback=callback||function(a,b){return a>b?1:-1;};var keys=[],subjectCopy={};$.eachKey(subject,function(e,i){keys.push(i);subjectCopy[i]=e;delete subject[i];});$.sort(keys,callback);$.each(keys,function(key){subject[key]=subjectCopy[key];});return subject;},submit:function(url,params,target){var form=$('form',{method:'post',action:url,target:target||'_self',css:{display:'none'}});$.eachKey($.buildQuery(params,true),function(e,i){form.add($('input',{type:'hidden',name:i,value:e}));});$.document.body.add(form);form.element.submit();$.document.body.remove(form);},throttle:function(callback,milliseconds){var timeout,next,throttled=function(){if(timeout)next=true;else{callback();timeout=setTimeout(function(){timeout=0;if(next)throttled();next=false;},milliseconds);}};return throttled;},title:function(a){if(arguments.length){$.document.title.html(a);return $;}return $.document.title.html();},trim:function(subject){return subject.replace(/^\s*(.*)\s*$/,'$1');},urldecode:function(input){return decodeURIComponent(input);},urlencode:function(input){return encodeURIComponent(input);},utf8decode:function(ascii){return $.urldecode(escape(ascii));},utf8encode:function(unicode){return unescape($.urlencode(unicode));}});for(var i=0;i<12;i++){$.keyboard['F'+(i+1)]=112+i;}$.eventify($);$.document=$(document).on({keydown:function(e){$.on('keydown',e);},keyup:function(e){$.on('keyup',e);},keypress:function(e){$.on('keypress',e);},mousedown:function(e){$.on('mousedown',e);},mousemove:function(e){$.on('mousemove',e);},mouseup:function(e){$.on('mouseup',e);}});$.document.html=$.document.first('html');$.document.body=$(document.body).on('mousewheel',function(e){$.on('mousewheel',e);});$.document.head=$.document.html.first('head');$.document.title=$.document.head.first('title');$.height=$.document.body.height;$.width=$.document.body.width;function hashChange(){$.location.hash=$.parseQuery(location.hash,true);$.on('hashchange',$.location.hash);}addListener(window,'hashchange',hashChange);addListener(window,'load',function(){$.location.search=$.parseQuery(location.search);$.on('load',$.location.search);hashChange();},false);addListener(window,'resize',function(e){$.on('resize');},false);setInterval(function(){$.on('tick');},40);return $;})();window.Foobar=$;
(function($){$.Field=function(initialValue,commit){var value=initialValue,that=function(a){if(arguments.length){if(that.on('change',a)){value=a;that.on('commit',a);}return this;}return value;};$.extend(that,{add:function(increment){return that(value+increment);},flip:function(){return that(!value);}});$.eventify(that);that.on('commit',commit);return that;};})($);
(function($){$.ajax=function(config){config=config||{};var ajax=$.Ajax(config.url).on({complete:config.complete,success:config.success,fail:config.fail,object:config.object});if($.isArray(config.params)){config.params.unshift({});config.params=$.extend.apply($,config.params);}if(config.method=='get'){ajax.get(config.params);}else{ajax.post(config.params);}return ajax;};$.Ajax=function(path,defaultParams){function load(xhr,queryString){that.busy=false;that.on('complete',xhr);if(xhr.status==200||xhr.status==304){if(that.cache()){cache[queryString]=xhr;}var contentType=xhr.getResponseHeader('Content-Type');if(contentType=='application/json'){that.on('object',JSON.parse(xhr.responseText));}that.on('success',xhr);}else{that.on('fail',xhr);}}function performRequest(method,params){lastMethod=method;lastParams=params;that.busy=true;params=$.combine.apply($,$.flatten([defaultParams,params]));var queryString=$.buildQuery(params);if(that.cache()&&cache[queryString]){load(cache[queryString],queryString);}else{var xhr=new XMLHttpRequest();xhr.onreadystatechange=function(){if(xhr.readyState==4){load(xhr,queryString);}};if(method=='get'){xhr.open('get',path+'?'+queryString,true);xhr.send(null);}else{xhr.open('post',path,true);xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');xhr.send(queryString);}}return that;}path=path||'';var cache={},lastMethod='get',lastParams={},that=$.eventify({busy:false,cache:$.Field(false),clearCache:function(){cache={};return that;},get:function(params){return performRequest('get',params);},post:function(params){return performRequest('post',params);},reload:function(){return performRequest(lastMethod,lastParams);}});return that;};})($);
(function($){var popups=$();$.document.body.add(popups);$.Popup=function(cls){function refresh(){if(that.visible()){that.css({width:width==null?'auto':width,height:height==null?'auto':height});if(that.constraint){that.css({left:that.alignerX(that.constraint,that),top:that.alignerY(that.constraint,that)});}else{that.css({left:x,top:y});}}return that;}cls=cls||'Popup';var container,width,height,x,y,that=$({cls:cls,css:{position:'absolute'}});$.extend(that,{constraint:null,alignerX:null,alignerY:null,container:$.Field(popups,function(e){container=e||popups;if(that.visible())that.hide().show();}),visible:$.Field(false,function(e){that.css({display:e?'block':'none'});if(e){if(!that.parent()){container.add(that);$.on('resize',refresh);}}else{container.remove(that);$.un('resize',refresh);}refresh();}),hide:function(){return that.visible(false);},promote:function(){try{if(container.last()!=that){container.remove(that);container.add(that);}}catch(e){}return that;},setConstraint:function(constraint,alignerX,alignerY){that.constraint=$(constraint);that.alignerX=$.isStr(alignerX)?$.Popup[alignerX]:alignerX;that.alignerY=$.isStr(alignerY)?$.Popup[alignerY]:alignerY;return refresh();},setLocation:function(a,b){x=a;y=b;return refresh();},setSize:function(a,b){width=a;height=b;return refresh();},show:function(){return that.visible(true);}});that.visible.on('commit',function(e){that.on(e?'show':'hide');});return that.container(popups).hide();};$.extend($.Popup,{X_CENTER:function(c,d){return c.x()+(c.width()-d.width())/2;},Y_CENTER:function(c,d){return c.y()+(c.height()-d.height())/2;},WEST_OUTSIDE:function(c,d){return c.x()-d.width();},WEST_INSIDE:function(c,d){return c.x();},EAST_INSIDE:function(c,d){return c.x()+c.width()-d.width();},EAST_OUTSIDE:function(c,d){return c.x()+c.width();},NORTH_OUTSIDE:function(c,d){return c.y()-d.height();},NORTH_INSIDE:function(c,d){return c.y();},SOUTH_INSIDE:function(c,d){return c.y()+c.height()-d.height();},SOUTH_OUTSIDE:function(c,d){return c.y()+c.height();}});})($);
(function($){var overlays=$();$.document.body.add(overlays);$.Overlay=function(constraint,cls){function resize(){if(that.visible()){that.css({left:constraint.x(),top:constraint.y(),width:constraint.width(),height:constraint.height()});}}cls=cls||'Overlay';constraint=$(constraint||$.document.body);var that=$({cls:cls,css:{position:'absolute'}});return $.extend(that,{visible:$.Field(false,function(e){$.un('resize',resize);if(e){if(!that.element.parent){overlays.add(that);}that.focus();$.on('resize',resize);}else{overlays.remove(that);}resize();}),hide:function(){return that.visible(false);},show:function(){return that.visible(true);}});};})($);
(function($){$.tween=function(config){return $.Tween(config).foreward();};$.Tween=function(config){function change(){var e=tweener(that.current()/frames);that.on('change',that.from()+(that.to()-that.from())*e);}function tick(){if(that.delay()>0){that.delay.add(-1);}else if(that.direction()>0){change();if(that.current()==frames)that.pause().on('finish');else that.current.add(1);}else if(that.direction()<0){change();if(that.current()==0)that.pause().on('finish');else that.current.add(-1);}}config=config||{};if(!$.isNum(config.to))config.to=1;var lastDirection=-1,frames=config.frames||30,tweener=config.tweener||$.Tween.NORMAL,that=$.eventify({current:$.Field(config.current||0),delay:$.Field(config.delay||0),loop:$.Field(config.loop),repeat:$.Field(config.repeat),from:$.Field(config.from||0),to:$.Field(config.to),direction:$.Field(0,function(e){$.un('tick',tick);if(e){lastDirection=e;$.on('tick',tick);}}),backward:function(){return that.direction(-1);},flip:function(){return that.direction(lastDirection==1?-1:1);},foreward:function(){return that.direction(1);},pause:function(){return that.direction(0);},resume:function(){return that.direction(lastDirection);}});if($.isStr(tweener))tweener=$.Tween[tweener];that.on({change:config.change,finish:config.finish,});that.on('finish',function(){if(that.loop())that.flip();if(that.repeat())that.current(0).resume();});return that;};$.extend($.Tween,{BOUNCE_IN:function(x){return(1-Math.abs(Math.cos(Math.pow(x,3)*5*Math.PI)))*(1-x)+x;},BOUNCE_OUT:function(x){return(Math.abs(Math.cos(Math.pow(1-x,3)*5*Math.PI))-1)*x+x;},ELASTIC_IN:function(x){return(1-Math.cos(Math.pow(x,3)*6*Math.PI))*(1-x)+x;},ELASTIC_OUT:function(x){return(Math.cos(Math.pow(x-1,3)*6*Math.PI)-1)*x+x;},NORMAL:function(x){return x;},STRONG_IN:function(x){return Math.pow(x,3);},STRONG_INOUT:function(x){if(x<=0.5)return Math.pow(2*x,3)/2;return Math.pow(2*x-2,3)/2+1;},STRONG_OUT:function(x){return Math.pow(x-1,3)+1;},STRONG_OUTIN:function(x){return Math.pow(2*x-1,3)/2+0.5;},RADIAL_IN:function(x){return 1-Math.sqrt(1-x*x);},RADIAL_OUT:function(x){return Math.sqrt(1-(x-1)*(x-1));},RADIAL_INOUT:function(x){if(x<=0.5)return(1-Math.sqrt(1-x*x*4))/2;return(1+Math.sqrt(1-Math.pow(x*2-2,2)))/2;},RADIAL_OUTIN:function(x){if(x<=0.5)return Math.sqrt(1-Math.pow(x*2-1,2))/2;return 1-Math.sqrt(1-Math.pow(x*2-1,2))/2;}});})($);
(function($){var weekdayNames=['S','M','T','W','T','F','S'];$.Calendar=function(cls){cls=cls||'Calendar';var Button=function(text,click){return{cls:cls+'-button',css:{display:'inline-block'},on:{click:click},add:text};},setVisibleDate=function(date){visibleDate=date;textDiv.html($.monthName(date).substr(0,3)+',\x20'+date.getFullYear());var prevMonthLength=$.monthLength($.addMonth(date,-1)),monthLength=$.monthLength(date),startWeekday=new Date(date.getFullYear(),date.getMonth(),1).getDay(),month=-1,day=prevMonthLength-startWeekday,selectionInThisMonth=that.val().getFullYear()==date.getFullYear()&&that.val().getMonth()==date.getMonth();$.each(daysDiv.tags(),function(e){$.each(e.tags(),function(e,i){day++;if(month==-1&&day>prevMonthLength){month=0;day=1;}if(month==0&&day>monthLength){month=1;day=1;}if(month==-1||month==1){e.cls(cls+'-empty');}else if(selectionInThisMonth&&date.getDate()==day){e.cls(cls+'-selected');}else{e.cls(cls+'-day');}e.html(day);e.date=new Date(date.getFullYear(),date.getMonth()+month,day);});});},visibleDate,textDiv=$({cls:cls+'-text'}),weeksDiv=$({cls:cls+'-weeks'}),daysDiv=$().add({add:textDiv},weeksDiv),i,j,row;for(i=0;i<7;i++){weeksDiv.add({cls:cls+'-week',css:{display:'inline-block'}});}for(i=0;i<6;i++){row=$();for(j=0;j<7;j++){row.add({css:{display:'inline-block'},on:{click:function(){that.val(this.date);}}});}daysDiv.add(row);}var that=$({cls:cls,add:[textDiv,weeksDiv,daysDiv,{add:{cls:cls+'-text',add:[ Button('\u00ab',function(){setVisibleDate($.addYear(visibleDate,-1));}),Button('\u2039',function(){setVisibleDate($.addMonth(visibleDate,-1));}),Button('Today',function(){that.val(new Date());}),Button('\u203a',function(){setVisibleDate($.addMonth(visibleDate,1));}),Button('\u00bb',function(){setVisibleDate($.addYear(visibleDate,1));})]}}]});$.extend(that,{val:$.Field(null,function(e){setVisibleDate(e);that.on('select',e);}),setWeekdayNames:function(names){$.each(weeksDiv.tags(),function(e,i){e.html(names[i]+'');});return that;}});return that.val(new Date()).setWeekdayNames(weekdayNames);};})($);
(function($){var width=7,height=7,COLORS=[[127,127,127]],m=[[0,1],[1,0],[1,0],[1,-1],[0,0],[0,0]];for(var i=0;i<6;i++){for(var j=0;j<6;j++){COLORS.push([ 255*(m[i][0]+m[i][1]*j/6),255*(m[(i+2)%6][0]+m[(i+2)%6][1]*j/6),255*(m[(i+4)%6][0]+m[(i+4)%6][1]*j/6)]);}}$.Palette=function(cls){cls=cls||'Palette';var createSample=function(r,g,b,w){var rs=$.lpad(r.toString(16),2),gs=$.lpad(g.toString(16),2),bs=$.lpad(b.toString(16),2),value={r:r,g:g,b:b,color:rs+gs+bs};return{css:{verticalAlign:'top',display:'inline-block',width:w||width,height:width,background:'#'+rs+gs+bs},on:{click:function(){that.on('select',value);},mouseover:function(){htmlcolor.html('#'+rs+gs+bs);}}};},htmlcolor=$({cls:cls+'-text',css:{fontFamily:'monospace'},add:'#000000'}),palettediv=$().add({add:createSample(0,0,0,width*COLORS.length)}),that=$({cls:cls,css:{display:'inline-block'},add:[palettediv,{add:htmlcolor}]});var i,j,r,g,b,div;for(i=1;i<=19;i++){div=$().css({lineHeight:0});palettediv.add(div);for(j=0;j<COLORS.length;j++){r=COLORS[j][0];g=COLORS[j][1];b=COLORS[j][2];if(i<=10){r=r*i/10;g=g*i/10;b=b*i/10;}else{r=r+(255-r)*(i-10)/10;g=g+(255-g)*(i-10)/10;b=b+(255-b)*(i-10)/10;}div.add(createSample(Math.round(r),Math.round(g),Math.round(b)));}}palettediv.add({add:createSample(255,255,255,width*COLORS.length)});$.each(palettediv.tags(),function(e){e.css({lineHeight:0});});return that;}})($);
(function($){$.Shape=function(config){config=config||{};var that=$.eventify({items:[],angle:$.Field(),opacity:$.Field(),scaleX:$.Field(),scaleY:$.Field(),visible:$.Field(),x:$.Field(),y:$.Field(),add:function(){$.each($.flatten(arguments),function(e){that.items.push(e);});return that;},path:function(c){that.transform(c);that.on('path',c);},paint:function(c){if(!that.visible())return that;c.save();c.beginPath();c.globalAlpha*=that.opacity();that.transform(c);c.save();that.on('paint',c);c.restore();$.each(that.items,function(e){e.paint(c);});c.restore();return that;},raise:function(name,c,e){c.save();c.beginPath();that.path(c);if(c.isPointInPath(e.x,e.y)){that.on(name,e);}c.restore();},reset:function(){that.opacity(1).angle(0).scaleX(1).scaleY(1).visible(true).x(0).y(0);return that;},transform:function(c){c.scale(that.scaleX(),that.scaleY());c.translate(that.x(),that.y());c.rotate(that.angle()*Math.PI/180);}});that.on({paint:config.paint,path:config.path});return that.reset();};})($);
(function($){$.PieChart=function(){var data=[],that=$.Shape({paint:function(c){var angle=0,innerRadius,outerRadius;c.save();$.each(data,function(e){angle=Math.PI*2*e.value;innerRadius=e.innerRadius||that.innerRadius();outerRadius=e.outerRadius||that.outerRadius();c.fillStyle=e.color=e.color||'#ff0';c.beginPath();c.moveTo(outerRadius,0);c.lineTo(innerRadius,0);c.arc(0,0,innerRadius,0,-angle,true);c.lineTo(Math.cos(angle)*outerRadius,-Math.sin(angle)*outerRadius);c.arc(0,0,outerRadius,-angle,0,false);c.fill();c.rotate(-angle);c.closePath();});c.restore();c.beginPath();$.each(data,function(e){angle=Math.PI*2*e.value;innerRadius=e.innerRadius||that.innerRadius();outerRadius=e.outerRadius||that.outerRadius();c.moveTo(outerRadius,0);c.lineTo(innerRadius,0);c.arc(0,0,innerRadius,0,-angle,true);c.lineTo(Math.cos(angle)*outerRadius,-Math.sin(angle)*outerRadius);c.arc(0,0,outerRadius,-angle,0,false);c.rotate(-angle);});c.globalAlpha/=3;c.strokeStyle='#fff';c.lineWidth=7;c.stroke();c.strokeStyle='#000';c.globalAlpha*=3;c.lineWidth=1;c.stroke();c.closePath();}});$.extend(that,{innerRadius:$.Field(40),outerRadius:$.Field(100),setData:function(e){data=e;return that;}});return that;};})($);

