// articlegroup_create takes two or more arguments:
// 1) The article_id for which we create the group
// 2) a list of article_group_ids to join
// It joins the groups,  sorts the articles and filters 
// away doublets and the article it self. 
// It returns an Array object with the related articles

function group_create() {
    if(document.article_groups) {

	var article_id = arguments[0];
	var related_articles = new Array();
	for(var i = 1; i < arguments.length; i++) {
	    related_articles = related_articles.concat(document.article_groups[arguments[i]]);
	}

	related_articles.sort(function(a,b) { return (a.publishing_time < b.publishing_time ? 1 : -1) });

 	// remove doublets

 	var filtered_articles = new Array();

 	var j=0;

 	for (i=0; i < related_articles.length; i++) {
 	    if ((i == related_articles.length - 1 || related_articles[i].article_id != related_articles[i+1].article_id) && related_articles[i].article_id != article_id) {
 		filtered_articles[j] = related_articles[i];
 		j++;
 	    }
 	}

	return filtered_articles;
    }
}
