/***
* ModTree - Module-Based PHP Framework
* (c) Sebastian Bojanowski ( sbojanowski (at) gmail (dot) com )
* JavaScript Utilities
***/

// List Class
var Utils = function() {
};

Utils.List = function () {
	this.items = Array();
        this.index = 0;
}

Utils.List.prototype = {
	addItem : function(item) {
	     this.items.push(item);
             return item;
	},
	
	getItemCount : function() {
             return this.items.length;
	},
        
        first : function() {
             this.index = 0;
        },
        
        last : function() {
             this.index = this.getItemCount()-1;
        },
        
        next : function() {
             this.index++;         
        },
        
        valid : function() {
             if (this.index < this.getItemCount())
                  return true;
             else
                  return false;
        },
   
        getItem : function() {
             return this.getItemByIndex(this.index);
        },
	
	getItemByIndex : function(index) {
             if (index < this.getItemCount())
                  return this.items[index];
             else
                  return null;
        },
   
        getItemByName : function(name) {
             var index = 0,found = null;
             while (!found && index<this.getItemCount()) {
                  if (name == this.items[index].getName())
                        found = this.items[index];
                  index++;
             }
             return found;
        }
}