var argPos;
var cont;
var tileAray;
var iEnd = 2;
var iInit = 0;
var inc = 0;
var positions = 2;
var direction;
var dc = 0;
var apressed = "slider_next";
var inc_passed = 1;
var myTimer;
var fullWidth
var clean_div_value;
var clean_container_value;
var clean_div_value_full;

//--------------------------------Make slide_contents container div the width of all the slides combined.
function updateContainerWidth(){
	var dValues = $('slide_contents').getFirst().getStyle('width');
	var allSlides = $('slide_contents').getChildren();
	
	clean_div_value = pixelSplitter(dValues);
	var multiplier = allSlides.length;
	fullWidth = multiplier * clean_div_value;
	$('slide_contents').setStyle('width', fullWidth); 
	fStartLoop();
	//alert('clean_div_value : '+clean_div_value+ ' | fullWidth : '+ fullWidth+' | multiplier : '+multiplier+'  | allSlides : '+allSlides);
}

//--------------------------------Move the tiles left or right.
function fSlideTile(){

	var xLeftChange = new Fx.Style('slide_contents', 'left', {duration:500, transition:Fx.Transitions.Sine.easeIn, fps:30, onComplete:fResetArrow});
	//var dValues = $('slide_contents').getCoordinates();  $('myElement').getStyles('width','height','padding');

	var dContainerValues = $('slide_contents').getStyles('width','left');
	var dValues = $('slide_contents').getFirst().getStyle('width');
	
	clean_container_value = pixelSplitter(dContainerValues.left);
	clean_div_value_full = pixelSplitter(dContainerValues.width);
	
	var absMathPos = Math.abs(clean_container_value);
	var containerPos = clean_div_value_full - absMathPos;
	
	//alert('absMathPos : ' +absMathPos+' | containerPos : '+containerPos);

	if(inc == 1){
	//--------------------------------the right arrow was pressed
	//alert('containerPos :'+containerPos+' | clean_div_value * 2 :'+clean_div_value * 2);
		if(containerPos >= (clean_div_value * 2)){
				xLeftChange.start(clean_container_value - clean_div_value);
			}else{
				$('slide_contents').getFirst().injectAfter($('slide_contents').getLast());
				$('slide_contents').setStyle('left',clean_container_value + clean_div_value);
				//clean_container_value = pixelSplitter(dContainerValues.left);
				xLeftChange.start(clean_container_value);
			}
	}else if(inc == -1){
	//--------------------------------the left arrow was pressed	
	//alert('absMathPos :'+absMathPos+' | clean_div_value * 2 :'+clean_div_value * 2);
			if(absMathPos >= (clean_div_value * 2)){
				xLeftChange.start(clean_container_value + clean_div_value);
			}else{
				$('slide_contents').getLast().injectBefore($('slide_contents').getFirst());
				$('slide_contents').setStyle('left',clean_container_value - clean_div_value);
				clean_container_value = pixelSplitter(dContainerValues.left);
				xLeftChange.start(clean_container_value);
			}
			
	
	};

};

function pixelSplitter(val){
	return Number(val.split('px')[0]);
}

function fDivCounter(i){
	inc = i;
	inc_passed = i;
	
	if(i != -1){
		
	//collect vars needed to reset the button
	apressed = "slider_next";
	
	//remove href from arrow pressed
	$(apressed).setProperty('href','javascript:fDummy();');
	
	}else{
		
	//collect vars needed to reset the button
	apressed = "slider_previous";
	
	//remove href from arrow pressed
	$(apressed).setProperty('href','javascript:fDummy();');
	}
	//stop the timer so we don't double up on the slide and so on
	myTimer = $clear(myTimer);
	//call the slider
	fSlideTile();
};

function fDummy(){
	
}

function fStartLoop(){
	
	inc = 0+1;//have the progression to appear right arrow press
	
	myTimer = fSlideTile.delay(20000);
	//created loop that does not change anything but takes 15 seconds to do it.
	//var loopSlider = new Fx.Style('slide_contents', 'width', {duration:15000, onComplete:fSlideTile});
	
	///loopSlider.start(2040);
	
}

function fResetArrow(){
	$(apressed).setProperty('href','javascript:fDivCounter('+inc_passed+');');
	fStartLoop();
}


onload_register('updateContainerWidth()');