Ext.iconPalette = function(config){
    Ext.iconPalette.superclass.constructor.call(this, config);
    this.addEvents(
        
/**
             * @event select
             * Fires when a icon is selected
             * @param {iconPalette} this
             * @param {String} icon The 6-digit icon hex code (without the # symbol)
             */
        'select'
    );

    if(this.handler){
        this.on('select', this.handler, this.scope, true);
    }
};
Ext.extend(Ext.iconPalette, Ext.Component, {
        
/**
         * @cfg {String} tpl An existing XTemplate instance to be used in place of the default template for rendering the component.
         */
    
/**
     * @cfg {String} itemCls
     * The CSS class to apply to the containing element (defaults to 'x-icon-palette')
     */
    itemCls : 'x-icon-palette',
    
/**
     * @cfg {String} value
     * The initial icon to highlight (should be a valid 6-digit icon hex code without the # symbol).  Note that
     * the hex codes are case-sensitive.
     */
    value : null,
    clickEvent :'click',
    // private
    ctype : 'Ext.iconPalette',

    
/**
     * @cfg {Boolean} allowReselect If set to true then reselecting a icon that is already selected fires the {@link #select} event
     */
    allowReselect : false,

    
/**
     * 

An array of 6-digit icon hex code strings (without the # symbol).  This array can contain any number
     * of icons, and each hex code should be unique.  The width of the palette is controlled via CSS by adjusting
     * the width property of the 'x-icon-palette' class (or assigning a custom class), so you can balance the number
     * of icons with the width setting until the box is symmetrical.

     * 

You can override individual icons if needed:

     * 


var cp = new Ext.iconPalette();
cp.icons[0] = 'FF0000';  // change the first box to red



Or you can provide a custom array of your own for complete control:


var cp = new Ext.iconPalette();
cp.icons = ['000000', '993300', '333300'];


     * @type Array
     */
    icons : [
        '000000', '993300', '333300', '003300', '003366', '000080', '333399', '333333',
        '800000', 'FF6600', '808000', '008000', '008080', '0000FF', '666699', '808080',
        'FF0000', 'FF9900', '99CC00', '339966', '33CCCC', '3366FF', '800080', '969696',
        'FF00FF', 'FFCC00', 'FFFF00', '00FF00', '00FFFF', '00CCFF', '993366', 'C0C0C0',
        'FF99CC', 'FFCC99', 'FFFF99', 'CCFFCC', 'CCFFFF', '99CCFF', 'CC99FF', 'FFFFFF'
    ],

    
/**
     * @cfg {Function} handler
     * Optional. A function that will handle the select event of this palette.
     * The handler is passed the following parameters:


    *      * palette : iconPalette
      The {@link #palette Ext.iconPalette}.

    *      * icon : String
      The 6-digit icon hex code (without the # symbol).

           * 


     */
    
/**
     * @cfg {Object} scope
     * The scope (this reference) in which the {@link #handler}
     * function will be called.  Defaults to this iconPalette instance.
     */

    // private
    onRender : function(container, position){
        var t = this.tpl || new Ext.XTemplate(
            ' '
        );
        var el = document.createElement('div');
        el.id = this.getId();
        el.className = this.itemCls;
        t.overwrite(el, this.icons);
        container.dom.insertBefore(el, position);
        this.el = Ext.get(el);
        this.mon(this.el, this.clickEvent, this.handleClick, this, {delegate: 'a'});
        if(this.clickEvent != 'click'){
                this.mon(this.el, 'click', Ext.emptyFn, this, {delegate: 'a', preventDefault: true});
        }
    },

    // private
    afterRender : function(){
        Ext.iconPalette.superclass.afterRender.call(this);
        if(this.value){
            var s = this.value;
            this.value = null;
            this.select(s);
        }
    },

    // private
    handleClick : function(e, t){
        e.preventDefault();
        if(!this.disabled){
            var c = t.className.match(/(?:^|\s)icon-(.{6})(?:\s|$)/)[1];
            this.select(c.toUpperCase());
        }
    },

    
/**
     * Selects the specified icon in the palette (fires the {@link #select} event)
     * @param {String} icon A valid 6-digit icon hex code (# will be stripped if included)
     */
    select : function(icon){
        icon = icon.replace('#', '');
        if(icon != this.value || this.allowReselect){
            var el = this.el;
            if(this.value){
                el.child('a.icon-'+this.value).removeClass('x-icon-palette-sel');
            }
            el.child('a.icon-'+icon).addClass('x-icon-palette-sel');
            this.value = icon;
            this.fireEvent('select', this, icon);
        }
    }

    
/**
     * @cfg {String} autoEl @hide
     */
});
Ext.reg('iconpalette', Ext.iconPalette);