jQuery(function($) {
		
		$('.gallery-thumbs').addClass('gallery-thumbs-list'); // adds new class name to maintain degradability
		
		$('ul.gallery-thumbs-list').galleria({
			history   : false, // activates the history object for bookmarking, back-button etc.
			clickNext : false, // helper for making the image clickable
			insert    : '#main_image', // the containing selector for our main image
			onImage   : function(image,caption,thumb) { // let's add some image effects for demonstration purposes
				
				// fade in the image & caption
				 // FF/Win fades large images terribly slow
					image.css('display','none').fadeIn(1000);

				
				// fetch the thumbnail container
				var _li = thumb.parents('li');
				
				// fade out inactive thumbnail
				_li.siblings().children('img.selected').fadeTo(500,0.3);
				
				// fade in active thumbnail
				thumb.fadeTo('fast',1).addClass('selected');
				
				// add a title for the clickable image
				image.attr('title','Trevor Currie, Fine Art Paintings');
			},
			onThumb : function(thumb) { // thumbnail effects goes here
				
				// fetch the thumbnail container
				var _li = thumb.parents('li');
				
				// if thumbnail is active, fade all the way.
				var _fadeTo = _li.is('.active') ? '1' : '0.3';
				
				// fade in the thumbnail when finnished loading
				thumb.css({display:'none',opacity:_fadeTo}).fadeIn(1500);
				
				// hover effects
				thumb.hover(
					function() { thumb.fadeTo('fast',1); },
					function() { _li.not('.active').children('img').fadeTo('fast',0.3); } // don't fade out if the parent is active
				)
			}
		});
	});

// Slideshow Thumb Action
$move_by = 960;
$frame_left = 0;
$frame_no = 1;
$start_middle = 0;

$(document).ready(function()
{
	
	$max_clicks = $("#thumb-container").children().size(); 	
	$imgCont = $move_by * $max_clicks; 
	
	$("#thumb-container").css({width : $imgCont});
	
	if($start_middle == 1)
		{
			// Get the middle frame, according to the $max_clicks
			$new_frame_no = ($max_clicks/2).toFixed(0)
			
			// Adjust the frame position
			$new_left = -($new_frame_no * $move_by);						
			$new_left_attr = $new_left+"px";
			
			// Do the move
			$("#thumb-container").animate({left: $new_left_attr}, 800 );
			
			// Save the new values
			$frame_left = $new_left;
			$frame_no = ($new_frame_no/1 + 1);
		}
	
	$(".prev").click(function()
		{
			/* 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";
			$("#thumb-container").animate({left: $new_left_attr}, 800 );
			$frame_left = $new_left;
			$frame_no = $new_frame_no;
			
		});
	$(".next").click(function()
		{
			/* 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";
			$("#thumb-container").animate({left: $new_left_attr}, 800 );
			$frame_left = $new_left;
			$frame_no = $new_frame_no;
		});	
});


	