JS={extend:function(a,b){b=b||{};for(var c in b){if(a[c]===b[c])continue;a[c]=b[c]}return a},makeFunction:function(){return function(){return this.initialize?(this.initialize.apply(this,arguments)||this):this}},makeBridge:function(a){var b=function(){};b.prototype=a.prototype;return new b},delegate:function(a,b){return function(){return this[a][b].apply(this[a],arguments)}},bind:function(){var a=JS.array(arguments),b=a.shift(),c=a.shift()||null;return function(){return b.apply(c,a.concat(JS.array(arguments)))}},callsSuper:function(a){return a.SUPER===undefined?a.SUPER=/\bcallSuper\b/.test(a.toString()):a.SUPER},mask:function(a){var b=a.toString().replace(/callSuper/g,'super');a.toString=function(){return b};return a},array:function(a){if(!a)return[];if(a.toArray)return a.toArray();var b=a.length,c=[];while(b--)c[b]=a[b];return c},indexOf:function(a,b){for(var c=0,d=a.length;c<d;c++){if(a[c]===b)return c}return-1},isFn:function(a){return a instanceof Function},ignore:function(a,b){return/^(include|extend)$/.test(a)&&typeof b==='object'}};JS.Module=JS.makeFunction();JS.extend(JS.Module.prototype,{initialize:function(a,b){b=b||{};this.__mod__=this;this.__inc__=[];this.__fns__={};this.__dep__=[];this.__res__=b._1||null;this.include(a||{})},define:function(a,b,c){c=c||{};this.__fns__[a]=b;if(JS.Module._0&&c._0&&JS.isFn(b))JS.Module._0(a,c._0);var d=this.__dep__.length;while(d--)this.__dep__[d].resolve()},instanceMethod:function(a){var b=this.lookup(a).pop();return JS.isFn(b)?b:null},include:function(a,b,c){if(!a)return c&&this.resolve();b=b||{};var d=a.include,f=a.extend,e,g,j,h,i=b._4||this;if(a.__inc__&&a.__fns__){this.__inc__.push(a);a.__dep__.push(this);if(b._2)a.extended&&a.extended(b._2);else a.included&&a.included(i)}else{if(b._5){for(h in a){if(JS.ignore(h,a[h]))continue;this.define(h,a[h],{_0:i||b._2||this})}}else{if(typeof d==='object'){e=[].concat(d);for(g=0,j=e.length;g<j;g++)i.include(e[g],b)}if(typeof f==='object'){e=[].concat(f);for(g=0,j=e.length;g<j;g++)i.extend(e[g],false);i.extend()}b._5=true;return i.include(a,b,c)}}c&&this.resolve()},includes:function(a){if(Object===a||this===a||this.__res__===a.prototype)return true;var b=this.__inc__.length;while(b--){if(this.__inc__[b].includes(a))return true}return false},ancestors:function(a){a=a||[];for(var b=0,c=this.__inc__.length;b<c;b++)this.__inc__[b].ancestors(a);var d=(this.__res__||{}).klass,f=(d&&this.__res__===d.prototype)?d:this;if(JS.indexOf(a,f)===-1)a.push(f);return a},lookup:function(a){var b=this.ancestors(),c=[],d,f,e;for(d=0,f=b.length;d<f;d++){e=b[d].__mod__.__fns__[a];if(e)c.push(e)}return c},make:function(a,b){if(!JS.isFn(b)||!JS.callsSuper(b))return b;var c=this;return function(){return c.chain(this,a,arguments)}},chain:JS.mask(function(c,d,f){var e=this.lookup(d),g=e.length-1,j=c.callSuper,h=JS.array(f),i;c.callSuper=function(){var a=arguments.length;while(a--)h[a]=arguments[a];g-=1;var b=e[g].apply(c,h);g+=1;return b};i=e.pop().apply(c,h);j?c.callSuper=j:delete c.callSuper;return i}),resolve:function(a){var a=a||this,b=a.__res__,c,d,f,e;if(a===this){c=this.__dep__.length;while(c--)this.__dep__[c].resolve()}if(!b)return;for(c=0,d=this.__inc__.length;c<d;c++)this.__inc__[c].resolve(a);for(f in this.__fns__){e=a.make(f,this.__fns__[f]);if(b[f]!==e)b[f]=e}}});JS.ObjectMethods=new JS.Module({__eigen__:function(){if(this.__meta__)return this.__meta__;var a=this.__meta__=new JS.Module({},{_1:this});a.include(this.klass.__mod__);return a},extend:function(a,b){return this.__eigen__().include(a,{_2:this},b!==false)},isA:function(a){return this.__eigen__().includes(a)},method:function(a){var b=this,c=b.__mcache__=b.__mcache__||{};if((c[a]||{}).fn===b[a])return c[a].bd;return(c[a]={fn:b[a],bd:JS.bind(b[a],b)}).bd}});JS.Class=JS.makeFunction();JS.extend(JS.Class.prototype=JS.makeBridge(JS.Module),{initialize:function(a,b){var c=JS.extend(JS.makeFunction(),this);c.klass=c.constructor=this.klass;if(!JS.isFn(a)){b=a;a=Object}c.inherit(a);c.include(b,null,false);c.resolve();do{a.inherited&&a.inherited(c)}while(a=a.superclass);return c},inherit:function(a){this.superclass=a;if(this.__eigen__){this.__eigen__().include(a.__eigen__?a.__eigen__():new JS.Module(a.prototype));this.__meta__.resolve()}this.subclasses=[];(a.subclasses||[]).push(this);var b=this.prototype=JS.makeBridge(a);b.klass=b.constructor=this;this.__mod__=new JS.Module({},{_1:this.prototype});this.include(JS.ObjectMethods,null,false);if(a!==Object)this.include(a.__mod__||new JS.Module(a.prototype,{_1:a.prototype}),null,false)},include:function(a,b,c){if(!a)return;var d=this.__mod__,b=b||{};b._4=this;return d.include(a,b,c!==false)},extend:function(a){if(!this.callSuper)return;this.callSuper();var b=this.subclasses.length;while(b--)this.subclasses[b].extend()},define:function(){var a=this.__mod__;a.define.apply(a,arguments);a.resolve()},includes:JS.delegate('__mod__','includes'),ancestors:JS.delegate('__mod__','ancestors'),resolve:JS.delegate('__mod__','resolve')});JS.Module=JS.extend(new JS.Class(JS.Module.prototype),JS.ObjectMethods.__fns__);JS.Module.include(JS.ObjectMethods);JS.Class=JS.extend(new JS.Class(JS.Module,JS.Class.prototype),JS.ObjectMethods.__fns__);JS.Module.klass=JS.Module.constructor=JS.Class.klass=JS.Class.constructor=JS.Class;JS.Module.extend({_3:[],methodAdded:function(a,b){this._3.push([a,b])},_0:function(a,b){var c=this._3,d=c.length;while(d--)c[d][0].call(c[d][1]||null,a,b)}});JS.extend(JS,{Interface:new JS.Class({initialize:function(d){this.test=function(a,b){var c=d.length;while(c--){if(!JS.isFn(a[d[c]]))return b?d[c]:false}return true}},extend:{ensure:function(){var a=JS.array(arguments),b=a.shift(),c,d;while(c=a.shift()){d=c.test(b,true);if(d!==true)throw new Error('object does not implement '+d+'()');}}}}),Singleton:new JS.Class({initialize:function(a,b){return new(new JS.Class(a,b))}})});
var GitHub={};GitHub.Base='http://github.com/api/v2/json/';GitHub.Helpers={empty:function(){},indexOf:function(arr,obj){for(var i in arr){if(arr[i]==obj){return i;}}
return-1;},remove:function(array,from,to){var rest=array.slice((to||from)+1||array.length);array.length=from<0?array.length+from:from;return array.push.apply(array,rest);},first:function(object){for(var i in object){return object[i];}},extend:function(target,object){for(var i in object){target[i]=object[i];}},jsonp:function(url,callback,name){var head=document.getElementsByTagName("head")[0];var script=document.createElement("script");script.type="text/javascript";script.src=url;window[name]=function(data){callback(data);window[name]=undefined;try{delete window[name];}catch(e){}
head.removeChild(script);};head.appendChild(script);}};GitHub.Simple=new JS.Singleton({jsonpid:0,call:function(url,query,func){if(!func){func=query;query=null;}
var name='githubjsonp'+this.jsonpid;this.jsonpid++;var query_string='?callback='+name;if(query){for(var i in query){query_string+='&'+encodeURIComponent(i)+'='+encodeURIComponent(query[i]);}}
var full_url=GitHub.Base+url+query_string;GitHub.Helpers.jsonp(full_url,func,name);},callset:function(url,object,done){this.call(url,function(data){var first=GitHub.Helpers.first(data);GitHub.Helpers.extend(object,first);if(done){done();}});},calleach:function(url,iter,done){this.call(url,function(data){var first=GitHub.Helpers.first(data);for(var i in first){iter(first[i]);}
if(done){done();}});},callmap:function(url,iter,done){var result=[];this.calleach(url,function(thing){result.push(iter(thing));},function(){done(result);});}});GitHub.Loader=new JS.Module({initialize:function(){this.loaded_set=[];},load:function(){var loaders=Array.prototype.slice.call(arguments);var callback;if(loaders[loaders.length-1]instanceof Function){callback=loaders.pop();}
if(loaders.length===0){loaders.push('basic');}
var done;if(callback){var finished_loaders=0,all_loaders=loaders.length,self=this;done=function(){finished_loaders+=1;if(finished_loaders==all_loaders){callback(self);}};}else{done=GitHub.Helpers.empty;}
for(var i in loaders){this.runLoader(loaders[i],done);}},reload:function(){var loaders=Array.prototype.slice.call(arguments);if(loaders[loaders.length-1]instanceof Function){loaders.pop();}
if(loaders.length===0){loaders.push('basic');}
for(var i in loaders){var index=GitHub.Helpers.indexOf(this.loaded_set,loaders[i]);if(index!=-1){GitHub.Helpers.remove(this.loaded_set,index);}}
this.load.apply(this,arguments);},runLoader:function(loader,done){if(this.isLoaded(loader)){done();}else{var self=this;this.loaders[loader].call(this,function(){self.loaded(loader);done();});}},isLoaded:function(loader){if(!loader){loader='basic';}
return GitHub.Helpers.indexOf(this.loaded_set,loader)!=-1;},loaded:function(loader){this.loaded_set.push(loader);}});GitHub.User=new JS.Class({initialize:function(login){this.login=login;this.callSuper();},repo:function(name){var res;if(this.repos){for(var i in this.repos){var repo=this.repos[i];if(repo.name==name){return repo;}}}
return new GitHub.Repo(this.login,name);},include:GitHub.Loader,loaders:{basic:function(done){var url='user/show/'+this.login;GitHub.Simple.callset(url,this,done);},followers:function(done){this.followers=[];var url='user/show/'+this.login+'/followers';GitHub.Simple.callset(url,this.followers,done);},following:function(done){this.following=[];var url='user/show/'+this.login+'/following';GitHub.Simple.callset(url,this.following,done);},repos:function(done){var repos=(this.repos=[]);var url='repos/show/'+this.login;GitHub.Simple.calleach(url,function(value){var repo=new GitHub.Repo(value.owner,value.name);GitHub.Helpers.extend(repo,value);repo.loaded('basic');repos.push(repo);},done);}}});GitHub.Repo=new JS.Class({initialize:function(owner,name){this.owner=owner;this.name=name;this.path=owner+'/'+name;this.callSuper();},issues:function(state,callback){var repo=this;var url='issues/list/'+this.path+'/'+state;GitHub.Simple.callmap(url,function(value){var issue=new GitHub.Issue(repo,value.number);GitHub.Helpers.extend(issue,value);issue.loaded('basic');return issue;},callback);},issue:function(number){return new GitHub.Issue(this,number);},commits:function(branch,file,callback){var repo=this;var url;if(!callback){callback=file;url='commits/list/'+this.path+'/'+branch;}else{url='commits/list/'+this.path+'/'+branch+'/'+file;}
GitHub.Simple.callmap(url,function(value){var commit=new GitHub.Commit(repo,value.id);GitHub.Helpers.extend(commit,value);commit.loaded('basic');return commit;},callback);},commit:function(sha){return new GitHub.Commit(this,sha);},tree:function(sha){return new GitHub.Tree(this,sha);},include:GitHub.Loader,loaders:{basic:function(done){var url='repos/show/'+this.path;GitHub.Simple.callset(url,this,done);},tags:function(done){this.tags={};var url='repos/show/'+this.path+'/tags';GitHub.Simple.callset(url,this.tags,done);},branches:function(done){this.branches={};var url='repos/show/'+this.path+'/branches';GitHub.Simple.callset(url,this.branches,done);}}});var commit_loader=function(done){var commit=this;var url='commits/show/'+this.path;GitHub.Simple.callset(url,this,function(){done();if(!commit.isLoaded('basic')){commit.loaded('basic');}
if(!commit.isLoaded('detailed')){commit.loaded('detailed');}});};GitHub.Commit=new JS.Class({initialize:function(repo,sha){this.repo=repo;this.sha=sha;this.path=this.repo.path+'/'+this.sha;this.callSuper();},include:GitHub.Loader,loaders:{basic:commit_loader,detailed:commit_loader,}});GitHub.Tree=new JS.Class({initialize:function(repo,sha){this.repo=repo;this.sha=sha;this.path=this.repo.path+'/'+this.sha;this.callSuper();},include:GitHub.Loader,loaders:{basic:function(done){var children=(this.children=[]);var repo=this.repo;var parent=this;var url='tree/show/'+this.path;GitHub.Simple.calleach(url,function(value){var res;if(value.type=='tree'){res=new GitHub.Tree(repo,value.sha);}else{res=new GitHub.Blob(parent,value.name);}
GitHub.Helpers.extend(res,value);children.push(res);},done);}}});GitHub.Blob=new JS.Class({initialize:function(parent,name){this.parent=parent;this.name=name;this.path=this.parent.path+'/'+this.name;this.callSuper();},include:GitHub.Loader,loaders:{basic:function(done){var url='blob/show/'+this.path;GitHub.Simple.callset(url,this,done);}}});GitHub.Issue=new JS.Class({initialize:function(repo,number){this.repo=repo;this.number=number;this.path=this.repo.path+'/'+this.number;this.callSuper();},include:GitHub.Loader,loaders:{basic:function(done){var url='issues/show/'+this.path;GitHub.Simple.callset(url,this,done);}}});
