var Color = Class.create({
	initialize: function() {
		this.color = [0, 0, 0];
		
		// Initialize with hex string
		if(arguments.length == 1) {
			var regex = /^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i;
			var match = regex.exec(arguments[0]);
			if(match)
			{
				this.color[0] = parseInt(match[1], 16);
				this.color[1] = parseInt(match[2], 16);
				this.color[2] = parseInt(match[3], 16);
				
				// Make sure we have valid rgb
				this.check();
				return;
			}
			
			var regex = /^rgb\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})\)$/i;
			var match = regex.exec(arguments[0]);
			if(match)
			{
				this.color[0] = parseInt(match[1], 10);
				this.color[1] = parseInt(match[2], 10);
				this.color[2] = parseInt(match[3], 10);
				
				// Make sure we have valid rgb
				this.check();
				return;
			}
		}
		
		// Initialize with rgb
		else if(arguments.length == 3) {
			
			if(arguments[0] >= 0 && arguments[0] <= 255 &&
			   arguments[1] >= 0 && arguments[1] <= 255 &&
			   arguments[2] >= 0 && arguments[2] <= 255)
			{
				this.color[0] = arguments[0];
				this.color[1] = arguments[1];
				this.color[2] = arguments[2];
				
				// Make sure we have valid rgb
				this.check();
				return;
			}
		}
	},
	
	darken: function(amount) {
		this.color[0] -= amount;
		this.color[1] -= amount;
		this.color[2] -= amount;
		this.check();
	},
	
	lighten: function(amount) {
		this.color[0] += amount;
		this.color[1] += amount;
		this.color[2] += amount;
		this.check();
	},
	
	check: function() {
		for(i = 0; i < 3; ++i)
		{
			if(this.color[i] < 0) {
				this.color[i] = 0; }
			else if(this.color[i] > 255) {
				this.color[i] = 255; }
		}
	},
	
	hex: function() {
		return '#' + this.color.invoke('toColorPart').join('');
	},
	
	rgb: function() {
		return this.color;
	}
});