// JavaScript Document

$frame_left = 0;
$frame_no = 1;
$start_middle = 0;
var infoHeights=new Array();

$(document).ready(function()
{
	jQuery.easing.def = 'easeInOutCirc';
	$move_by = ($("#gallery").css("width").replace("px","")/1);
	
	$max_clicks = $(".moduletableslideshow").children().size(); 	
	$imgCont = $move_by * $max_clicks; 
	$("#image_container").css({width : $imgCont});

	framecnt=1;
	while(framecnt<=$max_clicks)
	{
		infoHeights[framecnt] = document.getElementById('casestudy_'+framecnt).offsetHeight;
//($("#casestudy_"+framecnt).css("offsetheight").replace("px","")/1);
		if(framecnt!=(pQ+1))
			$("#casestudy_"+framecnt).animate({height: 0}, 1000,'easeInOutCirc');
			
		framecnt++;
	}
	

			// Get the middle frame, according to the $max_clicks
			$new_frame_no = pQ;
			
			// Adjust the frame position
			$new_left = -($new_frame_no * $move_by);						
			$new_left_attr = $new_left+"px";
			
			// Do the move
			$("#image_container").animate({left: $new_left_attr}, 1000,'easeInOutCirc' );
			
			// Save the new values
			$frame_left = $new_left;
			$frame_no = ($new_frame_no/1 + 1);

	
	$(".prev").click(function()
		{
			
			$(".prev").blur();
			/* Set the new position & frame number */
			$new_frame_no = (($frame_no/1)-1);
			$new_left = (($frame_left/1) + $move_by);
			/* Check if we're moving too far over */
			if($new_frame_no <= 0)
			{
				/* Move the images all the way left, minus one frame */
				$new_left = -($move_by*$max_clicks)+$move_by;
				$new_frame_no = $max_clicks;
			}
			$new_left_attr = $new_left+"px";
			
			$("#image_container").animate({left: $new_left_attr}, 1000,'easeInOutCirc', showText($frame_no,$new_frame_no) );
			$frame_left = $new_left;
			$frame_no = $new_frame_no;
			
		});
	$(".next").click(function()
		{
			$(".next").blur();
			/* Set the new position & frame number */
			$new_frame_no = (($frame_no/1)+1);
			$new_left = (($frame_left/1) - $move_by);
			/* Check if we're moving too far over */
			if($new_frame_no > $max_clicks)
				{		
					/* Move all the way right, to the beginning*/
					$new_left = 0;
					$new_frame_no = 1;
				}				
			$new_left_attr = $new_left+"px";
			$("#image_container").animate({left: $new_left_attr}, 1000,'easeInOutCirc', showText($frame_no,$new_frame_no) );
			$frame_left = $new_left;
			$frame_no = $new_frame_no;
		});	

	function showText(old_frame,new_frame)
	{
		$("#casestudy_"+old_frame).animate({height: 0}, 1000,'easeInOutCirc');
		$("#casestudy_"+new_frame).animate({height: infoHeights[new_frame]}, 1000,'easeInOutCirc');
	}


});

