//this variable monitors whether the pause button has been pressed
var pause = false;

//this variable controls the length of the intervals
var pauseTime = 7000;

//this variable controls which image is the current image.  It holds the position of the image. 0=1st image, 1=2nd image etc.
var currentImage = 0;

var galleryPreviousButton ="";
var galleryNextButton ="";


function initGalleryTween() {		

	slider = document.getElementById( 'gallery-thumbnail-slider' );
	galleryPreviousButton = document.getElementById( 'galleryPrevious' );
	galleryNextButton = document.getElementById( 'galleryNext' );
	
	slider.style.left = "0px";
	
	//loop through array and assign each box its left value.
	for (x=0;x<sliderArray.length;x++){
		temp = document.getElementById(sliderArray[x][0]+"-thumb");
		temp.style.left = sliderArray[x][1] + "px";
	}
	
	//start the Timer
	startTimer();
	slide(sliderArray[0][0]);
	
} // end init()

function slide(ID){
	
	//stop any timer that has started.
	clearTimeout ( nextTimer );
	
	newPosition = 0;
	
	//extract the left distance (measured in px) from the SliderArray.
	for (x=0;x<sliderArray.length;x++){
		if(sliderArray[x][0]==ID){
			newPosition = sliderArray[x][1] * -1;
			currentImage = x;
		}//if
	}//for
	
	/***slide the thumbnails if there is room left to slide***/
	if(currentImage < sliderArray.length-3){
		right_tween = new Tween(slider.style,'left',Tween.regularEaseInOut,parseInt(slider.style.left),newPosition,2,'px');
		right_tween.start();
	}//if
	
	/***hightlight the current thumbnail***/
	//remove the previous thumbnail's class
	jQuery("a.current").removeClass("current");
	//add class to current thumbnail
	jQuery("a#"+ID+"-thumb").addClass("current");
		
	
	/***after sliding fade the big picture in***/
	//fade out all divs
	jQuery("div#gallery-content-pane-slider > div").fadeOut("slow");
	//fade in one div
	selector = "div#"+ID;
	jQuery(selector).fadeIn("slow");
	
	/***Reset text styles***/
	jQuery(".sliderText").animate({ 
		marginLeft: "0px",
		color: 'gagnonlightbrown'
	}, 500 );
	
	/***Check to see if there is some matching text***/
	if(document.getElementById(sliderArray[currentImage][0]+"-text") != null){
		jQuery("#"+sliderArray[currentImage][0]+"-text").animate({ 
			marginLeft: "13px",
			color: 'gagnondarkbrown'
		}, 500 );
	}//if
	
	/***Change Nav if necessary***/
	if(currentImage == 0){
		//disable previous button
		galleryPreviousButton.className='notClickable';
	}//if
	else{
		//enable the previous button
		galleryPreviousButton.className='';
	}//else if
	if(currentImage != sliderArray.length -1){
		//enable the next button
		galleryNextButton.className='';
	}//else if
	
	//start the Timer over again
	startTimer();

}//function

function previousImage(){

	//check to see if there is a previous image.
	if(currentImage != 0){
		slide(sliderArray[currentImage-1][0]);
	}//if	
	
}//function

function nextImage(){

	//check to see if there is a next image.
	if(currentImage != sliderArray.length-1){
		slide(sliderArray[currentImage+1][0]);
	}//if
	else{
		//start at the beginning
		slide(sliderArray[0][0]);
	}//else

}//function

function startTimer(){
	//start time for 5 seconds
	if(pause==false){
		nextTimer = setTimeout ( "nextImage()", pauseTime );
	}//if

}//function