/* <![CDATA[ */
var scrollChange;

var sliderWidth = 590;
var knobWidth = 188;
var currentSection = 0;
var interactedWith = 0;

var wRatio;

window.addEvent('domready', function(){
	
	var scrollChange = new Fx.Styles($('sections_holder'), {duration:500, wait:false});
	var updateKnobPos = new Fx.Styles($('knob'), {duration:500, wait:false});
	var updateScrolling = new Fx.Style('sections_holder', 'left', {duration:0});
	var changeLArrowBG = new Fx.Style('left_arrow', 'backgroundImage', {duration:0});
	
	if (!($('dragger')))
	{
		return;
	}
	
//	wRatio = (sliderWidth-knobWidth)/$('dragger').getCoordinates().width;
	wRatio = 317/$('dragger').getCoordinates().width;
	
	$('left_arrow').addEvent('click', function(event) {
		interactedWith++;
		if(currentSection > 0){
			event = new Event(event).stop();
			currentSection--;
			if(currentSection < 0)currentSection=2;
			lockIntoSection();
		}
	});
	
	$('right_arrow').addEvent('click', function(event) {
		interactedWith++;
		if(currentSection < 2){
			event = new Event(event).stop();
			currentSection++;
			if(currentSection > 2)currentSection=0;
			lockIntoSection();
		}
	});
	
	var mySlide = new Slider($('area'), $('knob'), {
		steps: 644,
		onChange: function(step){
			updateScrolling.set(step/wRatio * -1);
		}, 
		onComplete: function(step){
			interactedWith++;
			var destX = 0;
			if(step<133){
				currentSection = 0;
			}else if(step<400){
				currentSection = 1;
			}else{
				currentSection = 2;
			}
			lockIntoSection();
		}
	}).set(0);
	
	function nextSection(){
		
		if(interactedWith <= 1){
			
			if(currentSection >= 2){
				interactedWith = true;
				myTimer = $clear(myTimer);
				return false;
			}
			
			currentSection++;
			
			lockIntoSection();
			
			//myTimer = nextSection.delay(10000);
			
		}
		
	}
	
	function lockIntoSection(){
		if(currentSection == 0){
			destX = 0;
			step=0;
			$('left_arrow').className=" inactive";
			$('right_arrow').className="";
		}else if(currentSection == 1){
			destX = 226;
			step=322;
			$('left_arrow').className="";
			$('right_arrow').className="";
		}else{
			destX = 455;
			step=643;
			$('left_arrow').className="";
			$('right_arrow').className=" inactive";
		}
		updateKnobPos.start({'left': destX});
		
		scrollChange.start({'left': step/wRatio * -1});
	}
	
	//var myTimer = nextSection.delay(5000);
	
});

/* ]]> */

