var galleryCurrentRow = 1;
$(document).ready(function () {
	$('#nextImages').bind('click', function () {
		var $div = $('#imageContainer');
		
		var nextPosition;
		galleryCurrentRow++;
		
		nextPosition = '#thumbRow'+galleryCurrentRow;		
		
		if ($(nextPosition).length == 0) {
			galleryCurrentRow--;
		} else {
			$div.scrollTo( $(nextPosition) , 1000, {
				axis:'xy',
				offset: {left: 9}
			});
		}
	})
	$('#prevImages').bind('click', function () {
		var $div = $('#imageContainer');
		
		var nextPosition, gotoStart=false;
		galleryCurrentRow--;
		
		if (galleryCurrentRow < 2) {
			galleryCurrentRow = 1;

			gotoStart = true;
		} else {
			nextPosition = '#thumbRow'+galleryCurrentRow;		
		}
		
		if (!gotoStart) {
			$div.scrollTo( $(nextPosition) , 1000, {
				axis:'xy',
				offset: {left: 9}
			});
		} else {
			$div.scrollTo( 0 , 1000, { 
				axis:'xy'
			});
		}	
		
	})

});