/***** PORTFOLIO CONTROLS  *****/		

// get a list of the images
images = $('.images img');
total_images = images.length;
current_index = 0;
current_image = 1;

$('.total').text(total_images);
$('.currentconflict').text(current_image);


// if there's only one image, hide the controls		
if(total_images == 1) $('.controls').hide();
	
		
// setup default state when the page loads
$.each(images, function(index, value){
	
	// only show the first image
	if(index == 0)
	{
		$(value).show();
	} else {
		$(value).hide();
	}
});


// prev button controls
$('.prev').click(function(){

	if(current_image > 1)
	{
		// find the index of the image to show
		new_image = current_image-1;
		new_index = current_index-1;
	} else {
		// user is at the end of the cycle, rewind count back to the start
		new_image = total_images;
		new_index = total_images-1;
	}
		
	// toggle the image being viewed
	$('.images img:visible').fadeOut(function(){
		$(images[new_index]).fadeIn();
		
		current_index = new_index;
		current_image = new_image;
		
		$('.currentconflict').text(current_image);			
	});
	
	return false;
});


// next button controls
$('.next').click(function(){

	if(current_image < total_images)
	{
		// find the index of the image to show
		new_image = current_image+1;
		new_index = current_index+1;
	} else {
		// user is at the end of the cycle, rewind count back to the start
		new_image = 1;
		new_index = 0;
	}
		
	// toggle the image being viewed
	$('.images img:visible').fadeOut(function(){
		$(images[new_index]).fadeIn();
		
		current_index = new_index;
		current_image = new_image;
		
		$('.currentconflict').text(current_image);			
	});
							
	return false;	
});
