// JavaScript Document
$move_bybook = 560;
$frame_leftbook = 0;
$frame_nobook = 1;




$(document).ready(function()
{
	
	$max_clicksbook = $("#image_containerbook").children().size(); 	
	
	/* Kudos to Rob MacKay [http://www.twitter.com/svgrob] for suggesting that we don't have to put a bookic style="width: 3960px" attribute in the div tag */
		$(".prevbook").fadeOut();
	$(".prevbook").click(function()
		{
   			/* Set the new position & frame number */
			$new_frame_nobook = (($frame_nobook/1)-1);

			$new_leftbook = (($frame_leftbook/1) + $move_bybook);
			/* Check if we're moving too far over */
			if($new_frame_nobook == 1)

				{$(".prevbook").fadeOut();			}
			else if($frame_nobook == $max_clicksbook )
				{$(".nextbook").fadeIn();}
			
			if($new_frame_nobook <= 0)
				{
					/* Move the images all the way left, minus one frame */
					$new_leftbook = -($move_bybook*$max_clicksbook)+$move_bybook;
					$new_frame_nobook = $max_clicksbook;
					   
				}
			$new_left_attrbook = $new_leftbook+"px";
			$("#image_containerbook").animate({left: $new_left_attrbook}, 800 );
			$frame_leftbook = $new_leftbook;
			$frame_nobook = $new_frame_nobook;
			
		});
	$(".nextbook").click(function()
		{
			/* Set the new position & frame number */
			$new_frame_nobook = (($frame_nobook/1)+1);
			$new_leftbook = (($frame_leftbook/1) - $move_bybook);
			/* Check if we're moving too far over */
			
			if ($new_frame_nobook == $max_clicksbook)
				{$(".nextbook").fadeOut();}
			else if ($frame_nobook == 1)
			{$(".prevbook").fadeIn();}
			
			if($new_frame_nobook > $max_clicksbook)
				{		
						/* Move all the way right, to the beginning*/
					$new_leftbook = 0;
					$new_frame_nobook = 1;
				
				}				
			$new_left_attrbook = $new_leftbook+"px";
			
			$("#image_containerbook").animate({left: $new_left_attrbook}, 800 );
			$frame_leftbook = $new_leftbook;
			$frame_nobook = $new_frame_nobook;
		});	
});







