// JavaScript Document
$(document).ready(function(){
	
	var holderWidth;
	var currLeft;
	var animation=0;
	var direction;
	
	$('.fab-slide-left, .fab-slide-right').show();
		
	$('#content-3').css({'height':'400px', 'overflow':'hidden'});
	
	$('.fab-slider-holder').each(function() {
		var count = $(this).children().length;
		$(this).css({'width':(count*770)+'px', 'position': 'absolute', 'top':'10px', 'left':'0px'});
	});
	
	$('.fab-slide-right').click(function(){
		holderWidth = $('.fab-slider-holder').width();
		currLeft = $('.fab-slider-holder').css('left').replace('px','');
		if(currLeft <= 0 && currLeft > -(holderWidth - 770) && animation==0){
			direction= '-';
			moveImage()
		} else {
			resetImageLeft()
		};
	});
	
	$('.fab-slide-left').click(function(){
		holderWidth = $('.fab-slider-holder').width();
		currLeft = $('.fab-slider-holder').css('left').replace('px','');
		if(currLeft < 0 && currLeft >= -(holderWidth - 770) && animation==0){
			direction= '+';
			moveImage()
		}else{
			resetImageLeft()
		};
	});

	function resetImageLeft() {
			if(currLeft==-(holderWidth - 770) && animation==0){
			animation =	1;
			$('.fab-slider-holder').animate({'left':'0px'},500, function() {
				animation =0;
			});
			}
			if(currLeft==0 && animation==0){
			animation =	1;
			$('.fab-slider-holder').animate({'left':-(holderWidth - 770)+'px'},500, function() {
				animation =0;
			});
			}
	}
	
	function moveImage() {
			animation =	1;
			$('.fab-slider-holder').animate({'left':direction+'='+'770px'},500, function() {
				animation =0;
			});
	}
	
	$(document).keyup(function(event){
		if (event.keyCode == 37) {
			$('.fab-slide-left').trigger('click');
		}
		if (event.keyCode == 39) {
			$('.fab-slide-right').trigger('click');
		}
	});
	
});
