/* Dynamic paper list maker

	Requires:
		1. A papers_array with objects that have the following
			properties
			--
			title: 
			authors: 
			paper: 
			publisher: 
			pages: (optional)
			extra: (optional)
			thumb: (optional)
			tags: (optional)
		2. A custom writePaperEntry feature with whatever styling
			the page requires
		3. (optional) postProcessFn that happens after the papers
			are inserted
*/

extras = ['paper', 'video']
PAPER_LIMIT = 6;
function filterOn(filter, limit){
    if(!limit) limit = PAPER_LIMIT;
    filter = filter.toLowerCase()
    if(filter == 'all'){
        subset = papers_array;
    }
    else {
        subset = new Array();
        for(var i = 0; i < papers_array.length; i++){
            if(papers_array[i].tags.match(filter)){
                subset.push(papers_array[i]);
            }
        }
    }
    populatePapersList(subset, limit);
}


function populatePapersList(array, limit){
    if(!limit) limit = PAPER_LIMIT;
    var container = document.getElementById('paper_container');
    container.innerHTML = "";
    for(var i = 0; i < Math.min(array.length, limit); i++){
        var newDiv = writePaperEntry(array[i]);
        container.innerHTML += newDiv;
    }
    if(window.postProcessFn) postProcessFn();
}