var currentPage;
var numberOfPages;

$(document).ready(function(){
	
	currentPage = 0;
	numberOfPages = 0;
	
	showPage();
	
	/*
	$(document).find(".gallery_container .gallery-page").each(function(i) {
		numberOfPages++;
	});
	*/
	
	numberOfPages = $('#js-gallery-number-of-pages').html();
	
	$('#next-js-gallery').click(function(i) {
		
		if (currentPage < numberOfPages-1){
			currentPage++;
		}else{
			currentPage = 0;
		}
		
		showPage();
		
	});
	
	$('#previous-js-gallery').click(function(i) {
		
		if (currentPage > 0){
			currentPage--;
		}else{
			currentPage = numberOfPages-1;
		}
		
		showPage();
		
	});
	
	
	$(document).find(".pagination .pagination-page").each(function(i) {
		
		$(this).click(function(){
			
			currentPage = i;
			showPage();
			
		});
		
	});
	
	
});

function showPage(){
	
	$(document).find(".gallery_container .gallery-page").each(function(i) {
		
		$('#js-gallery-container').stop().animate({
			left: (-1*600*currentPage)+'px'
		}, 500);
		
		/*
		if (i == currentPage){
			$(this).fadeIn(200);
		}else{
			$(this).fadeOut(200);
		}
		*/
			
	});
	
	
	$(document).find(".pagination .pagination-page").each(function(i) {
		
		if (i == currentPage){
			$(this).addClass('current');
		}else{
			$(this).removeClass('current');
		}
		
	});
	
	$('#js-gallery-current-page').html(currentPage+1);
	
	/*
	$('#inside-page-numbers').animate({
		left: (190 - 30*currentPage)+'px'
	}, 200)
	*/
}
