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

	this.x = GetScreenWidth()>>1;
	this.y = GetScreenHeight()>>1;
	this.name = "";
	this.value = 1;
	this.min = 0;
	this.max = 255;
	this.x_min = 0;
	this.x_max = GetScreenWidth();
	this.selected = false;
	this.pressed = false;
	this.over = false;
	this.ball = CreateSurface(16,16, CreateColor(110,110,100) ).createImage(); // Default slider ball

	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.ball.width;
		this.height = this.ball.height;
	}

	this.cm = {
		normal: CreateColorMatrix(0, 255,0,0, 0, 0,255,0, 0, 0,0,255),
		over: CreateColorMatrix(40, 255,0,0, 40, 0,255,0, 40, 0,0,255),
		low: CreateColorMatrix(0, 200,0,0, 0, 0,200,0, 0, 0,0,200),
		select: CreateColorMatrix(30, 250,0,0, 0, 0,250,0, 0, 0,0,250)
	}


	// 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();
		this.setXY( Math.floor(this.x_min + (this.value - this.min)/(this.max - this.min) * (this.x_max-this.x_min)), this.y);
	}
	this.setBall = function(aball){
		this.ball = aball;
		this.ballover = aball.createSurface(); this.ballover.applyColorFX(0,0, aball.width, aball.height, this.cm.over); this.ballover = this.ballover.createImage();
		this.ballselected = aball.createSurface(); this.ballselected.applyColorFX(0,0, aball.width, aball.height, this.cm.select); this.ballselected = this.ballselected.createImage();
		this.draw();
	}
	this.calcDimensions.call(this);
	//Abort(this.x)
	this.draw.call(this);
	this.setBall.call(this,this.ball);
	if(!this.name) this.name = this.value;
	return this;
}

Slider.prototype.setValue = function(value){
	this.value = value<this.min? this.min:value>this.max?this.max:value;
	this.draw();
}


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

Slider.prototype.setOver = function(hover){
	if(this.over == hover)
		return;
	this.over = hover;
	this.draw();
}

Slider.prototype.setPressed = function(press){
	if(this.pressed == press)
		return;
	this.pressed = press;
	this.draw();
}

Slider.prototype.display = function(){
//	if(this.selected)
//	if(this.over)
//	if(this.pressed == press)
	if(this.over)
		this.ballover.blit(this.x, this.y);
	else
		this.ball.blit(this.x, this.y);
}
