function NewsList (){

  //a list of all Articles
  this.articles = [];
  
  //create the HTML for the list of articles/dates
  var div = document.createElement('div');
  div.className = "menu";
  var ul = document.createElement('ul');
  ul.appendChild(div);
  this.menu = ul;
   
  //add the list to the document
  document.getElementById('newsList').appendChild(this.menu);
  
  //add a blank, hidden div to the page to display news stories in
  div = document.createElement('div');
  div.className = "view";
  this.view = div;
  document.getElementById('newsList').appendChild(this.view);  
  
}
  
//adds an article to the news list    
NewsList.prototype.addArticle = function (article){
  
  this.articles[article.title] = article;
  this.menu.appendChild(article.html);
  
}
 

//a news article object
function Article(article){
  
  this.title = article['title'];
  
  this.html = "";
  
  var div = document.createElement('div');

  var a = document.createElement('a');
    a.href = "#";  
    a.innerHTML = this.title;
  
  div.appendChild(a);
  div.innerHTML += "<BR>"
  div.onclick = showArticle(this);
  var li = document.createElement('li');
  li.appendChild(div);
  
  div = document.createElement('div');
  div.className = 'date';
  div.innerHTML = article['date'];
  li.appendChild(div);

  this.html = li;

  div = document.createElement('div');
  
  var ul = document.createElement('ul');
  
  var li = document.createElement('li');
    var a = document.createElement('a');
      a.innerHTML = article['title'];
      a.href = article['url'];
    li.appendChild(a);
    li.className = 'title';
  
  var dateDiv = document.createElement('div');
    dateDiv.innerHTML = article['date'];
    dateDiv.className = 'date';
  
  li.appendChild(dateDiv);
  ul.appendChild(li);

  li = document.createElement('li');
  li.innerHTML = article['news'];
  li.className = 'news';
  ul.appendChild(li);
  
  div.appendChild(ul);
  
  a = document.createElement('a');
    a.onclick = hideArticle();
    a.innerHTML = "(return to menu)";
    a.href= "#";
  div.appendChild(a);
  this.news = div;
    
}

function showArticle (article) {
  return function () {
    
    //hide menu
    news.menu.style.display = "none";

    //display selected story
    news.view.appendChild(article.news);
    news.view.style.display = "block";  
  }
}


function hideArticle () {
  return function () {
    
  //hide selected story
  news.view.innerHTML = "";
  news.view.style.display = "block";  

  //display menu
  news.menu.style.display = 'block';
  }
}




