package com.bit101.components{
	import com.bit101.components.HBox;
	import com.bit101.components.HSlider;
	import com.bit101.components.InputText;
	import com.bit101.components.Label;
	import com.greensock.loading.core.DisplayObjectLoader;
	import flash.display.DisplayObjectContainer;
	
	/**
	 * ...
	 * @author netgrind
	 */
	public class InputSlidernew extends HBox {
		
		public var slider:HSlider;
		public var input:InputText;
		public var label:Label;
		public var chars:String = '1234567890.';
		public var obj:Object;
		public var nom:String;
		
		public function InputSlidernew(object:*, varName:String, parent:DisplayObjectContainer = null,  defaultValue:Number = 0, min:Number=0,max:Number=100,text:String='' ):void {
			super(parent);
			
			obj = object;
			nom = varName;
			
			slider = new HSlider(this, 0, 0, sliderChnage);
			slider.height = 15;
			input = new InputText(null, 0, 0, '0', textChange);
			input.width = 30;			
			label = new Label(this,0,0,text);
			value = defaultValue;
			slider.minimum = min;
			slider.maximum = max;
			
		}
		
		
		
		private function textChange(e:*):void {
			if (slider.value.toString() != input.text) {
				if (input.text.length == 0) return;
				if (isNaN(Number(input.text))) return;
				
				var i:Number = Number(input.text);
				if (i < slider.minimum) {
					i = slider.minimum;
					input.text = i + '';
				}else if (i > slider.maximum) {
					i = slider.maximum;
					input.text = i + '';
				}
				slider.value = obj[nom] = i;
			}
		}
		
		private function sliderChnage(e:*):void {
			if (input.text != slider.value.toString()) {
				input.text = slider.value + '';
				obj[nom] = slider.value;
			}
		}
		
		public function get value():Number {
			return slider.value
		}
		public function set value(v:Number):void {
			slider.value = obj[nom] = v;
			input.text = '' + v;
		}
		
		public function get minimum():int {
			return slider.minimum;
		}
		
		public function set minimum(value:int):void {
			slider.minimum = value;
		}
		
		public function get maximum():int {
			return slider.maximum;
		}
		
		public function set maximum(value:int):void {
			slider.maximum = value;
		}
		
	}
	
}