var Transporter = Class.create();
Transporter.prototype = {
	initialize: function() {
		this.controlSetList = ['Elastic','Ease'];
		this.controlSet = 'Elastic';
		this.transition = 'Elastic';
		
		this.options = {};
		this.options.fps = 25.0;
		this.options.bounce = 4.0;
		this.options.decel = 8.0;
		this.options.friction = 6.0;
		this.options.easing = 4.0;
		this.options.duration = 1.3;
		
		this.ranges = {};
		this.ranges.fps = $R(10,100);
		this.ranges.bounce = $R(0.1,100.0);
		this.ranges.decel = $R(0.1,100.0);
		this.ranges.friction = $R(1.1,100.0);
		this.ranges.easing = $R(2,5);
		this.ranges.duration = $R(0.1,10.0);
		
		this.handle = false;
		
		this.setupControls();
		this.listen();
	},
	setupControls: function() {
		var precision;
		for( optName in this.options ) {
			precision = (['fps','easing'].member(optName) ? 0 : 1);
			new Control.Slider(optName+'-hnd',optName,{
				axis: 'horizontal',
				range: this.ranges[optName],
				sliderValue: this.options[optName],
				onSlide: function(val,slider){$((slider.handles[0].id).replace('-hnd','-val')).innerHTML = val.toFixed(1)},
				//onSlide: function(val){$(optName+'-val').innerHTML = val.toFixed(precision)}.bind(this),
				onChange: function(val,slider){trnsp.setOption((slider.handles[0].id).replace('-hnd',''),val.toFixed(1))}
				//onChange: function(val){this.options[optName] = val.toFixed(precision)}.bind(this)
			});
		}
		Element.hide('Ease-only');
	},
	listen: function() {
		Event.observe('clickpad','click',function(evt) {
			this.launch(Event.pointerX(evt),Event.pointerY(evt));
		}.bindAsEventListener(this));
	},
	setOption: function(optName,value) {
		this.options[optName] = value;
	},
	setTransition: function(el,setName) {
		this.transition = el.value;
		this.controlSetList.each(function(set) {
			$(set+'-only').style.display = (set==setName ? '' : 'none');
		}.bind(this));
	},
	launch: function(toX,toY) {
		if( this.handle )
			this.handle.cancel();
		this.handle = new Effect.Move('box',{
			mode: 'absolute',
			x: toX,
			y: toY,
			duration: this.options.duration,
			fps: this.options.fps,
			transition: Effect.Transitions[this.transition],
			afterFinish: function(){this.handle=false}.bind(this)
		});
	}
};
