﻿Type.registerNamespace("Telerik.Web.UI");

Telerik.Web.UI.ControlItemCollection = function (parent)
{
	this._array = new Array();
	this._parent = parent;
	this._control = null;
}

Telerik.Web.UI.ControlItemCollection.prototype = 
{
	add : function (item)
	{	
		var index = this._array.length;
		this.insert(index, item);
	},
	
	insert : function (index, item)
	{
		var itemParent = item.get_parent();
		var control = this._parent._getControl();
		
		if(itemParent)
			itemParent._getChildren().remove(item);
		
		if (control)
			control._childInserting(index, item, this._parent);
			
		Array.insert(this._array, index, item);
		item.set_parent(this._parent);

		if (control)
		{
			control._childInserted(index, item, this._parent);
			control._logInserted(item);
		}
	},
	
	remove : function (item)
	{
		var control = this._parent._getControl();
		if (control)
			control._childRemoving(item);
		
		Array.remove(this._array, item);
		
		if (control)
			control._childRemoved(item, this._parent);
			
		item.set_parent(null);
		item._control = null;
	},
	
	removeAt : function (index)
	{
		var item = this.getItem(index);
		if (item)
			this.remove(item);
	},
	
	clear : function ()
	{
		var control = this._parent._getControl();
		if (control)
		{
			control._logClearing(this._parent);
			control._childrenCleared(this._parent);
		}
		
		this._array = new Array();
	},
	
	get_count : function ()
	{
		return this._array.length;
	},
	
	getItem : function(index)
	{
		return this._array[index];
	},
	
	indexOf : function (item)
	{
		return Array.indexOf(this._array, item);
	},

	forEach : function (lambda)
	{
	    for (var i = 0, count = this.get_count(); i < count; i++)
	    {
	        lambda(this._array[i]);
	    }
	}
}

Telerik.Web.UI.ControlItemCollection.registerClass("Telerik.Web.UI.ControlItemCollection");

if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();