// JavaScript Document

NewsCollection = function() {
	
	this.collection = new Array();
	
	this.clear = function() { this.collection = new Array(); }
	
	this.add = function(newsItem) { this.collection[this.collection.length]=newsItem; }
	
	this.load = function(start, length) {
		this.clear();
		var query = '';
		if(typeof start !='undefined') { query+='&start='+encodeURIComponent(start); }
		if(typeof length !='undefined') { query+='&length='+encodeURIComponent(length); }
		var data = getData('./XML/nieuws.xml','');
		
		if(typeof data.response!='undefined') {
		
			if(data.response.header.status == 0) {
				if((typeof data.response.body != 'undefined') && (typeof data.response.body.news != 'undefined'))  { // 
					if(typeof data.response.body.news.item.length != 'undefined') {
						for(var i=0;i<data.response.body.news.item.length;i++) {
							var anItem = data.response.body.news.item[i];
							this.add(new NewsItem(anItem.itempk, anItem.title, anItem.newsdate, anItem.content, anItem.shortdescription, anItem.image));	
						}
					} else {
						var anItem = data.response.body.news.item;
						this.add(new NewsItem(anItem.itempk, anItem.title, anItem.newsdate, anItem.content, anItem.shortdescription, anItem.image));	
					}
				}
			}
		}

		
	}
	
	this.getByItemPK = function(itempk) {
		var returnItem = false;
		for(var i=0;(i<this.collection.length) && (returnItem===false);i++) {
			if(this.collection[i].itempk==itempk) returnItem=this.collection[i];
		}
		
		return returnItem;
	}
	
}

NewsItem = function(anItemPK, aTitle, aDate, aContent, aShortDescription, anImage) {

	this.itempk				=	anItemPK;
	this.title				=	aTitle;
	this.date				=	aDate;
	this.content			=	aContent;
	this.shortdescription	=	aShortDescription;
	this.image				=	anImage;

	this.getShortContent	=	function() {
		return this.shortdescription;		
		
//		if(this.content.length>128) {
//			return this.content.substr(0,125)+'...';
//		} else {
//			return this.content;
//		}
	}
	

}
