jQuery(document).ready(function() {
	
	if ( jQuery('.scrollable').length > 0 ) {
		
		jQuery('.scrollable').scrollable({
			size:1
			,clickable: false
			,vertical: false
			,loop: false
			,easing: "swing"
			,prev: '#prev_button'
			,next: '#next_button'
			,activeClass: "active"
			,onSeek: adjust_height_and_count
		});
		
		// fill in initial image count
		var total_count = jQuery('.scrollable ul.items li').length;
		jQuery('.scrollable_wrapper span').html('1 of ' + total_count);
		
		// set height of scrollable to equal height of first image
		var elem = jQuery('.scrollable ul.items li:first img');
		var image_height = jQuery(elem).height();

		jQuery('.scrollable').css({ 'height' : image_height });
		
	}
	
});

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * */

function adjust_height_and_count( i ) {
	
	// update image count
	var current_image = i + 1;
	var total_count = jQuery('.scrollable ul.items li').length;
	jQuery('.scrollable_wrapper span').html(current_image + ' of ' + total_count);
	
	// adjust height of scrollable to equal height of current image
	var elem = jQuery('.scrollable li:eq('+ i +') img');
	var image_height = jQuery(elem).height();
	
	jQuery('.scrollable').animate({ height: image_height });
	
}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * */

