$(document).ready(function() {

	//Set Default State of each portfolio piece
	$(".paging_staff").show();
	$(".paging_staff a:first").addClass("active");
		
	//Get size of images, how many there are, then determin the size of the image reel.
	var imageWidthStaff = $(".window_staff").width();
	var imageSumStaff = $(".image_reel_staff div").size();
	var imageReelWidthStaff = imageWidthStaff * imageSumStaff;
	
	//Adjust the image reel to its new size
	$(".image_reel_staff").css({'width' : imageReelWidthStaff});
	
	//Paging + Slider Function
	rotateStaff = function(){	
		var triggerIDStaff = $active.attr("rel") - 1; //Get number of times to slide
		var image_reelPositionStaff = triggerIDStaff * imageWidthStaff; //Determines the distance the image reel needs to slide

		$(".paging_staff a").removeClass('active'); //Remove all active class
		$active.addClass('active'); //Add active class (the $active is declared in the rotateSwitchStaff function)
		
		//Slider Animation
		$(".image_reel_staff").animate({ 
			left: -image_reelPositionStaff
		}, 500 );
		
	}; 
	
	//Rotation + Timing Event
	rotateSwitchStaff = function(){		
		play = setInterval(function(){ //Set timer - this will repeat itself every 3 seconds
			$active = $('.paging_staff a.active').next();
			if ( $active.length === 0) { //If paging reaches the end...
				$active = $('.paging_staff a:first'); //go back to first
			}
			rotateStaff(); //Trigger the paging and slider function
		}, 20000); //Timer speed in milliseconds (3 seconds)
	};
	
	rotateSwitchStaff(); //Run function on launch
	
	//On Hover
	$(".image_reel_staff a").hover(function() {
		clearInterval(play); //Stop the rotation
	}, function() {
		rotateSwitchStaff(); //Resume rotation
	});	
	
	//On Click
	$(".paging_staff a").click(function() {	
		$active = $(this); //Activate the clicked paging
		//Reset Timer
		clearInterval(play); //Stop the rotation
		rotateStaff(); //Trigger rotation immediately
		rotateSwitchStaff(); // Resume rotation
		return false; //Prevent browser jump to link anchor
	});	
	
});

