
// collector class is the constructor for the collector object.
function collector(){
    this.stack = new Array(); //array to hold function requests
    this.first = null; //var to hold the first function 
    this.last = null; //var to hold the last function
    this.iterations = null;
	this.time = null;
	this.x = null;
}

// addItem function adds an item to the collector objects stack array.
function addItem(item){
    with (this) { 
        var i = stack.length;
    	stack[i] = item;
    }
}

// delItem function removes an item from the collector objects stack array.
function delItem(item){
    with (this) {
        for (var i = 0; i < stack.length; i++) {
            if (stack[i] == item) {
                stack.splice(i, 1);
            }
        }
    }
}

/* run function cycles through the stack array provided by the collector object
 and evaluates the statements held within. */
function run(){ 
	with (this) {
        for (var i = 0; i < stack.length; i++) {
            eval(stack[i]);
        }
    }
}

//replaces the stack array with an empty one. 
function flush(){
    with (this) {
        stack = new Array();
    }
}

//
function display(item){
    with (this) {
        document.getElementById('body').appendChild(document.createElement('<br>'));
        document.getElementById('body').appendChild(document.createElement('<hr>'));
        document.getElementById('body').appendChild(document.createTextNode(item));
    }
}

// the following lines associate the addItem, delItem, run, and display functions to the collector objects
collector.prototype.addItem = addItem;
collector.prototype.delItem = delItem;
collector.prototype.flush = flush;
collector.prototype.run = run;
collector.prototype.display = display;
collector.prototype.runT = runT;





