 [Event(name="itemRemove", type="flex.events.ItemExistenceChangedEvent")]
 
 //--------------------------------------
-//  Styles
-//--------------------------------------
-
-include "../styles/metadata/BasicContainerFormatTextStyles.as"
-include "../styles/metadata/AdvancedContainerFormatTextStyles.as"
-include "../styles/metadata/BasicParagraphFormatTextStyles.as"
-include "../styles/metadata/AdvancedParagraphFormatTextStyles.as"
-include "../styles/metadata/BasicCharacterFormatTextStyles.as"
-include "../styles/metadata/AdvancedCharacterFormatTextStyles.as"
-
-//--------------------------------------
 //  Other metadata
 //--------------------------------------
 

        return super.addChildAt(child, index != -1 ? index : super.numChildren);
    }
    
    
    //--------------------------------------------------------------------------
    //
    //  Item -> Skin mapping
    //
    //--------------------------------------------------------------------------
    
    public function getItemSkin(item:*):DisplayObject
    {
        var result:DisplayObject = null;
                    
        if (skinRegistry)
            result = skinRegistry[item];
        
        if (!result && item is DisplayObject)
            result = item;
                
        return result;
    }
    
    public function getSkinItem(skin:DisplayObject):*
    {
        // !! This implementation is really slow... 
        var item:*;
        
        for (var i:int = 0; i < numItems; i++)
        {
            item = getItemAt(i);
            if (getItemSkin(item) == skin)
                return item;
        }
        
        return null;
    }
    
    //--------------------------------------------------------------------------
    //
    //  IGraphicElement Implementation
    //
    //--------------------------------------------------------------------------
    
    //----------------------------------
    //  mask
    //----------------------------------
    private var _mask:DisplayObject;
    private var maskChanged:Boolean;
    
    [Inspectable(category="General")]
    override public function get mask():DisplayObject
    {
        return _mask;
    }
    
    /*
     *  sets the mask. The mask will be added to the display list. The mask must
     *  not already on a display list nor in the elements array.  
     */ 
    override public function set mask(value:DisplayObject):void
    {
        if (_mask !== value)
        {
            _mask = value;
            maskChanged = true;
            invalidateProperties();
            //addDrawnElements();
            
        }
        super.mask = value;         
    } 
    
    //----------------------------------
    //  maskType
    //----------------------------------
    
    [Bindable("propertyChange")]
    [Inspectable(category="General",enumeration="clip,alpha", defaultValue="clip")]
    private var _maskType:String = MaskType.CLIP;
    private var _oldMaskType:String = MaskType.CLIP;
    private var maskTypeChanged:Boolean;
    private var originalMaskFilters:Array;
    
    public function get maskType():String
    {
        return _maskType;
    }
    
    public function set maskType(value:String):void
    {
        if (_maskType != value)
        {
            _oldMaskType = _maskType;
            _maskType = value;
            maskTypeChanged = true;
            invalidateProperties();
        }
    }
    
    //----------------------------------
    //  rotation
    //----------------------------------
    
    /**
     *  @private
     */
    private var _rotation:Number = 0;
    
    [Bindable("propertyChange")]
    [Inspectable(category="General")]
    
    /**
     *  The rotation for this group, in degrees.
     */
    override public function get rotation():Number
    {
        return !isNaN(_rotation) ? _rotation : super.rotation;
    }
    
    override public function set rotation(value:Number):void
    {
        if (_rotation != value)
        {
            var oldValue:Number = _rotation;
            
            _rotation = value;
            transformChanged = true;
            invalidateProperties();
        }
    }

    //----------------------------------
    //  transform
    //----------------------------------
    private var _transform:flash.geom.Transform;
    private var _matrix:Matrix;
    private var _colorTransform:ColorTransform;
    
    override public function set transform(value:flash.geom.Transform):void
    {
        // Clean up the old event listeners
        var oldTransform:flex.geom.Transform = _transform as flex.geom.Transform;       
        if (oldTransform)
        {
            oldTransform.removeEventListener(PropertyChangeEvent.PROPERTY_CHANGE, transformPropertyChangeHandler);
        }
        
        var newTransform:flex.geom.Transform = value as flex.geom.Transform;
        
        if (newTransform)
        {   
            newTransform.addEventListener(PropertyChangeEvent.PROPERTY_CHANGE, transformPropertyChangeHandler);
            _matrix = value.matrix.clone(); // Make sure it is a copy
            _colorTransform = value.colorTransform; 
        }
    
        _transform = value; 
        super.transform = value; 
    } 
    
    //----------------------------------
    //  transformX
    //----------------------------------
    private var _transformX:Number = 0;
        
    /**
     *  The x position transform point of the element. 
     */
    public function get transformX():Number
    {
        return _transformX;
    }
    
    public function set transformX(value:Number):void
    {
        if (_transformX != value)
        {
            _transformX = value;
            transformChanged = true;
            invalidateProperties();
        }
    }
    
    //----------------------------------
    //  transformY
    //----------------------------------
    private var _transformY:Number = 0;
    
    /**
     *  The y position transform point of the element. 
     */
    public function get transformY():Number
    {
        return _transformY;
    }
    
    public function set transformY(value:Number):void
    {
        if (_transformY != value)
        {
            _transformY = value;
            transformChanged = true;
            invalidateProperties();
        }
    }

    private function transformPropertyChangeHandler(event:PropertyChangeEvent):void
    {
        if (event.kind == PropertyChangeEventKind.UPDATE)
        {           
            if (event.property == "matrix")
            {
                // Apply matrix
                if (_transform)
                {
                    _matrix = _transform.matrix.clone();
                    transformChanged = true;
                    invalidateProperties();
                } 
            }
            else if (event.property == "colorTransform")
            {
                // Apply colorTranform
                if (_transform)
                {
                    _colorTransform = _transform.colorTransform;
                    // TODO EGeorgie: figure out what to invalidate when we implement
                    // colotTransform being applied.
                    transformChanged = true;
                    invalidateProperties();
                }
            }
        }
    }
    
    //--------------------------------------------------------------------------
    //
    //  IGraphicElementHost Implementation
    //
    //--------------------------------------------------------------------------
    
    /**
     *  @inheritDoc
     */
    public function elementChanged(e:IGraphicElement):void
    {
        // TODO!!! Optimize
        invalidateSize();
        invalidateDisplayList();    
    }
    
    /**
     *  @inheritDoc
     */
    public function elementSizeChanged(e:IGraphicElement):void
    {
        // TODO!!! Optimize
        invalidateSize();
        invalidateDisplayList();    
    }
    
    /**
     * @inheritDoc
     */
    public function elementLayerChanged(e:IGraphicElement):void
    {
        // TODO!!! Optimize
        // TODO!!! Need to recalculate the elements
        invalidateSize();
        invalidateDisplayList();    
        // One of our children have told us they might need a displayObject     
        assignDisplayObjects();
    }
    
    /**
     *  @inheritDoc
     */
    public function get parentGraphic():Graphic
    {
        return null;
    }
    
    protected var maskElements:Dictionary;
    
    public function addMaskElement(mask:DisplayObject, target:IGraphicElement):void
    {
        if (!maskElements)
            maskElements = new Dictionary();

        // validate sizes of the elements, even in cases where recursive==false.
        
        // Check whether we manage the elements, or are they managed by an ItemRenderer
        // TODO EGeorgie: we need to optimize this, iterating through all the elements is slow.
        // Validate element size
        var length:int = numItems;
        for (var i:int = 0; i < length; i++)
        {
            var element:GraphicElement = getItemAt(i) as GraphicElement;
            if (element)
                element.validateSize();
        }

        super.validateSize(recursive);
    }   
    
    override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
    {
        super.updateDisplayList(unscaledWidth, unscaledHeight);

        // TODO EGeorgie: we need to optimize this, iterating through all the elements is slow.
        // Iterate through the graphic elements, clear their graphics and draw them

        graphics.clear(); // Clear the group's graphic because graphic elements might be drawing to it
        // This isn't needed for DataGroup because there's not much DisplayObject sharing
        
        // TODO EGeorgie: we need to optimize this, iterating through all the elements is slow.
        // Iterate through the graphic elements, clear their graphics and draw them
        var length:int = numItems;
        for (var i:int = 0; i < length; i++)
        {
            var element:GraphicElement = getItemAt(i) as GraphicElement;
            if (element)
                element.validateDisplayList();
        }
    }

    //--------------------------------------------------------------------------
    //
    //  Content management
