(function(){


jQuery.fn.githubBox = function(githubName) {
	var $box = this;
	$.getJSON('http://github.com/api/v1/json/' + githubName + '?callback=?', function(data) {
		var user = data.user;
		$box.append('<ul></ul>');
		var $list = $box.find('ul');
		var sortedRepos = $(user.repositories).sort(function(a, b){ return b.watchers - a.watchers; });
		var finalRepos = [];
		for (i = 0; i < 10; i++) {
			var nextRepo = sortedRepos.get(i);
			if ( ! nextRepo) {
				break;
			}
			finalRepos.push(nextRepo);
		}
		$(finalRepos).each(function() {
			$list.append('<li><a href="http://github.com/' + githubName + '/' + this.name + '">' + this.name + '</a> - ' + this.forks + ' forks, ' + this.watchers + ' watchers</li>');
		});
	});
}

jQuery.fn.sort = function() {
	return this.pushStack( jQuery.makeArray( [].sort.apply( this, arguments ) ) ); 
};


})();