var Colorizer = Class.create();
Colorizer.prototype = {

    initialize: function(style, group) {   
        this._default = style;
        this.style = style;
        this._group = group;
        this._elements = $A($$('.' + this._group));
        this._links = $A($$('.' + this._group + ' a'));
    },
    
    _styles: {
        BrickRed:       {backgroundColor:'#cc0000', color:'#ffffff'},
        Orange:         {backgroundColor:'#ff6600', color:'#ffffff'},
        LightOrange:    {backgroundColor:'#ff9900', color:'#000000'},
        DeepYellow:     {backgroundColor:'#ffcc00', color:'#000000'},
        LightYellow:    {backgroundColor:'#ffff66', color:'#000000'},
        BananaYellowL:  {backgroundColor:'#cccc66', color:'#000000'},
        BananaYellow:   {backgroundColor:'#cccc00', color:'#000000'},
        Gold:           {backgroundColor:'#cc9900', color:'#ffffff'},
        Olive:          {backgroundColor:'#999900', color:'#ffffff'},
        GrassGreen:     {backgroundColor:'#339900', color:'#ffffff'},
        OliveDrab:      {backgroundColor:'#666600', color:'#ffffff'},
        Brown:          {backgroundColor:'#996600', color:'#ffffff'},
        Walnut:         {backgroundColor:'#663300', color:'#ffffff'},
        DeepNavyBlue:   {backgroundColor:'#330066', color:'#ffffff'},
        DeepRiver:      {backgroundColor:'#6633cc', color:'#ffffff'},
        ElectricBlue:   {backgroundColor:'#6666ff', color:'#ffffff'},
        Blue:           {backgroundColor:'#0099ff', color:'#ffffff'},
        BabyBlue:       {backgroundColor:'#ccccff', color:'#000000'},
        White:          {backgroundColor:'#ffffff', color:'#000000'},
        Grey:           {backgroundColor:'#cccccc', color:'#000000'},
        DeepGrey:       {backgroundColor:'#999999', color:'#000000'},
        Black:          {backgroundColor:'#000000', color:'#cccccc'}
    },
    
    _busy: false,
    
    setStyle: function(style){
        if(this._busy){return};  
        this._busy = true;
        this.style = style;    
        for(var i = 0 ; i < this._elements.length ; i++){
            this._elements[i].setStyle(this._styles[style]);
        } 
        for(var i = 0 ; i < this._links.length ; i++){
            var l = this._links[i];
            l.removeClassName(l.readAttribute('class')).addClassName(style);
        } 
        this._busy = false;       
    },
    
    resetStyle: function(){
        if(this._busy){return};  
        this._busy = true; 
        this.style = this._default;     
        this.setStyle(this._default);  
        this._busy = false;      
    },
    
    toString: function(){
        return 'Colorizer ' + this._group + ':' + this.style;
    }
};

