/**
 * @author Matthew Foster
 * @date   February 5th 2007
 * @purpose An extension of the Grid class, creates a "Paintable" grid, with a pallete defined by an array of class names
 */
var GridPaint = Class.create();
 
Object.extend(Object.extend(GridPaint.prototype, GridBase.prototype),
				{
				
					initialize : function(classArr, options){
						this.classArr = classArr;
						
						GridBase.prototype.initialize.apply(this, [options]);
					
						this.buildPallette();
					},
					buildPallette : function(){
						this.pallette = $C("ul");
						
						this.classArr.each(this.buildColor.bind(this));
						
						
						this.curPaint = $C("li");
						
						this.curPaintBrush = $C("div");
						
						this.curPaint.appendChild(this.curPaintBrush);
						this.curPaint.appendChild(document.createTextNode("Current Brush"));
						
						Element.addClassName(this.curPaint, "currentPaint");
						this.pallette.appendChild(this.curPaint);
					
					},
					buildColor : function(className){
						var listEle = $C("li");
						var paint   = $C("div");
						var label   = document.createTextNode(className);
						
						this.attachPaintListeners(paint);
						
						
						Element.addClassName(paint, className);
						
						listEle.appendChild(paint);
						listEle.appendChild(label);
						
						this.pallette.appendChild(listEle);					
					
					},
					attachPaintListeners : function(paint){
						
						Event.observe(paint, "click", this.onPaintClick.bindAsEventListener(this));
										
					},
					onPaintClick : function(e){
						
						this.currentClass = Event.element(e).className;
						this.curPaintBrush.className = this.currentClass;
					
					},
					cellDown : function(e){
														
						var cell = Event.element(e);
						
						cell.className = this.currentClass;
							
						//Element.addClassName(cell, this.currentClass);
					},
					cellUp : function(e){
						//var cell = Event.element(e);
						//cell.className = "";
						//Element.removeClassName(cell, this.currentClass);
						
					} 
				
				
				
				
				}
			);	
	