(function() { 

	function SBList( inArray )
	{
		this.data = ( inArray ) ? inArray : new Array();
	}

	SBList.prototype.append = function( inObj )
	{
		this.data.push( inObj );
	};  

	SBList.prototype.remove = function( inObj )
	{
		for( var i = 0; i < this.data.length; i++ )
		{	
			if( this.data[i] == inObj )
			{
				this.data.splice(i, 1); 
				return inObj;
			}
		}
	
		return null;
	};

	SBList.prototype.insertAt = function( inObj, inIndex )
	{
		if( inIndex >= 0 )
			this.data.splice(inIndex, 0, inObj); 
	}; 

	SBList.prototype.removeAll = function()
	{
		this.removeAfter(0);
		this.remove( this.data[0] );
	};

	SBList.prototype.removeAfter = function( index )
	{
		index++;
		var objs = this.data.slice( index );
		this.data.splice(index, (this.data.length - (index)) ); 

		return objs;
	};

	SBList.prototype.merge = function( arr )
	{
		for( var i = 0; i < arguments.length; i++ )
		{
			this.data = this.data.concat( arguments[i].data );	
		}
	};

	SBList.prototype.get = function( inIndex )
	{
		if( (inIndex < this.data.length) && inIndex >= 0 )
			return this.data[inIndex];
	
		return null;
	};

	SBList.prototype.size =  function()
	{
		return this.data.length;
	};

	SBList.prototype.contains = function( inObj )
	{
		for( var i = 0; i < this.data.length; i++ )
		{
			if( this.data[i] == inObj )
			{
				return true;
			}
		}
	
		return false;
	};

	SBList.prototype.find = function( inObj )
	{
		for( var i = 0; i < this.data.length; i++ )
		{
			if( this.data[i] == inObj )
			{
				return i;
			}
		}
	
		return -1;
	};


	SBList.prototype.perform = function( inFunc, inObj, inFilter )
	{
		if( !inFunc ) return;

		for( var i = 0; i < this.data.length; i++ )
		{
			if( (inFilter && inFilter(this.data[i]) ) || !inFilter )
			{
				if( inObj != null )
				{
					if( inObj[inFunc] )
						inObj[inFunc]( this.data[i] );
					else
						YAHOO.log("List::Perform Object does not have function ("+inFunc+")");
				}
				else if( this.data[i][inFunc] )
				{
					this.data[i][inFunc]();
				}
				else
				{
					inFunc( this.data[i] );		
				}
			}
		}
	};

	window['SB']['util']['List'] = SBList;
})();
