var publications;
function cb(param) {
	publications = param;
	var byYear = function sortfunction(a, b) {
		return (b.year - a.year);
	}
	publications.items.sort(byYear);
}
document.observe("dom:loaded", function() {
	var result = "";
	var oldYear = 0;
	publications.items.each(function(s){
		result += "<div class= 'publication'>"
		if (oldYear !== s.year){
				oldYear = s.year;
				result += "<div class='newPublicationYear'>"+ s.year +"</div>";
		}
		result += "<span class='author'>";
		for ( var i = 0; i < s.author.length; i++) {
			result += s.author[i] ;
			if(i< s.author.length-1) result+= "; ";
		}
		result += "</span>: ";
		result += "<span class='title'><a href='"+s.id+"'>" + s.label + "</a></span>";
		
		if(typeof(s.booktitle) !== 'undefined' && s.booktitle != null) {
			result += "; In: <span class='inproceedings'>" + s.booktitle + "</span> ";
		}
		result += " <span class='year'>" + s.year + "</span> ";
		if(typeof(s.note) !== 'undefined' && s.note != null) {
			 result +="<span class = 'note'>"+ s.note +"</span>";
		 }
		if(typeof(s["pub-type"]) !== 'undefined' && s["pub-type"] != null && s["pub-type"] === "mastersthesis" ) {
			result += " (Diplomarbeit - master theses)";
		}
		result += "</div>";
		result += "<br />";
		
	})
	$("publications").innerHTML = result;
});
