MyCustomSlider = function (settings) {
	var t = this;
	t.slideByStep = false;
	$.extend(t, settings);

	t.picker = t.container.children('#' + t.picker_id);

	t.picker.delta = Math.round(t.picker.width() / 2);

	t.minX = 0;
	t.maxX = t.maxVal; //t.container.width() - 9;

	if (t.defaultValue) {
		t.picker[0].style.left = t.defaultValue + t.picker.delta - 2 + 'px';
	}

	t.container.bind('mousedown', this, t.initSlide);

	return this;
}

MyCustomSlider.prototype = {
	initSlide: function (e) {
		e.preventDefault();
		e.stopPropagation();

		var that = e.data;

		var offset = Math.round($(this).offset().left);
	
		that.slide(e, offset);

		var active = true;
		
		$(document).bind('mousemove', that, function (e) {
			e.preventDefault();
			if (!active) { return; }
			
			var timer = setTimeout (function () {
				active = true;
				clearTimeout(timer);
			}, 1);
			
			active = false;
			that.slide(e, offset);
			
		})
		.mouseup(function () {
			$(this).unbind('mousemove mouseup');
		});
	},

	slide: function (e, offset) {
		var that = e.data;
		var picker = that.picker;
		
		var position = e.clientX - offset - picker.delta + 2;
		position = Math.min(Math.max(that.minX, position), that.maxX);

		var value = position * Math.round((that.maxVal + that.minX) / that.maxX) - that.minX;

		if (that.slideByStep) {
			picker[0].style.left = value + picker.delta - 2 + 'px';
		} else {
			picker[0].style.left = position + 'px';
		}

		if (that.fn && that.fn.onChange) {
			that.fn.onChange.call(that.fn.that, value);
		}
	}
}


