var imageTotal;
var imagePanels;
var imageIndex = 1;
var animationTime = 500;

$(document).ready(function(){
    imageTotal = $('.galleryList').children('li').length;
    imagePanels = Math.ceil(imageTotal / 9);

    if(Number(imageTotal) > 9) {
        $('.galleryNext').show();
    }
	
    $('.galleryNext').click(function(e) {
        e.preventDefault();
        if(imageIndex < imagePanels) {
            if(imageIndex == (imagePanels-1) && imageTotal < (imagePanels*9)) {
                $('.galleryList').animate({
                    right: ((imageTotal*65)-585)+'px'
                    }, animationTime, "swing");
            } else {
                $('.galleryList').animate({
                    right: (imageIndex*585)+'px'
                    }, animationTime, "swing");
            }
            imageIndex++;
        }
    });
	
    $('.galleryPrev').click(function(e) {
        e.preventDefault();
        if(imageIndex > 1) {
            $('.galleryList').animate({
                right: ((imageIndex-2)*585)+'px'
                }, animationTime, "swing");
            imageIndex--;
        }
    });
	
    $('.galleryList li a').click(function(e) {
        e.preventDefault();
        newImage = $(this).attr('href');
        $('.galleryHero').attr('src', newImage);
    });
});
