/* Constructor for CacheDivision objects, which can contain other CacheDivision objects. */

	function CacheDivision() {

		/* Create store for items that never need to be accessed directly by name, but only iterated though */
		this.plainStore = [];

		/* Create store for items which need to be accessed directly by name */
		this.linkedStore = {};

		/* Creates a new cache division and appends it to the owner object of this method, allowing a hierarchy of divisions */
		this.createDivision = function(name) {
			this[name] = new CacheDivision();
		};

		/* Adds an item to the plain (unlinked) store */
		this.add = function(value) {
			this.plainStore.push(value);
		};

		/* Iterates through all items in the unlinked store and calls the iterator (a function) passed to it.
		'iterator' can contain an 'item' parameter, which refers to each item being iterated */
		this.iterate = function(iterator) {
			for (var i = 0; i < this.plainStore.length; i++)
				iterator(this.plainStore[i]);
		};

		/* Adds an item to the linked store. The item then becomes accessible by its 'label' */
		this.addLinked = function(label, value) {
			this.linkedStore[label] = value;
		};
		
		/* Retrieves an item from the linked store */
		this.fetchLinked = function(label) {
			return this.linkedStore[label];
		};

		/* Iterates through all items in the linked store and calls the iterator (a function) passed to it.
		'iterator' can contain an 'item' and a 'value' parameter, which refer to each item and its value */
		this.iterateLinked = function(iterator) {
			for (property in this.linkedStore)
				iterator(this.linkedStore[property], value);
		};	

	}
    
	Cache = new CacheDivision();
