
function collection_list_item() {
	this.next = null;
	this.last = null;
}

function collection_list() {
	this.fisrt = null;
	this.end = null;
	this.count = 0;
	
	this.collection_exists = function(item) {
		var loop = this.first;
		while (loop != null && loop != item) loop = loop.next;
		
		return loop
	}
	
	this.collection_add = function(item) {
		if (item.next == null && item.last == null) {
			if (this.first == null) {
				this.first = item;
				this.end = item;
				this.count++;
			} else {
				this.end.next = item;
				item.last = this.end;
				this.end = item;
				this.count++;
			}
			
			return item;
		}
		
		return null;
	}
	
	this.collection_rem = function(item) {
		if (this.first != null) {
			if (item.last == null && item.next == null) {
				this.first = null;
				this.end = null;
			} else if (item.last == null) {
				this.first = this.first.next;
				this.first.last = null;
			} else if (item.next == null) {
				this.end = this.end.last;
				this.end.next = null;
			} else {
				item.last.next = item.next;
				item.next.last = item.last;
			}
			
			this.count--;
			return item;
		} 
		
		return null;
	}
	
	this.collection_flush = function() {
		if (this.first != null) {
			var loop = this.first;
			var next = null;
			while (loop != null) {
				next = loop.next;
				context.object_destroy(loop);
				loop = next;
			}
			
			this.first = null;
			this.last = null;
		}
	}
}

