var gallery_step_button_area = 200;

var gallery_prev_loading = false;
var gallery_next_loading = false;

var gallery_show_buttons = true;



$(document).ready(function(){
	
	// If page has an image foucs gallery
	if($('.image-focus').length > 0){
	
		$('.pager-control-step').click(function(){
			gallery_show_buttons = false;
		});
	
		// Get total width of all images (including padding & margin)
		var width = 0;
		$('.image-focus .right img').each(function(){
			width += $(this).outerWidth(true);
		});
		
		// Assign max-width matching the total image width to the pager container
		$('.image-focus .right .pager-container').css({'max-width': width});
		
		
		
		$('.image-focus .images-container').mousemove(function(e){
			var mouse_x = e.pageX - $(this).offset().left;
			
			var prev = $(this).find('.pager-prev');
			if(!prev.is(':animated')){
				if(mouse_x < gallery_step_button_area) prev.fadeIn(300);
				else if(!gallery_show_buttons) prev.fadeOut(300);
			}
			
			var next = $(this).find('.pager-next');
			if(!next.is(':animated')){
				if(mouse_x > gallery_step_button_area) next.fadeIn(300);
				else if(!gallery_show_buttons) next.fadeOut(300);
			}

		}).bind('mouseleave', function(){
			if(!gallery_show_buttons){
				$(this).find('.pager-prev').fadeOut(300);
				$(this).find('.pager-next').fadeOut(300);
			}
		});
		
	}

});

// Update the maximum width once all images have loaded (fixes IE9 bug)
$(window).load(function(){
	
	// If page has an image foucs gallery
	if($('.image-focus').length > 0){
	
		// Get total width of all images (including padding & margin)
		var width = 0;
		$('.image-focus .right img').each(function(){
			width += $(this).outerWidth(true);
		});
		
		// Assign max-width matching the total image width to the pager container
		$('.image-focus .right .pager-container').css({'max-width': width});
	
	}

});
