

function repository_h1(repos) {
  var h1 = document.createElement('h1');
  var a = document.createElement('a');
  a.setAttribute('href', repos.url);
  a.innerHTML = repos.name;
  h1.appendChild(a);
  
  return h1;
}

function repository_properties(repos) {
  var div = document.createElement('div');
  div.className = "properties";
  
  var p1 = document.createElement('p');
  p1.innerHTML = "in "+repos.language;
  div.appendChild(p1);
  
  var p2 = document.createElement('p');
  var date = new Date(repos.created_at);
  p2.innerHTML = "created on "+date.getFullYear()+"/"+date.getMonth()+"/"+date.getDate();
  div.appendChild(p2);
  
  return div;
}

function repository_branches(repos, parent) {
  var num = 0;
  for (i in repos.commits) {
    var div = document.createElement('div');
    div.className = (num == 0)?"branch left":"branch";
    if (num > 0) {
      div.setAttribute('style', "margin-left: "+(num*270)+"px");
    }
    
    var h2 = document.createElement('h2');
    h2.innerHTML = "branch: "+i;
    div.appendChild(h2);
    
    for (j=0; j<repos.commits[i].commits.length; j++) {
      var div2 = document.createElement('div');
      div2.className = 'commit';
      
      var h3 = document.createElement('h3');
      h3.innerHTML = repos.commits[i].commits[j].message + " <a href=\"https://github.com" + repos.commits[i].commits[j].url + "\">&#9688;</a>";
      div2.appendChild(h3);
      
      var h4 = document.createElement('h4');
      h4.innerHTML = "by "+repos.commits[i].commits[j].committer.name+" ("+repos.commits[i].commits[j].committer.email.replace("@", "[at]")+")<br />on "+repos.commits[i].commits[j].committed_date;
      div2.appendChild(h4);
      
      div.appendChild(div2);
    }
    
    parent.appendChild(div);
    
    num++;
  }
  
  parent.setAttribute('style', "width: "+(275*num)+"px");
}

function repository_div(repos) {
  var div = document.createElement('div');
  div.className = "repos";
  
  div.appendChild(repository_h1(repos));
  div.appendChild(repository_properties(repos));
  repository_branches(repos, div);
  
  repos_divs.push(div);
}

function repository_all() {
  for (i in repositories) {
    repository_div(repositories[i]);
  }
}

