// JavaScript Document

/*** AUTOPLAY FUNCTIONS AND VARS  ***/

var autoplay_num = 0;

function autoplay_slideshow() {

	if (autoplay_num == 0) {
		autoplay_num++;
		setTimeout('autoplay_slideshow()', 3500);
	}
	else {
		moveNext();
		setTimeout('autoplay_slideshow()', 3500);
	}

}



/*** ARROW NEXT FUNCTIONS ***/
	function moveNext() {
		//get the next slide so I can feed two ids to the animate function
		getNextSlide(j);
		//Run animation function on current and next slides
		initAnimate(currentSlide, nextSlide, -slideWidth, 0);
		//if the current slide is less than the total amount of slides
		if (j < arrayLength) {
			//increment i by 1 so it = next Slide
			j++;
		}
		//if i is the same as the array length set it back to 0
		else if (j == arrayLength) {
			j = 0;
		}
		//change the current slide variable to the next slide
		currentSlide = slides[j];
	}//End moveNext

// Get the next slide ID so two ids can be fed to the animation function
	function getNextSlide (n){
		if (n == arrayLength ) {
			n = 0;
		}
		else {
			n++;
		}
		nextSlide = slides[n];
		//make sure the next slide is in the correct position for animating in
		onDeckRight(nextSlide);
		return;
	}

// Positions the next slide immediatly to the right so it's in the correct spot for animation 
	function onDeckRight(objectID) {
		var object = document.getElementById(objectID);
		object.style.left = slideWidth + 'px';
		object.style.top = '0px';
	}


/*** Animation FUNCTIONS ***/

// Init Vars For Animation Function
var objectOne = null;
var objectTwo = null;
var currXPosOne = null;
var currYPosOne = null;
var currXPosTwo = null;
var currYPosTwo = null;
var finalXPosOne = null;
var finalXPosTwo = null;
var distanceOne = null;
var distanceTwo = null;
var step = null;
//Distance to move per calculation
var animateSpeed = 15;


//Figure Out the animation of Two Objects At once.
	function initAnimate (slideOne, slideTwo, finalXOne, finalXTwo) {

		objectOne = document.getElementById(slideOne);
		objectTwo = document.getElementById(slideTwo);
	//get current x and y, I only need current X for this script but Y will be important in the future		
		currXPosOne = objectOne.offsetLeft;
		currYPosOne = objectOne.offsetTop;
		currXPosTwo = objectTwo.offsetLeft;
		currYPosTwo = objectTwo.offsetTop;
		finalXPosOne = finalXOne;
		finalXPosTwo = finalXTwo;
	//assign a distance to travel for X; current - final 
		distanceOne = Math.abs(currXPosOne - finalXPosOne);
		distanceTwo = Math.abs(currXPosTwo - finalXPosTwo);
	//determine whether we're moving left or right
	if (currXPosOne < finalXPosOne) {
		step = animateSpeed;
	}
	else if (currXPosOne > finalXPosOne) {
		step = -animateSpeed;
	}	
	animateObjects();
	}

//animate two objects at once
	function animateObjects() {
	// if my distances are greater than 0 subtract the step value from the distance and change the current left hand position by the step value 
		if ( distanceOne > 0 || distanceTwo > 0 ) {
			//set the current X position for both objects
			objectOne.style.left = Math.round(currXPosOne) + 'px';
			objectTwo.style.left = Math.round(currXPosTwo) + 'px';
			//reset current position to minus the step value
			currXPosOne = currXPosOne + step;
			currXPosTwo = currXPosTwo + step;
			//subtract the step from the distance as well since this if evals distance
			distanceOne = distanceOne - Math.abs(step);
			distanceTwo = distanceTwo - Math.abs(step);
			//this function should rerun itself evertime if evals as true
			setTimeout ('animateObjects()',0); 
		}
		else {
		//distance is no longer greater than 0 so set the final x positions and be done.
			objectOne.style.left = finalXPosOne + "px";
			objectTwo.style.left = finalXPosTwo + "px";
		}
		return;
	}

