
function BasicButton(init){
	 if(this instanceof BasicButton== false) 
	 	return new BasicButton(init);

	this.x = GetScreenWidth()>>1;
	this.y = GetScreenHeight()>>1;
	this.name = "";
	this.label = "";
	this.selected = false;
	this.pressed = false;
	this.over = false;
	this.borderY = 2;
	this.borderX = 2;

	this.setXY = function(x,y){
		this.x = x;
		this.y = y;
		this.x2 = this.x + this.width;
		this.y2 = this.y + this.height;
	}

	this.calcDimensions = function(){
		this.width = this.font.getStringWidth(this.label) + 2*this.borderX;
		this.height = this.font.getHeight() + 2*this.borderY;
		this.setXY(this.x, this.y);
	}
	this.font =  GetSystemFont();
	this.color = {
		normal: CreateColor(80,80,80),
		over: CreateColor(90,90,90),
		high: CreateColor(110,110,100),
		low: CreateColor(50,50,50),
		none: CreateColor(255,255,255,255),
		selected: CreateColor(255,55,55,255)
	};
	this.cm = {
		normal: CreateColorMatrix(0, 255,0,0, 0, 0,255,0, 0, 0,0,255),
		over: CreateColorMatrix(20, 255,0,0, 20, 0,255,0, 20, 0,0,255),
		low: CreateColorMatrix(0, 200,0,0, 0, 0,200,0, 0, 0,0,200),
		high: CreateColorMatrix(30, 255,0,0, 30, 0,255,0, 30, 0,0,255)
	}

	this.surface;

	// Run a function else set a value
	for (var action in init){
		if( (typeof this[action] == 'function') && (typeof init[action] == 'object') ){
			if(init[action].length !== undefined)
				this[action].apply(this, init[action]);
			else
				for(var vars in init[action]){
					this[action].apply(this, init[action][vars]);
				}
		} else
			this[action] = init[action];
	}

	this.draw = function(){
		this.calcDimensions();
		if(this.over)
			this.surface = CreateSurface(this.width, this.height, this.color.over);
		else
			this.surface = CreateSurface(this.width, this.height, this.color.normal);

		//var cm = this.over ? this.cm.over : this.cm.normal;
		//this.surface.applyColorFX4(to, to, this.width+to-1, this.height+to-1,
		//	cm, this.cm.low,  cm, this.cm.high);

		var col1 = this.pressed ?  this.color.low : this.color.high;
		var col2 = this.pressed ?  this.color.high : this.color.low;
		var to = this.pressed ? 1 : 0;

		this.surface.line(0,0, this.width-1,0, col1);
		this.surface.line(0,0, 0,this.height, col1);
		this.surface.line(1,this.height-1, this.width-1,this.height-1, col2);
		this.surface.line(this.width-1,0, this.width-1,this.height-1, col2);

		this.font.setColorMask(this.color.low);
		this.surface.drawText(this.font,
			this.borderX + to + 1,
			this.borderY + to + 1,
			this.label
		);
		if(this.selected)
			this.font.setColorMask(this.color.selected);
		else
			this.font.setColorMask(this.color.none);
		this.surface.drawText(this.font,
			this.borderX + to,
			this.borderY + to,
			this.label
		);
		if(this.selected)
			this.font.setColorMask(this.color.none);
	}
	this.calcDimensions.call(this);
	this.draw.call(this);
	if(!this.name) this.name = this.label;
	return this;
}

BasicButton.prototype.setlabel = function(label){
	this.label = label;
	this.draw();
}

BasicButton.prototype.setFont = function(font){
	this.font = font;
	this.draw();
}

BasicButton.prototype.setSelected = function(select){
	if(this.selected == select)
		return;
	this.selected = select;
	this.draw();
} 

BasicButton.prototype.setOver = function(hover){
	if(this.over == hover)
		return;
	this.over = hover;
	LL.write("BasicButton "+this.name+" stting hover "+hover);
	this.draw();
}

BasicButton.prototype.setPressed = function(press){
	if(this.pressed == press)
		return;
	this.pressed = press;
	LL.write("BasicButton "+this.name+" stting press "+press);
	this.draw();
}
BasicButton.prototype.display = function(){
	this.surface.blit(this.x, this.y);
}
