 
 package flex.layout
 {
+import flash.geom.Rectangle;	
 
 import flex.core.Group;
 import flex.intf.ILayout;


        var totalWidthToDistribute:Number = unscaledWidth;
        if (totalCount > 1)
            totalWidthToDistribute -= (totalCount - 1) * GAP;

        distributeWidth(layoutItemArray, totalWidthToDistribute, unscaledHeight); 
                            
        // TODO EGeorgie: verticalAlign
        var vAlign:Number = 0;
        
        // Finally, position the objects        
        var x:Number = 0;
        for each (var lo:ILayoutItem in layoutItemArray)
        {
            var y:Number = (unscaledHeight - lo.actualSize.y) * vAlign;

            lo.setActualPosition(x, y);
            x += lo.actualSize.x;
            x += GAP;
        }
    }

    /**
     *  This function sets the width of each child

        _target = value;
    }
    
    //----------------------------------
    //  gap
    //----------------------------------

    /**
     *  @private
     */
    private var _gap:int = 6;
    
    /**
     *  @private
     */
    private var gapChanged:Boolean = false;

    [Inspectable(category="General")]

    /**
     *  Horizontal space between columns.
     * 
     *  @default 6
     */
    public function get gap():int
    {
        return _gap;
    }

    /**
     *  @private
     */
    public function set gap(value:int):void
    {
        if (_gap == value) return;
    
		_gap = value;
 	   	var layoutTarget:Group = target;
    	if (layoutTarget != null) 
    	{
			gapChanged = true;
        	layoutTarget.invalidateSize();
            layoutTarget.invalidateDisplayList();
    	}
    }
    
    //----------------------------------
    //  expliciColumnCount
    //----------------------------------

    /**
     *  The column count requested by explicitly setting
     *  <code>columnCount</code>.
     */
    protected var explicitColumnCount:int = -1;

    //----------------------------------
    //  columnCount
    //----------------------------------

    /**
     *  @private
     */
    private var _columnCount:int = -1;
    
    /**
     *  @private
     */
    private var columnCountChanged:Boolean = false;

    [Inspectable(category="General")]

    /**
     *  Number of columns to be displayed.
     *  If the width of the component has been explicitly set,
     *  this property might not have any effect.
     * 
     *  @default -1
     */
    public function get columnCount():int
    {
        return _columnCount;
    }

    /**
     *  @private
     */
    public function set columnCount(value:int):void
    {
        explicitColumnCount = value;

        if (_columnCount == value) return;

        setColumnCount(value);
 	   	var layoutTarget:Group = target;
    	if (layoutTarget != null) 
    	{
    		columnCountChanged = true;
        	layoutTarget.invalidateSize();
            layoutTarget.invalidateDisplayList();
    	}
    }

    /**
     *  Sets the <code>columnCount</code> property without causing
     *  invalidation or setting the <code>explicitColumnCount</code>
     *  property, which permanently locks in the number of columns.
     *
     *  @param v The row count.
     */
    protected function setColumnCount(v:int):void
    {
        _columnCount = v;
    }
    
    //----------------------------------
    //  explicitColumnWidth
    //----------------------------------

    /**
     *  The column width requested by explicitly setting
     *  <code>columnWidth</code>.
     */
    protected var explicitColumnWidth:Number;

    //----------------------------------
    //  columnWidth
    //----------------------------------
    
    /**
     *  @private
     */
    private var _columnWidth:Number = 20;
    
    /**
     *  @private
     */
    private var columnWidthChanged:Boolean = false;

    [Inspectable(category="General")]

    /**
     *  The width of the columns in pixels.
     *  Unless the <code>variableColumnWidth</code> property is
     *  <code>true</code>, all columns are the same width.  
     */
    public function get columnWidth():Number
    {
        return _columnWidth;
    }

    /**
     *  @private
     */
    public function set columnWidth(value:Number):void
    {
        explicitColumnWidth = value;

        if (_columnWidth != value)
        {
            setColumnWidth(value);
 		   	var layoutTarget:Group = target;
        	if (layoutTarget != null) 
        	{
        		columnWidthChanged = true;
            	layoutTarget.invalidateSize();
	            layoutTarget.invalidateDisplayList();
        	}
        }
    }

    /**
     *  Sets the <code>columnWidth</code> property without causing invalidation or 
     *  setting of <code>explicitColumnWidth</code> which
     *  permanently locks in the width of the columns.
     *
     *  @param value The column width, in pixels.
     */
    protected function setColumnWidth(value:Number):void
    {
        _columnWidth = value;
    }    


    //----------------------------------
    //  variableColumnWidth
    //----------------------------------

    /**
     *  @private
     */
    private var _variableColumnWidth:Boolean = true;

    [Inspectable(category="General")]

    /**
     *  @default true
     */
    public function get variableColumnWidth():Boolean
    {
        return _variableColumnWidth;
    }

    /**
     *  @private
     */
    public function set variableColumnWidth(value:Boolean):void
    {
        if (value == _variableColumnWidth) return;
        
        _variableColumnWidth = value;
 		var layoutTarget:Group = target;
        if (layoutTarget != null) {
    		layoutTarget.invalidateSize();
        	layoutTarget.invalidateDisplayList();
        }
    }
    
    

    public function variableColumnWidthMeasure(layoutTarget:Group):void
    {
        var minWidth:Number = 0;
        var minHeight:Number = 0;
        var preferredWidth:Number = 0;
        var preferredHeight:Number = 0;
        var visibleWidth:Number = 0;
        var visibleColumns:uint = 0;
        var explicitColumnCount:int = explicitColumnCount;        
        
        
        var count:uint = layoutTarget.numLayoutItems;
        var totalCount:uint = count; // How many items will be laid out
